Java Code Examples for org.eclipse.swt.widgets.TableColumn#getData()

The following examples show how to use org.eclipse.swt.widgets.TableColumn#getData() . 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: MergeProcessorColumnSelectionListener.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void widgetSelected(SelectionEvent e) {
	final TableColumn column = (TableColumn) e.widget;
	final TableViewerColumn viewerColumn = (TableViewerColumn) column.getData(COLUMN_VIEWER_KEY);
	final Table table = column.getParent();
	comparator.setColumn(table.indexOf(column));
	if (table.getSortColumn() == column) {
		table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
	} else {
		table.setSortColumn(column);
		table.setSortDirection(SWT.DOWN);
	}
	viewerColumn.getViewer().refresh();
	configuration.setSortColumn(Column.valueForIndex(table.indexOf(column)));
	configuration.setSortDirection(table.getSortDirection());
}
 
Example 2
Source File: EventViewTable.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void widgetSelected ( final SelectionEvent e )
{
    final Table table = this.tableViewer.getTable ();
    final TableColumn newColumn = (TableColumn)e.widget;
    final TableColumn currentColumn = table.getSortColumn ();

    final EventTableColumn column = (EventTableColumn)newColumn.getData ( COLUMN_KEY );
    if ( column == EventTableColumn.reservedColumnSourceTimestamp || column == EventTableColumn.reservedColumnEntryTimestamp )
    {
        final int currentDir = table.getSortDirection ();
        int newDir = SWT.UP;
        if ( newColumn == currentColumn )
        {
            newDir = currentDir == SWT.UP ? SWT.DOWN : SWT.UP;
        }
        else
        {
            table.setSortColumn ( newColumn );
        }
        table.setSortDirection ( newDir );
        this.tableViewer.setSorter ( new EventTableSorter ( column, newDir ) );
    }
}
 
Example 3
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private IAction createAutoFitAction(TableColumn column) {
    final IAction autoFitAction = new Action(Messages.TmfEventsTable_AutoFit, IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            boolean isChecked = isChecked();
            int index = (int) column.getData(Key.INDEX);
            if (isChecked) {
                fPacking = true;
                column.pack();
                fPacking = false;
                column.setData(Key.WIDTH, SWT.DEFAULT);
                fColumnSize[index] = SWT.DEFAULT;
            } else {
                fColumnSize[index] = column.getWidth();
                column.setData(Key.WIDTH, fColumnSize[index]);
            }
        }
    };
    autoFitAction.setChecked(Objects.equals(column.getData(Key.WIDTH), SWT.DEFAULT));
    return autoFitAction;
}
 
Example 4
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private IAction createShowAllAction() {
    return new Action(Messages.TmfEventsTable_ShowAll) {
        @Override
        public void run() {
            for (TableColumn column : fTable.getColumns()) {
                int index = (int) column.getData(Key.INDEX);
                if (index != MARGIN_COLUMN_INDEX) {
                    final int width = (int) column.getData(Key.WIDTH);
                    column.setResizable(true);
                    if (width <= 0) {
                        fPacking = true;
                        column.pack();
                        fPacking = false;
                        column.setData(Key.WIDTH, SWT.DEFAULT);
                        fColumnSize[index] = SWT.DEFAULT;
                    } else {
                        column.setWidth(width);
                    }
                    fColumnResizable[index] = true;
                }
            }
            fTable.refresh();
        }
    };
}
 
Example 5
Source File: CoverageViewerComparator.java    From tlaplus with MIT License 5 votes vote down vote up
@Override
public int compare(final Viewer viewer, final Object e1, final Object e2) {
	final ActionInformationItem a1 = (ActionInformationItem) e1;
	final ActionInformationItem a2 = (ActionInformationItem) e2;

	final Table table = (Table) viewer.getControl();
	final TableColumn sortColumn = table.getSortColumn();
	if (sortColumn == null) {
		// a) Compare by distinct states first (we want actions with zero distinct states
		// to appear at the top).
		if (Long.compare(a1.getUnseen(), a2.getUnseen()) == 0L) {
			// b) Compare by location
			return a1.getModuleLocation().compareTo(a2.getModuleLocation());
		} else {
			return Long.compare(a1.getUnseen(), a2.getUnseen());
		}
	} else {
		// User requested to sort a specific column up or down.
		@SuppressWarnings("unchecked")
		final Comparator<ActionInformationItem> comp = (Comparator<ActionInformationItem>) sortColumn
				.getData(CoverageLabelProvider.COVERAGE_COMPARATOR);
		if (table.getSortDirection() == SWT.UP) {
			return comp.compare(a2, a1);
		} else {
			return comp.compare(a1, a2);
		}
	}
}
 
Example 6
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void controlResized(ControlEvent e) {
    TableColumn column = (TableColumn) e.widget;
    if (fPacking) {
        /* Don't update column width if resize due to packing */
        return;
    }
    if (column.getResizable() && !isExpanded(column)) {
        int index = (int) column.getData(Key.INDEX);
        fColumnSize[index] = column.getWidth();
        /* Turns off AutoFit */
        column.setData(Key.WIDTH, fColumnSize[index]);
    }
}
 
Example 7
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private IAction createShowColumnAction(final TableColumn column) {
    final IAction columnMenuAction = new Action(column.getText(), IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            boolean isChecked = isChecked();
            int index = (int) column.getData(Key.INDEX);
            if (isChecked) {
                int width = (int) column.getData(Key.WIDTH);
                column.setResizable(true);
                if (width <= 0) {
                    fPacking = true;
                    column.pack();
                    fPacking = false;
                    column.setData(Key.WIDTH, SWT.DEFAULT);
                    fColumnSize[index] = SWT.DEFAULT;
                } else {
                    column.setWidth(width);
                }
            } else {
                column.setResizable(false);
                column.setWidth(0);
            }
            fColumnResizable[index] = isChecked;
            fTable.refresh();
        }
    };
    columnMenuAction.setChecked(column.getResizable());
    return columnMenuAction;
}
 
Example 8
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set the item data of the header row.
 *
 * @param item
 *            The item to use as table header
 */
protected void setHeaderRowItemData(final TableItem item) {
    if (fHeaderState == HeaderState.NO_SEARCH) {
        item.setImage(SEARCH_IMAGE);
    } else if (fHeaderState == HeaderState.SEARCH) {
        item.setImage(FILTER_ADD_IMAGE);
    }
    item.setForeground(fGrayColor);
    // Ignore collapse and image column
    for (int i = EVENT_COLUMNS_START_INDEX; i < fTable.getColumns().length; i++) {
        final TableColumn column = fTable.getColumns()[i];
        final String filter = (String) column.getData(Key.SEARCH_TXT);
        if (filter == null) {
            item.setText(i, SEARCH_HINT);
            item.setForeground(i, fGrayColor);
            item.setFont(i, fFont);
        } else {
            item.setText(i, filter);
            item.setForeground(i, fGreenColor);
            item.setFont(i, fBoldFont);
        }
    }
    if (!fPackMarginDone) {
        packMarginColumn();
        fPackMarginDone = true;
    }
}
 
Example 9
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Returns true if the column is a visible event column.
 *
 * @param column
 *            the column
 * @return false if the column is the margin column or hidden, true
 *         otherwise
 */
private static boolean isVisibleEventColumn(TableColumn column) {
    if (column.getData(Key.ASPECT) == TmfMarginColumn.MARGIN_ASPECT) {
        return false;
    }
    return !(!column.getResizable() && column.getWidth() == 0);
}