Java Code Examples for org.eclipse.jface.viewers.TableViewer#setSorter()

The following examples show how to use org.eclipse.jface.viewers.TableViewer#setSorter() . 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: KeyValueListFieldEditor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (newInput == null){
        return;
    }
    if (viewer instanceof TableViewer){
        TableViewer tableViewer = (TableViewer) viewer;
        if (tableViewer.getTable().isDisposed()) {
            return;
        }
        tableViewer.setSorter(new ViewerSorter() {
            public int compare(Viewer iviewer, Object e1, Object e2) {
                if (e1 == null) {
                    return -1;
                } else if (e2 == null) {
                    return 1;
                } else {
                    return ((EnvironmentVariable)e1).getName().compareToIgnoreCase(((EnvironmentVariable)e2).getName());
                }
            }
        });
    }
}
 
Example 2
Source File: StyleListFieldEditor.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    if (newInput == null){
        return;
    }
    if (viewer instanceof TableViewer){
        TableViewer tableViewer = (TableViewer) viewer;
        if (tableViewer.getTable().isDisposed()) {
            return;
        }
        tableViewer.setSorter(new ViewerSorter() {
            public int compare(Viewer iviewer, Object e1, Object e2) {
                if (e1 == null) {
                    return -1;
                } else if (e2 == null) {
                    return 1;
                } else {
                    return ((SmartKeyVariable)e1).getName().compareToIgnoreCase(((SmartKeyVariable)e2).getName());
                }
            }
        });
    }
}
 
Example 3
Source File: BuildpathJarSelectionDialog.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
  Composite grid = new Composite(parent, SWT.NONE);
  GridData gridData = new GridData(GridData.FILL_BOTH);
  grid.setLayoutData(gridData);
  GridLayout gridLayout = new GridLayout(1, false);
  gridLayout.marginHeight = 8;
  gridLayout.marginWidth = 8;
  grid.setLayout(gridLayout);

  Label descriptionLabel = new Label(grid, SWT.NONE);
  descriptionLabel.setText("Select JAR file(s) from the build path:");

  jarsViewer = new TableViewer(grid);
  GridData jarsListGridData = new GridData(GridData.FILL_BOTH);
  jarsViewer.getTable().setLayoutData(jarsListGridData);
  jarsViewer.setContentProvider(new ArrayContentProvider());
  jarsViewer.setLabelProvider(new JarsLabelProvider());
  jarsViewer.setSorter(jarsSorter);

  return grid;
}
 
Example 4
Source File: HistoryTableProvider.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void setSortColumn(final TableViewer tableViewer, int column) {
		HistorySorter oldSorter = (HistorySorter)tableViewer.getSorter();
		if (oldSorter != null && column == oldSorter.getColumnNumber()) {
			oldSorter.setReversed(!oldSorter.isReversed());
			if (oldSorter.isReversed()) tableViewer.getTable().setSortDirection(SWT.DOWN);
			else tableViewer.getTable().setSortDirection(SWT.UP);	
			tableViewer.refresh();
		} else {
			HistorySorter newSorter = new HistorySorter(column);
			if (column == 0) newSorter.setReversed(true);
			tableViewer.setSorter(newSorter);
			if (column == 0)tableViewer.getTable().setSortDirection(SWT.DOWN);
			else tableViewer.getTable().setSortDirection(SWT.UP);
		}
//				tableViewer.getTable().setSortColumn((TableColumn)e.widget);
		tableViewer.getTable().setSortColumn(tableViewer.getTable().getColumn(column));
	}
 
Example 5
Source File: HistoryTableProvider.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a TableViewer that can be used to display a list of ILogEntry instances.
 * Ths method provides the labels and sorter but does not provide a content provider
 * 
 * @param parent
 * @return TableViewer
 */
public TableViewer createTable(Composite parent) {
	Table table = new Table(parent, style);
	table.setHeaderVisible(true);
	table.setLinesVisible(true);
	GridData data = new GridData(GridData.FILL_BOTH);
	data.horizontalIndent = 0;
	data.verticalIndent = 0;
	table.setLayoutData(data);

	TableLayout layout = new TableLayout();
	table.setLayout(layout);
	
	TableViewer viewer = new TableViewer(table);
	
	createColumns(table, layout, viewer);

	viewer.setLabelProvider(new HistoryLabelProvider());
	
	HistorySorter sorter = new HistorySorter(COL_REVISION);
	viewer.setSorter(sorter);
	table.setSortDirection(SWT.DOWN);
	table.setSortColumn(table.getColumn(0));

       table.addDisposeListener(new DisposeListener() {
           public void widgetDisposed(DisposeEvent e) {
               if(currentRevisionFont != null) {
                   currentRevisionFont.dispose();
               }
           }
       });
       
	this.viewer = viewer;
	return viewer;
}
 
Example 6
Source File: EditExpressionDialog.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createExpressionTypePanel(final Composite parentForm) {
    final Composite parentComposite = new Composite(parentForm, SWT.NONE);
    parentComposite
            .setLayoutData(GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.FILL).grab(false, true).create());
    parentComposite.setLayout(GridLayoutFactory.fillDefaults().spacing(LayoutConstants.getSpacing().x, 1).create());

    final Label expressionTypeLabel = new Label(parentComposite, SWT.NONE);
    expressionTypeLabel.setText(Messages.expressionTypeLabel);
    expressionTypeLabel.setLayoutData(GridDataFactory.swtDefaults().grab(true, false).create());

    expressionTypeViewer = new TableViewer(parentComposite, SWT.FULL_SELECTION | SWT.BORDER | SWT.SINGLE);
    expressionTypeViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    expressionTypeViewer.setContentProvider(new ExpressionTypeContentProvider());
    expressionTypeViewer.setLabelProvider(new ExpressionTypeLabelProvider());
    expressionTypeViewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(final Viewer viewer, final Object e1, final Object e2) {
            final IExpressionProvider p1 = (IExpressionProvider) e1;
            final IExpressionProvider p2 = (IExpressionProvider) e2;
            return p1.getTypeLabel().compareTo(p2.getTypeLabel());
        }
    });
    if (viewerTypeFilters != null) {
        expressionTypeViewer.setFilters(viewerTypeFilters);
    }
    if (!filteredEditor.isEmpty()) {
        expressionTypeViewer.addFilter(filterEditor());
    }
    ColumnViewerToolTipSupport.enableFor(expressionTypeViewer, ToolTip.NO_RECREATE);
    expressionTypeViewer.setInput(expressionViewer.getInput());
}
 
Example 7
Source File: ParameterPropertySection.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createParameterComposite(final Composite parent) {
    final Composite parameterComposite = getWidgetFactory().createComposite(parent);
    parameterComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    parameterComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());

    final Composite buttonsComposite = getWidgetFactory().createComposite(parameterComposite, SWT.NONE);
    buttonsComposite.setLayout(GridLayoutFactory.fillDefaults().spacing(0, 3).create());
    buttonsComposite.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).create());

    createAddParameterButton(buttonsComposite);
    updateButton = createUpdateParameterButton(buttonsComposite);
    createRemoveParameterButton(buttonsComposite);

    parameterTableViewer = new TableViewer(widgetFactory.createTable(parameterComposite,
            GTKStyleHandler.removeBorderFlag(SWT.BORDER | SWT.MULTI | SWT.NO_FOCUS | SWT.H_SCROLL | SWT.V_SCROLL)));
    parameterTableViewer.getTable().setLayout(GridLayoutFactory.fillDefaults().create());
    getWidgetFactory().adapt(parameterTableViewer.getTable(), false, false);
    parameterTableViewer.getTable()
            .setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
    parameterTableViewer.setSorter(new ViewerSorter());
    parameterTableViewer.addDoubleClickListener(this);
    parameterTableViewer.addSelectionChangedListener(this);
    parameterTableViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL) {
                e.doit = false;
                remove();
            }
        }
    });

    parameterTableViewer.setContentProvider(new ArrayContentProvider());
    parameterTableViewer.setLabelProvider(new ParameterStyledLabelProvider());
    ColumnViewerToolTipSupport.enableFor(parameterTableViewer, ToolTip.RECREATE);
}
 
Example 8
Source File: AbstractDataSection.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected void createDataComposite(final Composite parent) {
    createViewerHeaderLabel(parent);

    final Composite buttonsComposite = getWidgetFactory().createComposite(parent, SWT.NONE);
    buttonsComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).spacing(0, 3).create());
    buttonsComposite.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).create());

    createAddDataButton(buttonsComposite);
    updateDataButton = createEditDataButton(buttonsComposite);
    removeDataButton = createRemoveDataButton(buttonsComposite);
    promoteDataButton = createMoveDataButton(buttonsComposite);

    dataTableViewer = new TableViewer(
            getWidgetFactory().createTable(parent, GTKStyleHandler
                    .removeBorderFlag(SWT.BORDER | SWT.MULTI | SWT.NO_FOCUS | SWT.H_SCROLL | SWT.V_SCROLL)));
    dataTableViewer.getTable().setLayout(GridLayoutFactory.fillDefaults().create());
    dataTableViewer.getTable().setData(SWTBotConstants.SWTBOT_WIDGET_ID_KEY, SWTBotConstants.SWTBOT_ID_PROCESS_DATA_LIST);
    dataTableViewer.getTable().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, 100).create());
    dataTableViewer.setSorter(new ViewerSorter());
    dataTableViewer.addDoubleClickListener(this);
    dataTableViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL) {
                e.doit = false;
                removeData((IStructuredSelection) dataTableViewer.getSelection());
            }
        }
    });
    final ObservableListContentProvider contentProvider = new ObservableListContentProvider();
    dataTableViewer.setContentProvider(contentProvider);
    dataTableViewer.addFilter(hideBusinessObjectData());
    // create the label provider including monitoring
    // of the changes of the labels
    final IObservableSet knownElements = contentProvider.getKnownElements();
    final IObservableMap[] labelMaps = EMFObservables.observeMaps(knownElements, new EStructuralFeature[] { ProcessPackage.Literals.ELEMENT__NAME,
            ProcessPackage.Literals.DATA__DATA_TYPE });
    dataTableViewer.setLabelProvider(new DataStyledTreeLabelProvider(labelMaps));

}