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

The following examples show how to use org.eclipse.swt.widgets.Table#getColumn() . 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 check out the related API usage on the sidebar.
Example 1
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns true if the column is expanded to take extra available space.
 * This is the last non-zero-width visible column in the column order on
 * Linux. This column's width should not be persisted.
 *
 * @param column
 *            the column
 * @return true if the column is expanded.
 */
private static boolean isExpanded(TableColumn column) {
    if (IS_LINUX) {
        Table table = column.getParent();
        int[] order = table.getColumnOrder();
        for (int i = order.length - 1; i >= 0; i--) {
            TableColumn col = table.getColumn(order[i]);
            if (col == column) {
                return true;
            }
            if (col.getWidth() > 0) {
                return false;
            }
        }
    }
    return false;
}
 
Example 2
Source File: CloneDiffTooltip.java    From JDeodorant with MIT License 6 votes vote down vote up
protected void packAndFillLastColumn(Table table) {
    int columnsWidth = 0;
    for (int i = 0; i < table.getColumnCount() - 1; i++) {
        columnsWidth += table.getColumn(i).getWidth();
    }
    TableColumn lastColumn = table.getColumn(table.getColumnCount() - 1);
    lastColumn.pack();

    Rectangle area = table.getClientArea();

    Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    int width = area.width - 2*table.getBorderWidth();

    if (preferredSize.y > area.height + table.getHeaderHeight()) {
        // Subtract the scrollbar width from the total column width
        // if a vertical scrollbar will be required
        Point vBarSize = table.getVerticalBar().getSize();
        width -= vBarSize.x;
    }

    // last column is packed, so that is the minimum. If more space is available, add it.
    if(lastColumn.getWidth() < width - columnsWidth) {
        lastColumn.setWidth(width - columnsWidth + 4);
    }
}
 
Example 3
Source File: CausalFactorTable.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
public void render(Section section, FormToolkit toolkit) {
	Composite composite = UI.sectionClient(section, toolkit, 1);
	String[] columnTitles = getColumnTitles();
	viewer = Tables.createViewer(composite, columnTitles);
	viewer.setLabelProvider(new FactorLabel());
	Action copy = TableClipboard.onCopy(viewer);
	Actions.bind(viewer, copy);
	Tables.bindColumnWidths(viewer, 0.2, 0.1, 0.1, 0.1);
	createModifySupport();
	Table table = viewer.getTable();
	for (int i = 0; i < table.getColumnCount(); i++) {
		if (i < 4)
			continue;
		TableColumn column = table.getColumn(i);
		if (!editor.hasAnyComment("allocationFactors") || i % 2 == 0) {
			column.setWidth(80);
			column.setToolTipText(columnTitles[i]);
		} else {
			column.setWidth(24);
		}
	}
	for (int i = 3; i < table.getColumnCount(); i++) {
		viewer.getTable().getColumns()[i].setAlignment(SWT.RIGHT);
	}
}
 
Example 4
Source File: ExportToTsvUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Export content of a table to TSV file
 * @param table
 *              the table to export
 * @param stream
 *              the output stream
 */
public static void exportTableToTsv(Table table, @Nullable OutputStream stream) {
    if (table == null || stream == null) {
        return;
    }
    try (PrintWriter pw = new PrintWriter(stream)) {
        int size = table.getItemCount();
        List<String> columns = new ArrayList<>();
        for (int i = 0; i < table.getColumnCount(); i++) {
            TableColumn column = table.getColumn(i);
            if (column == null) {
                return;
            }
            String columnName = String.valueOf(column.getText());
            if (columnName.isEmpty() && i == table.getColumnCount() - 1) {
                // Linux GTK2 undocumented feature
                break;
            }
            columns.add(columnName);
        }
        pw.println(Joiner.on('\t').join(columns));
        for (int i = 0; i < size; i++) {
            TableItem item = table.getItem(i);
            if (item == null) {
                continue;
            }
            List<String> data = new ArrayList<>();
            for (int col = 0; col < columns.size(); col++) {
                data.add(String.valueOf(item.getText(col)));
            }
            pw.println(Joiner.on('\t').join(data));
        }
    }
}
 
Example 5
Source File: TableClipboard.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private static void copyHeaders(Table table, StringBuilder text) {
	int cols = table.getColumnCount();
	for (int col = 0; col < cols; col++) {
		TableColumn column = table.getColumn(col);
		String s = column.getText();
		text.append(s == null ? "" : s);
		if (col != (cols - 1))
			text.append('\t');
	}
	text.append('\n');
}
 
Example 6
Source File: HeaderLayout.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected Widget getColumnAt(Composite rowOrHeader, int offset) {
    Table headerTable = getHeader(rowOrHeader).headerTable;
    int[] columnOrder = headerTable.getColumnOrder();
    return headerTable.getColumn(columnOrder[offset]);
}
 
Example 7
Source File: UiUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static int getColumnTextWidth(Table table, GC gc, int i) {
  TableColumn tableColumn = table.getColumn(i);
  int maxTextExtent = 20 + gc.textExtent(tableColumn.getText()).x;
  return maxTextExtent;
}
 
Example 8
Source File: SwtUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static int getColumnTextWidth(Table table, GC gc, int i) {
	TableColumn tableColumn = table.getColumn(i);
	int maxTextExtent = 20 + gc.textExtent(tableColumn.getText()).x;
	return maxTextExtent;
}