Java Code Examples for org.eclipse.swt.widgets.Table#getItems()

The following examples show how to use org.eclipse.swt.widgets.Table#getItems() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void addCustomTableEditorControls()
{
	clearTableEditors();

	final Table table = tableViewer.getTable();
	TableItem[] items = table.getItems();
	for (int i = 0; i < items.length; i++)
	{
		ThemeRule rule = (ThemeRule) items[i].getData();
		if (rule.getTextAttribute().foreground != null)
		{
			createButton(table, items[i], 1, rule.getTextAttribute().foreground);
		}
		if (rule.getTextAttribute().background != null)
		{
			createButton(table, items[i], 2, rule.getTextAttribute().background);
		}
		createFontStyle(table, items[i], rule.getTextAttribute());
	}
}
 
Example 2
Source Project: MergeProcessor   File: Dashboard.java    License: Apache License 2.0 5 votes vote down vote up
private void selectMergeUnits(IMergeUnit[] mergeUnitsToSelect) {
	final Table table = view.getTableViewer().getTable();
	TableItem[] tableItems = table.getItems();

	ArrayList<TableItem> tableItemsToSelect = new ArrayList<>();

	for (TableItem tableItem : tableItems) {
		Object data = tableItem.getData();

		if (data != null && data instanceof IMergeUnit) {
			IMergeUnit mergeUnit = (IMergeUnit) data;

			for (IMergeUnit mergeUnitToSelect : mergeUnitsToSelect) {
				if (mergeUnit.compareTo(mergeUnitToSelect) == 0) {
					tableItemsToSelect.add(tableItem);
					break;
				}
			}
		} else {
			String message = String.format("Error while reading selection.Unexpected tableItem data. data=[%s]", //$NON-NLS-1$
					data);
			throw LogUtil.throwing(new MergeDataException(message));
		}
	}

	table.setSelection(tableItemsToSelect.toArray(new TableItem[tableItemsToSelect.size()]));
}
 
Example 3
Source Project: nebula   File: Snippet1.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public static Print createPrint(Table table) {
	// Create GridPrint with all columns at default size.

	DefaultGridLook look = new DefaultGridLook();
	look.setCellBorder(new LineBorder());
	RGB background = table.getDisplay()
			.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND).getRGB();
	look.setHeaderBackground(background);
	look.setFooterBackground(background);

	GridPrint grid = new GridPrint(look);

	// Add header and footer to match table column names.
	TableColumn[] columns = table.getColumns();
	for (int i = 0; i < columns.length; i++) {
		TableColumn col = columns[i];

		// Add the column to the grid with alignment applied, default width,
		// no
		// weight
		grid.addColumn(new GridColumn(col.getAlignment(), SWT.DEFAULT, 0));

		Print cell = createCell(col.getImage(), col.getText(), SWT.CENTER);
		grid.addHeader(cell);
		grid.addFooter(cell);
	}

	// Add content rows
	TableItem[] items = table.getItems();
	for (int i = 0; i < items.length; i++) {
		TableItem item = items[i];
		for (int j = 0; j < columns.length; j++)
			grid.add(createCell(item.getImage(j), item.getText(j),
					columns[j].getAlignment()));
	}

	return grid;
}
 
Example 4
Source Project: nebula   File: DualList.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Cleans the content of a table
 *
 * @param table table to be emptied
 */
private void clean(final Table table) {
	if (table == null) {
		return;
	}

	for (final TableItem item : table.getItems()) {
		item.dispose();
	}
}
 
Example 5
private Object[] getRootElements(TableViewer viewer) {
	Table t= viewer.getTable();
	Item[] roots= t.getItems();
	Object[] elements= new Object[roots.length];
	for (int i = 0; i < elements.length; i++) {
		elements[i]= roots[i].getData();
	}
	return elements;
}
 
Example 6
public TableItem[] getDataElements(Table table, Object... data) {
	List<TableItem> tableItems = new ArrayList<TableItem>();
	List<Object> dataList = Arrays.asList(data);
	for (TableItem tableItem : table.getItems()) {
		if (dataList.contains(tableItem.getData())) {
			tableItems.add(tableItem);
		}
	}
	return tableItems.toArray(new TableItem[] {});
}
 
Example 7
Source Project: arx   File: ClipboardHandlerTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Renders the table into a string.
 *
 * @param table
 * @return
 */
private String getText(Table table){

    StringBuilder builder = new StringBuilder();
    
    TableColumn[] columns = table.getColumns();
    for (int i = 0; i < columns.length; i++) {
        TableColumn column = columns[i];
        builder.append(column.getText());
        if (i < columns.length - 1) {
            builder.append(";");
        } else {
            builder.append("\n");
        }
    }
    
    for (TableItem item : table.getItems()) {
        for (int i = 0; i < columns.length; i++) {
            String value = item.getText(i);
            if (value != null && !value.equals("")) { //$NON-NLS-1$
                builder.append(value); //$NON-NLS-1$
            } else if (item.getData(String.valueOf(i)) != null && 
                       item.getData(String.valueOf(i)) instanceof Double) {
                builder.append(SWTUtil.getPrettyString(((Double) item.getData(String.valueOf(i))).doubleValue() * 100d) + "%"); //$NON-NLS-1$
            }
            if (i < columns.length - 1) {
                builder.append(";");
            } else {
                builder.append("\n");
            }
        }
    }
    
    return builder.toString();
}
 
Example 8
Source Project: uima-uimaj   File: AbstractSection.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the index.
 *
 * @param item the item
 * @return the index
 */
public static int getIndex(TableItem item) {
  Table parent = item.getParent();
  TableItem[] items = parent.getItems();
  for (int i = items.length - 1; i >= 0; i--) {
    if (items[i] == item)
      return i;
  }
  throw new InternalErrorCDE("invalid state"); //$NON-NLS-1$
}
 
Example 9
Source Project: uima-uimaj   File: AbstractSection.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Swap table items.
 *
 * @param itemBelow the item below
 * @param newSelection the new selection
 */
public static void swapTableItems(TableItem itemBelow, int newSelection) {
  Table parent = itemBelow.getParent();
  int i = getIndex(itemBelow);
  TableItem itemAbove = parent.getItems()[i - 1];
  TableItem newItemAbove = new TableItem(parent, SWT.NONE, i - 1);
  copyTableItem(newItemAbove, itemBelow);
  TableItem newItemBelow = new TableItem(parent, SWT.NONE, i);
  copyTableItem(newItemBelow, itemAbove);
  itemAbove.dispose();
  itemBelow.dispose();
  parent.setSelection(newSelection);
}
 
Example 10
public static void sortTable(Table table, TableColumn column) {
	TableItem[] items = table.getItems();
	int rows = items.length;
	int dir = table.getSortDirection() == SWT.DOWN ? 1 : -1;
	TableColumn currentColumn = table.getSortColumn();
	int columnNum = 0;
	for (int j = 0; j < table.getColumnCount(); j++) {
		if (table.getColumn(j).equals(column)) {
			columnNum = j;
			break;
		}
	}
	if (column.equals(currentColumn))
		dir = -dir;
	else
		dir = 1;

	// sort an index map, then move the actual rows
	int[] map = new int[rows];
	for (int i = 0; i < rows; i++)
		map[i] = i;

	for (int i = 0; i < rows - 1; i++) {
		for (int j = i + 1; j < rows; j++) {
			TableItem a = items[map[i]];
			TableItem b = items[map[j]];
			if ((a.getText(columnNum).toLowerCase().compareTo(b.getText(columnNum).toLowerCase()) * dir > 0)) {
				int t = map[i];
				map[i] = map[j];
				map[j] = t;
			}
		}
	}

	// can't move existing items or delete first, so append new items to the end and then delete existing rows
	for (int i = 0; i < rows; i++) {
		int n = map[i];
		TableItem item = new TableItem(table, SWT.NONE);
		for (int j = 0; j < table.getColumnCount(); j++) {
			item.setText(j, items[n].getText(j));
		}
		item.setData(items[n].getData());
		items[n].dispose();
	}

	table.setSortDirection(dir == 1 ? SWT.DOWN : SWT.UP);
	table.setSortColumn(column);
}
 
Example 11
Source Project: SWET   File: TableEditorEx.java    License: MIT License 4 votes vote down vote up
private static void appendRowToTable(Table table, List<String> stepIds) {

		TableItem[] tableItems = table.getItems();
		int cnt = 0;
		for (String stepId : stepIds) {

			// get element data
			TableItem tableItem = tableItems[cnt];
			Map<String, String> elementData = testData.get(stepId);
			String selectorChoice = selectorFromSWD
					.get(elementData.get("ElementSelectedBy"));

			String selectorValue = elementData
					.get(elementData.get("ElementSelectedBy"));

			// Append row into the TableEditor
			tableItem.setText(new String[] { elementData.get("ElementStepNumber"),
					elementData.get("ElementCodeName"), String.format("Action %d", cnt),
					selectorChoice, selectorValue });
			// some columns need to be converted to selects

			TableEditor keywordChoiceEditor = new TableEditor(table);
			CCombo keywordChoiceCombo = new CCombo(table, SWT.NONE);
			keywordChoiceCombo.setText("Choose..");
			for (String keyword : keywordTable.keySet()) {
				keywordChoiceCombo.add(keyword);
			}
			// NOTE: none of options is initially selected
			keywordChoiceEditor.grabHorizontal = true;
			int keywordChoiceColumn = 2;
			keywordChoiceCombo.setData("column", keywordChoiceColumn);
			keywordChoiceCombo.setData("item", tableItem);
			keywordChoiceEditor.setEditor(keywordChoiceCombo, tableItem,
					keywordChoiceColumn);
			keywordChoiceCombo.addModifyListener(new keywordChoiceListener());

			TableEditor selectorChoiceEditor = new TableEditor(table);
			CCombo selectorChoiceCombo = new CCombo(table, SWT.NONE);
			for (String locator : selectorFromSWD.values()) {
				selectorChoiceCombo.add(locator);
			}
			// java.lang.ClassCastException: java.util.LinkedHashMap$LinkedValues
			// cannot be cast to java.util.List
			selectorChoiceCombo.select(new ArrayList<String>(selectorFromSWD.values())
					.indexOf(selectorFromSWD.get(elementData.get("ElementSelectedBy"))));
			selectorChoiceEditor.grabHorizontal = true;
			int selectorChoiceColumn = 3;
			selectorChoiceCombo.setData("item", tableItem);
			selectorChoiceCombo.setData("column", selectorChoiceColumn);
			selectorChoiceEditor.setEditor(selectorChoiceCombo, tableItem,
					selectorChoiceColumn);
			selectorChoiceCombo.addModifyListener(new selectorChoiceListener());
			cnt = cnt + 1;
		}
		return;
	}
 
Example 12
/**
 *
 */
public void saveAsCSV() {
	try {
		Files.newFolder(getScope(), exportFolder);
	} catch (final GamaRuntimeException e1) {
		e1.addContext("Impossible to create folder " + exportFolder);
		GAMA.reportError(getScope(), e1, false);
		e1.printStackTrace();
		return;
	}

	final String exportFileName = FileUtils.constructAbsoluteFilePath(getScope(),
			exportFolder + "/" + getSpeciesName() + "_population" + getScope().getClock().getCycle() + ".csv",
			false);
	final Table table = viewer.getTable();
	final TableColumn[] columns = table.getColumns();
	try (final CsvWriter writer = new CsvWriter(exportFileName);) {
		// AD 2/1/16 Replaces the comma by ';' to properly output points and
		// lists
		writer.setDelimiter(';');
		writer.setUseTextQualifier(false);

		final List<String[]> contents = new ArrayList<>();
		final String[] headers = new String[columns.length];
		int columnIndex = 0;
		for (final TableColumn column : columns) {
			headers[columnIndex++] = column.getText();
		}
		contents.add(headers);
		final TableItem[] items = table.getItems();
		for (final TableItem item : items) {
			final String[] row = new String[columns.length];
			for (int i = 0; i < columns.length; i++) {
				row[i] = item.getText(i);
			}
			contents.add(row);
		}
		try {
			for (final String[] ss : contents) {
				writer.writeRecord(ss);
			}

		} catch (final IOException e) {
			throw GamaRuntimeException.create(e, getScope());

		}
	}
}