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

The following examples show how to use org.eclipse.swt.widgets.TableColumn#setData() . 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
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 2
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 3
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Apply the current search condition as a new filter.
 *
 * @since 2.0
 */
protected void applySearchAsFilter() {
    Object searchObj = fTable.getData(Key.SEARCH_OBJ);
    if (searchObj instanceof ITmfFilter) {
        ITmfFilter filter = (ITmfFilter) searchObj;
        fTable.setData(Key.SEARCH_OBJ, null);
        fireSearchApplied(null);
        fHeaderState = HeaderState.NO_SEARCH;
        for (final TableColumn col : fTable.getColumns()) {
            col.setData(Key.FILTER_TXT, col.getData(Key.SEARCH_TXT));
            col.setData(Key.SEARCH_TXT, null);
            col.setData(Key.SEARCH_OBJ, null);
        }
        applyFilter(filter);
    }
}
 
Example 4
Source File: CoverageLabelProvider.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * @param stateTable
 */
void createTableColumns(final Table stateTable, final TableColumnLayout layout) {
	for (int i = 0; i < COLUMN_TITLES.length; i++) {
		final TableColumn column = new TableColumn(stateTable, SWT.NULL);
		column.setWidth(COLUMN_WIDTHS[i]);
		column.setText(COLUMN_TITLES[i]);
		column.setToolTipText(COLUMN_TOOLTIPS[i]);
		column.setData(COVERAGE_COMPARATOR, COLUMN_COMP[i]);

		final int weight = (int)(100.0 * COLUMN_WIDTH_PERCENTAGES[i]);
		layout.setColumnData(column, new ColumnWeightData(weight, COLUMN_WIDTHS[i], true));
	}
}
 
Example 5
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 6
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 7
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clear all currently active filters.
 */
protected void clearFilters() {
    if (fTable.getData(Key.FILTER_OBJ) == null) {
        return;
    }
    stopFilterThread();
    stopSearchThread();
    fCache.clearFilter();
    fHeaderBar.clearFilters();
    fCollapseFilterEnabled = false;
    fTable.clearAll();
    for (final TableColumn column : fTable.getColumns()) {
        column.setData(Key.FILTER_OBJ, null);
        column.setData(Key.FILTER_TXT, null);
    }
    fTable.setData(Key.FILTER_OBJ, null);
    if (fTrace != null) {
        /* +1 for header row */
        fTable.setItemCount((int) fTrace.getNbEvents() + 1);
    } else {
        /* +1 for header row */
        fTable.setItemCount(1);
    }
    fFilterMatchCount = 0;
    fFilterCheckCount = 0;
    if (fSelectedRank >= 0) {
        /* +1 for header row */
        fTable.setSelection((int) fSelectedRank + 1);
    } else {
        fTable.setSelection(0);
    }
    fireFilterApplied(null);
    updateStatusLine(null);

    // Set original width
    fTable.getColumns()[MARGIN_COLUMN_INDEX].setWidth(0);
    packMarginColumn();
}
 
Example 8
Source File: TmfEventsTable.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Sets the column width and resizability
 *
 * @param width
 *            an array of widths
 * @param resizable
 *            an array of bools saying if a column is resizable or not
 * @since 2.1
 */
public void setColumnWidth(int[] width, boolean[] resizable) {
    int length = fTable.getColumns().length;
    if (width == null || resizable == null || resizable.length != length || width.length != length) {
        return;
    }
    if (width.length > 0 && width[0] == 0) {
        /*
         * When width of margin column is 0 instead of SWT.DEFAULT, it is an old
         * setting. Reset all widths to SWT.DEFAULT to initially enable AutoFit.
         */
        Arrays.fill(width, SWT.DEFAULT);
    }
    int i = 0;
    for (TableColumn column : fTable.getColumns()) {
        if (i != MARGIN_COLUMN_INDEX) {
            column.setData(Key.WIDTH, width[i]);
            column.setResizable(resizable[i]);
            if (column.getResizable() && width[i] > 0) {
                column.setWidth(width[i]);
            } else if (width[i] == 0) {
                column.setWidth(0);
            }
        }
        i++;
    }
    fColumnSize = width;
    fColumnResizable = resizable;
}