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

The following examples show how to use org.eclipse.swt.widgets.Table#pack() . 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: SetupOptionsPage.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return table created with the provided data and tool tip, or {@code null} if no data. */
private static Table createTable(Composite parent, Map<String, String> data, String toolTipText, String label) {
	if (data == null || data.isEmpty())
		return null;

	new Label(parent, SWT.HORIZONTAL | SWT.SEPARATOR).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
	new Label(parent, SWT.NONE).setText(label);
	Table table = new Table(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
	table.setLinesVisible(true);
	table.setHeaderVisible(true);
	table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	table.setToolTipText(toolTipText);
	TableColumn nameColumn = new TableColumn(table, SWT.NONE);
	nameColumn.setText("name");
	TableColumn locationColumn = new TableColumn(table, SWT.NONE);
	locationColumn.setText("Location");
	TableItem defaultItem = new TableItem(table, SWT.NONE);
	defaultItem.setText(0, "default");
	defaultItem.setText(1, "default settings");

	data.forEach((path, name) -> {
		TableItem item = new TableItem(table, SWT.NONE);
		item.setText(0, name);
		item.setText(1, path);
	});

	table.getColumn(0).pack();
	table.getColumn(1).pack();
	table.pack(true);
	return table;
}
 
Example 2
Source File: SelectionDialog.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
private final void createTableDialogArea(final Composite parent) {

		String[] inputKeys = getSelectableKeys();
		int columnCount = 0;
		Point dimens = getColumnCount( parent, inputKeys, sizeHint.x); 
		int count = dimens.x;

		GridLayout compositeLayout = new GridLayout(count,true);
		parent.setLayout(compositeLayout);
		parent.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		Table table = new Table(parent, SWT.V_SCROLL | SWT.HORIZONTAL | SWT.WRAP | SWT.FULL_SELECTION); //| SWT.MULTI);
		GridData gridData = new GridData(GridData.FILL_BOTH);
		table.setLayoutData(gridData);
		table.setBackground(parent.getBackground());
		table.setLinesVisible(true);
		table.setHeaderVisible(false);
		
		int columnWidth = (sizeHint.x - getSizeAdjustment()) / count;
		
		TableColumn[] columns = new TableColumn[count];
		for (int i = 0; i < count; i++) {
			columns[i] = new TableColumn(table, SWT.LEFT, columnCount++);
			columns[i].setWidth(columnWidth);
		}
		TableColumnLayout layout = new TableColumnLayout();
		for (int i = 0; i < count; i++) {
			layout.setColumnData(columns[i], new ColumnWeightData(100/count,columnWidth,false));
		}
		parent.setLayout(layout);
		
		int len = inputKeys.length;
		int rowCount = len / columnCount;
		if ((len - rowCount * columnCount) > 0) {
			rowCount++;
		}
		for (int i = 0; i < rowCount; i++) {
			String[] row = new String[columnCount];
			for (int j = 0; j < columnCount; j++) {
				int sourceIndex = i * columnCount + j;
				row[j] = (sourceIndex < len ? (String) inputKeys[sourceIndex] : ""); //$NON-NLS-1$ 
			}
			TableItem item = new TableItem(table, SWT.NULL);
			item.setText(row);
		}

		table.pack();
		sizeHint.y = Math.min(table.getBounds().height + getSizeAdjustment(),sizeHint.y);

		Dialog.applyDialogFont(parent);
		addTableListeners(table);
	}