org.eclipse.jface.viewers.ViewerSorter Java Examples

The following examples show how to use org.eclipse.jface.viewers.ViewerSorter. 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: ReadOnceTreeLoader.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init(){
	if (slp == null) {
		slp = (SelectorPanelProvider) cv.getConfigurer().getControlFieldProvider();
	}
	if (filter == null) {
		filter = new TreeFilter(slp.getPanel());
	}
	tv = (TreeViewer) cv.getViewerWidget();
	if (orderBy != null) {
		tv.setSorter(new ViewerSorter() {
			
			@Override
			public int compare(Viewer viewer, Object e1, Object e2){
				String c1 = ((PersistentObject) e1).get(orderBy);
				String c2 = ((PersistentObject) e2).get(orderBy);
				return c1.compareTo(c2);
			}
			
		});
	}
	tv.setFilters(new ViewerFilter[] {
		filter
	});
	
}
 
Example #2
Source File: ElementNamesConfigurationBlock.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void sortTable(final TableColumn column, final boolean asc)
{
	Table table = tableViewer.getTable();
	table.setSortColumn(column);
	table.setSortDirection(asc? SWT.UP : SWT.DOWN);
	tableViewer.setSorter(new ViewerSorter() {
		public int compare(Viewer viewer, Object o1, Object o2)
		{
			int result;
			switch(tableViewer.getTable().indexOf(column))
			{
				case 0: default:
					result = ( (ItemContent) o1 ).getDisplayName().compareTo(( (ItemContent) o2 ).getDisplayName());
					break;
				case 1:
					result = ( (ItemContent) o1 ).getCustomName().compareTo(( (ItemContent) o2 ).getCustomName());
					break;
				case 2:
					result = ( (ItemContent) o1 ).getDescription().compareTo(( (ItemContent) o2 ).getDescription());
					break;
			}
			return asc? result : result * -1;
		}
	});
	
}
 
Example #3
Source File: UnansweredDocumentsView.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
public UnansweredDocumentsView(Composite parent, IWorkbenchPartSite site,
        Supplier<Questionnaire> questionnaireSupplier, Supplier<IProject> projectSupplier) {
    this.questionnaireSupplier = questionnaireSupplier;
    this.projectSupplier = projectSupplier;

    incompleteDocumentsLabel = new Label(parent, 0);
    incompleteDocumentsLabel.setText(TEMPLATE_ANSWERS_COMPLETE);
    incompleteDocumentsLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1));

    incompleteDocumentsList = new ListViewer(parent, SWT.V_SCROLL);
    GridData gd = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 2, 1);
    gd.heightHint = (int) (((org.eclipse.swt.widgets.List) incompleteDocumentsList.getControl()).getItemHeight()
            * 4);
    gd.widthHint = 300;
    incompleteDocumentsList.getControl().setLayoutData(gd);
    incompleteDocumentsList.getControl().setVisible(false);
    incompleteDocumentsList.setSorter(new ViewerSorter());
    incompleteDocumentsList.setContentProvider(ArrayContentProvider.getInstance());
    incompleteDocumentsList.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((Document) element).getKey();
        }
    });
    site.setSelectionProvider(incompleteDocumentsList);
}
 
Example #4
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 #5
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 #6
Source File: SourceView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
private void createColumns() {
	        TableLayout layout = new TableLayout();
	        getTable().setLayout(layout);
	        getTable().setHeaderVisible(true);
	        for (int i = 0; i < columnHeaders.length; i++) {
	            layout.addColumnData(columnLayouts[i]);
	            TableColumn tc = new TableColumn(getTable(), SWT.NONE,i);
	            tc.setResizable(columnLayouts[i].resizable);
	            tc.setText(columnHeaders[i]);
	            final int j = i;
	            tc.addSelectionListener(new SelectionAdapter() {           	
                	public void widgetSelected(SelectionEvent e) {
                		ViewerSorter oldSorter = viewer.getSorter();
                		if(oldSorter instanceof ColumnBasedSorter) {
                			ColumnBasedSorter sorter = (ColumnBasedSorter) oldSorter;	                			 
                			if(sorter.getColumn() == j) {
                				sorter.toggle();
                				viewer.refresh();
//                				System.err.println("Resorting column " + j + " in order " + sorter.getOrientation());
                				return;
                			}
                		}
                		
                		viewer.setSorter(new ColumnBasedSorter(j));
//                		System.err.println("Sorting column " + j + " in order " + 1);	                		
                		viewer.refresh();
                    }	                
                });
	        }
	    }
 
Example #7
Source File: RnContentProvider.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public void reorder(final String field){
	cv.getViewerWidget().setSorter(new ViewerSorter() {
		
		@Override
		public int compare(final Viewer viewer, final Object e1, final Object e2){
			TimeTool t1 = getLatest((Tree) e1);
			TimeTool t2 = getLatest((Tree) e2);
			return t1.compareTo(t2);
		}
		
	});
}
 
Example #8
Source File: DataWizardPage.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createTypeChooser(final Composite parent) {
    final Label typeLabel = new Label(parent, SWT.NONE);
    typeLabel.setText(Messages.datatypeLabel);
    typeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());

    typeCombo = new ComboViewer(parent, SWT.BORDER | SWT.READ_ONLY);
    typeCombo.setContentProvider(new ArrayContentProvider());
    typeCombo.setLabelProvider(new DataTypeLabelProvider());
    typeCombo.addFilter(typeViewerFilter);
    typeCombo.setSorter(new ViewerSorter());
    typeCombo.getCombo().setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(10, 0).create());

    typeDescriptionDecorator = new ControlDecoration(typeCombo.getCombo(), SWT.LEFT);
    typeDescriptionDecorator.setImage(Pics.getImage(PicsConstants.hint));

    if (allowEnum) {
        final Button createOptionButton = new Button(parent, SWT.PUSH);
        createOptionButton.setText(Messages.listOfOptions);
        createOptionButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                final EnumDataTypeDialog dialog = new EnumDataTypeDialog(Display.getDefault().getActiveShell(),
                        ModelHelper.getMainProcess(container));
                if (dialog.open() == Window.OK) {
                    final EnumType type = dialog.getSelectedEnum();
                    updateDatabinding();
                    typeCombo.setSelection(new StructuredSelection(type));
                }
            }
        });
    } else {
        typeCombo.getCombo()
                .setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).indent(10, 0).create());
    }
}
 
Example #9
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 #10
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 #11
Source File: ScriptExpressionEditor.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
protected void createReturnTypeComposite(final Composite parent) {
    final Composite typeComposite = new Composite(parent, SWT.NONE);
    typeComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    final GridLayout gl = new GridLayout(3, false);
    gl.marginWidth = 0;
    gl.marginHeight = 0;
    typeComposite.setLayout(gl);

    final Label typeLabel = new Label(typeComposite, SWT.NONE);
    typeLabel.setText(Messages.returnType);
    typeLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).create());

    typeCombo = new ComboViewer(typeComposite, SWT.BORDER);
    typeCombo.getCombo().setLayoutData(
            GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).indent(10, 0).create());
    typeCombo.setContentProvider(new ExpressionReturnTypeContentProvider());
    typeCombo.setLabelProvider(new LabelProvider());
    typeCombo.setSorter(new ViewerSorter() {

        @Override
        public int compare(final Viewer viewer, final Object e1, final Object e2) {
            final String t1 = (String) e1;
            final String t2 = (String) e2;
            return t1.compareTo(t2);
        }
    });
    typeCombo.getCombo().addModifyListener(e -> fireSelectionChanged());

    browseClassesButton = new Button(typeComposite, SWT.PUSH);
    browseClassesButton.setText(Messages.browse);
    browseClassesButton.setLayoutData(GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).create());
    browseClassesButton.addListener(SWT.Selection, event -> openClassSelectionDialog());
}
 
Example #12
Source File: NodesSearcher.java    From jbt with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the Composite that contains the result of the search. The
 * Composite contains the {@link #resultsTable} element.
 * 
 * @param parent
 *            the Composite where the created Composite will be placed.
 */
private void createBottomComposite(Composite parent) {
	this.resultsTable = new TableViewer(parent, SWT.SINGLE | SWT.BORDER);
	this.resultsTable.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	this.resultsTable.setLabelProvider(new ResultsTableLabelProvider());
	this.resultsTable.setContentProvider(new ResultsTableContentProvider());
	this.resultsTable.setInput(this.searchResult);

	/* Sort elements by its String representation. */
	this.resultsTable.setSorter(new ViewerSorter());

	/*
	 * Listener that will select the node in the target BTEditor and which
	 * also activates the target BTEditor.
	 */
	this.resultsTable.addSelectionChangedListener(new ISelectionChangedListener() {
		public void selectionChanged(SelectionChangedEvent event) {
			ISelection selection = event.getSelection();

			if (!selection.isEmpty()) {
				Identifier selectedNode = (Identifier) ((IStructuredSelection) selection)
						.getFirstElement();
				targetEditor.selectNode(selectedNode);
				Utilities.activateEditor(targetEditor);
			}
		}
	});

	this.targetEditorName = new Label(parent, SWT.NONE);
	this.targetEditorName.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
}
 
Example #13
Source File: ResultSetPreviewPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Carry out sort operation against certain column
 * 
 * @param columnIndex
 *            the column based on which the sort operation would be carried
 *            out
 * @param asc
 *            the sort direction
 */
private void sort( final int columnIndex, final boolean asc )
{
	resultSetTable.setSortColumn( resultSetTable.getColumn( columnIndex ) );
	resultSetTable.setSortDirection( asc == true ? SWT.DOWN : SWT.UP );
	this.resultSetTableViewer.setSorter( new ViewerSorter( ) {

		// @Override
		public int compare( Viewer viewer, Object e1, Object e2 )
		{
			CellValue cv1 = ( (CellValue[]) e1 )[columnIndex];
			CellValue cv2 = ( (CellValue[]) e2 )[columnIndex];
			int result = 0;
			if ( cv1 == null && cv2 != null )
				result = -1;
			else if( cv2 == null && cv1 != null )
				result = 1;
			else if ( cv1 != null )
				result = cv1.compareTo( cv2 );
			if ( !asc )
				return result;
			else
				return result * -1;
		}

	} );
}
 
Example #14
Source File: ConfigurationFormToolkit.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public void createListSection ( final ScrolledForm form, final ConfigurationEditorInput input, final String attribute, final String label, final String delimiter, final String pattern )
{
    final IObservableList list = StringSplitListObservable.observeString ( Observables.observeMapEntry ( input.getDataMap (), attribute, String.class ), delimiter, pattern );

    // section

    final Section section = this.toolkit.createSection ( form.getBody (), ExpandableComposite.TITLE_BAR );
    section.setText ( label );

    final Composite client = this.toolkit.createComposite ( section, SWT.NONE );
    section.setClient ( client );
    this.toolkit.paintBordersFor ( client );

    client.setLayout ( new GridLayout ( 1, true ) );
    final GridData gd = new GridData ( GridData.FILL_BOTH );
    gd.horizontalSpan = 2;
    section.setLayoutData ( gd );

    // fields
    final ListViewer viewer = new ListViewer ( client );

    viewer.setContentProvider ( new ObservableListContentProvider () );
    viewer.setInput ( list );

    viewer.getControl ().setLayoutData ( new GridData ( GridData.FILL_BOTH ) );

    viewer.setSorter ( new ViewerSorter () );
}
 
Example #15
Source File: CContainerViewer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected int indexForElement(Object element) {
	ViewerSorter sorter = getSorter();
	if (sorter == null)
		return container.getItemCount();
	int count = container.getItemCount();
	int min = 0, max = count - 1;
	while(min <= max) {
		int mid = (min + max) / 2;
		Object data = container.getItem(mid).getData();
		int compare = sorter.compare(this, data, element);
		if(compare == 0) {
			// find first item > element
			while(compare == 0) {
				++mid;
				if(mid >= count) break;
				data = container.getItem(mid).getData();
				compare = sorter.compare(this, data, element);
			}
			return mid;
		}
		if(compare < 0) {
			min = mid + 1;
		} else {
			max = mid - 1;
		}
	}
	return min;
}
 
Example #16
Source File: ListDialogSortableFiltered.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public ListDialogSortableFiltered(String dialogTitle, String dialogMessage, PatternFilter patternFilter, IContentProvider contentProvider, IBaseLabelProvider labelProvider, ViewerSorter viewerSorter) {
   super(Display.getCurrent().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.NONE,
      new String[] {XViewerText.get("button.ok"), XViewerText.get("button.cancel")}, 0); //$NON-NLS-1$ //$NON-NLS-2$
   this.contentProvider = contentProvider;
   this.labelProvider = labelProvider;
   this.patternFilter = patternFilter;
   this.viewerSorter = viewerSorter;
   setShellStyle(getShellStyle() | SWT.RESIZE);
}
 
Example #17
Source File: XCheckFilteredTreeDialog.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public XCheckFilteredTreeDialog(String dialogTitle, String dialogMessage, PatternFilter patternFilter, IContentProvider contentProvider, IBaseLabelProvider labelProvider, ViewerSorter viewerSorter) {
   super(Display.getCurrent().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.NONE, new String[] {
 	  XViewerText.get("button.ok"), XViewerText.get("button.cancel")}, 0); //$NON-NLS-1$ //$NON-NLS-2$
   this.contentProvider = contentProvider;
   this.labelProvider = labelProvider;
   this.patternFilter = patternFilter;
   this.viewerSorter = viewerSorter;
   setShellStyle(getShellStyle() | SWT.RESIZE);
}
 
Example #18
Source File: SinkView.java    From lapse-plus with GNU General Public License v3.0 5 votes vote down vote up
private void createColumns() {
    TableLayout layout = new TableLayout();
    getTable().setLayout(layout);
    getTable().setHeaderVisible(true);
    for (int i = 0; i < columnHeaders.length; i++) {
        layout.addColumnData(columnLayouts[i]);
        TableColumn tc = new TableColumn(getTable(), SWT.BORDER, i);
        tc.setResizable(columnLayouts[i].resizable);
        tc.setText(columnHeaders[i]);
        tc.pack();
        final int j = i;
        tc.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                ViewerSorter oldSorter = viewer.getSorter();
                if (oldSorter instanceof ColumnBasedSorter) {
                    ColumnBasedSorter sorter = (ColumnBasedSorter) oldSorter;
                    if (sorter.getColumn() == j) {
                        sorter.toggle();
                        viewer.refresh();
                        // System.err.println("Resorting column " + j +
                        // " in order "
                        // + sorter.getOrientation());
                        return;
                    }
                }
                viewer.setSorter(new ColumnBasedSorter(j));
                logError("Sorting column " + j + " in order " + 1);
                viewer.refresh();
            }
        });
    }
}
 
Example #19
Source File: ListDialogField.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @deprecated Use {@link #setViewerComparator(ViewerComparator)} instead}
 */
@Deprecated
public void setViewerSorter(ViewerSorter sorter) {
	setViewerComparator(sorter);
}
 
Example #20
Source File: ListDialogField.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @deprecated Use {@link #setViewerComparator(ViewerComparator)} instead}
 */
public void setViewerSorter(ViewerSorter sorter) {
	setViewerComparator(sorter);
}
 
Example #21
Source File: PackageViewerWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setSorter(ViewerSorter sorter) {
	fViewer.setSorter(sorter);
}
 
Example #22
Source File: PackageViewerWrapper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ViewerSorter getSorter() {
	return fViewer.getSorter();
}
 
Example #23
Source File: ListDialogSortable.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void setSorter(ViewerSorter viewerSorter) {
   this.viewerSorter = viewerSorter;
}
 
Example #24
Source File: ListDialogSortable.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public ListDialogSortable(ViewerSorter viewerSorter, Shell parent) {
   super(parent);
   this.viewerSorter = viewerSorter;
}
 
Example #25
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));

}
 
Example #26
Source File: XViewerCustomizeDialog.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void createSelectCustomizationSection(Composite comp) {
    // Customization Table and Buttons
    final Composite custComp = new Composite(comp, SWT.NONE);
    final GridData gd_composite_6 = new GridData(SWT.FILL, SWT.FILL, true, true);
    custComp.setLayoutData(gd_composite_6);
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.marginWidth = 0;
    gridLayout_1.marginHeight = 0;
    custComp.setLayout(gridLayout_1);

    Label selectCustomizationLabel = new Label(custComp, SWT.NONE);
    selectCustomizationLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectCustomizationLabel.setText(XViewerText.get("XViewerCustomizeDialog.prompt")); //$NON-NLS-1$

    // Customization Table
    custTable = new XViewerFilteredTree(custComp, SWT.BORDER);
    final Tree table_2 = custTable.getViewer().getTree();
    final GridData gd_table_2 = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_table_2.heightHint = 270;
    gd_table_2.widthHint = 200;
    table_2.setLayoutData(gd_table_2);
    custTable.getViewer().setLabelProvider(new CustomizeDataLabelProvider(xViewerToCustomize));
    custTable.getViewer().setContentProvider(new ArrayTreeContentProvider());
    custTable.getViewer().setSorter(new ViewerSorter() {
       @SuppressWarnings("unchecked")
       @Override
       public int compare(Viewer viewer, Object e1, Object e2) {
          if (((CustomizeData) e1).getName().startsWith("-")) { //$NON-NLS-1$
             return -1;
          } else if (((CustomizeData) e2).getName().startsWith("-")) { //$NON-NLS-1$
             return 1;
          } else {
             return getComparator().compare(((CustomizeData) e1).getName(), ((CustomizeData) e2).getName());
          }
       }
    });
custTable.getViewer().addSelectionChangedListener(event -> {
	handleCustTableSelectionChanged();
	updateButtonEnablements();
	storeCustTableSelection();
});

    // Customization Table Buttons
    final Composite composite = new Composite(custComp, SWT.NONE);
    composite.setLayoutData(new GridData());
    final GridLayout gridLayout_7 = new GridLayout();
    gridLayout_7.numColumns = 4;
    composite.setLayout(gridLayout_7);

    setDefaultButton = new Button(composite, SWT.NONE);
    setDefaultButton.setLayoutData(new GridData());
    setDefaultButton.setText(SET_AS_DEFAULT);
setDefaultButton.addListener(SWT.Selection, e -> {
	handleSetDefaultButton();
	updateButtonEnablements();
});

    deleteButton = new Button(composite, SWT.NONE);
    deleteButton.setLayoutData(new GridData());
    deleteButton.setText(XViewerText.get("button.delete")); //$NON-NLS-1$
    deleteButton.addListener(SWT.Selection, e -> {
          handleDeleteButton();
          updateButtonEnablements();
    });
 }
 
Example #27
Source File: XViewer.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void setSorter(ViewerSorter sorter) {
   super.setSorter(sorter);
   updateStatusLabel();
}
 
Example #28
Source File: ElementTreeSelectionDialog.java    From translationstudio8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the sorter used by the tree viewer.
 * @param sorter
 * @deprecated as of 3.3, use {@link ElementTreeSelectionDialog#setComparator(ViewerComparator)} instead
 */
public void setSorter(ViewerSorter sorter) {
    fComparator = sorter;
}
 
Example #29
Source File: ElementTreeSelectionDialog.java    From tmxeditor8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the sorter used by the tree viewer.
 * @param sorter
 * @deprecated as of 3.3, use {@link ElementTreeSelectionDialog#setComparator(ViewerComparator)} instead
 */
public void setSorter(ViewerSorter sorter) {
    fComparator = sorter;
}