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

The following examples show how to use org.eclipse.swt.widgets.Table#getSelection() . 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
Source Project: n4js   File: SetupOptionsPage.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** Expects one row selected in the table and returns value of second row. */
private String getTableItem(Table table) {
	String result = "";
	if (table == null)
		return result;

	TableItem[] items = table.getSelection();

	if (items.length >= 2) {
		String text = Strings.nullToEmpty(table.getToolTipText());
		if (!text.isEmpty())
			text = " :: " + text;
		throw new RuntimeException("Multiple selections are not supported" + text);
	}

	if (items.length == 1 && items[0] != null)
		// first is the display name, second is data
		result = Strings.nullToEmpty(items[0].getText(1));

	return result;
}
 
Example 2
Source Project: logbook   File: TableToClipboardAdapter.java    License: MIT License 6 votes vote down vote up
/**
 * テーブルの選択されている部分をヘッダー付きでクリップボードにコピーします
 *
 * @param header ヘッダー
 * @param table テーブル
 */
public static void copyTable(String[] header, Table table) {
    TableItem[] tableItems = table.getSelection();
    StringBuilder sb = new StringBuilder();
    sb.append(StringUtils.join(header, "\t"));
    sb.append("\r\n");
    for (TableItem column : tableItems) {
        String[] columns = new String[header.length];
        for (int i = 0; i < header.length; i++) {
            columns[i] = column.getText(i);
        }
        sb.append(StringUtils.join(columns, "\t"));
        sb.append("\r\n");
    }
    Clipboard clipboard = new Clipboard(Display.getDefault());
    clipboard.setContents(new Object[] { sb.toString() }, new Transfer[] { TextTransfer.getInstance() });
}
 
Example 3
private void handleTableSelectionChanged() {
    Table fieldTable = fieldViewer.getTable();
    TableItem[] items = fieldTable.getSelection();
    boolean validSelection = items != null && items.length > 0;
    boolean enableUp = validSelection;
    boolean enableDown = validSelection;
    if (validSelection) {
        int indices[] = fieldTable.getSelectionIndices();
        int max = fieldTable.getItemCount();
        enableUp = indices[0] != 0;
        enableDown = indices[indices.length - 1] < max - 1;
    }
    upButton.setEnabled(enableUp);
    downButton.setEnabled(enableDown);
}
 
Example 4
Source Project: olca-app   File: TableClipboard.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private static void copyItems(Table table, Converter converter,
		StringBuilder buffer) {
	int cols = table.getColumnCount();
	for (TableItem item : table.getSelection()) {
		for (int col = 0; col < cols; col++) {
			String s = converter.asString(item, col);
			buffer.append(s);
			if (col != (cols - 1)) {
				buffer.append('\t');
			}
		}
		buffer.append('\n');
	}
}
 
Example 5
/**
 * Returns the <code>ColumnItem</code>s that is currently selected in the
 * receiver.
 *
 * @return the selected item, or <code>null</code> if no one is selected
 *
 * @exception SWTException
 *                <ul>
 *                <li>ERROR_WIDGET_DISPOSED - if the receiver has been
 *                disposed</li>
 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
 *                thread that created the receiver</li>
 *                </ul>
 */
public ColumnItem getSelection() {
	for (int i = columns.size() - 1; i >= 0; i--) {
		final Table table = columns.get(i);
		if (table == null || table.getData() == null || table.getSelection().length == 0) {
			continue;
		}
		return (ColumnItem) table.getItem(table.getSelectionIndex()).getData();
	}
	return null;
}