Example usage for org.eclipse.jface.viewers ViewerComparator ViewerComparator

List of usage examples for org.eclipse.jface.viewers ViewerComparator ViewerComparator

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers ViewerComparator ViewerComparator.

Prototype

public ViewerComparator(Comparator<? super String> comparator) 

Source Link

Document

Creates a new ViewerComparator , which uses the given comparator to sort strings.

Usage

From source file:com.aptana.ide.core.ui.preferences.ProjectNaturesPage.java

License:Open Source License

private ViewerComparator getViewerComperator() {
    return new ViewerComparator(new Comparator() {
        public int compare(Object element1, Object element2) {
            // set the Aptana on top and the rest on the bottom
            String firstId = element1.toString();
            String secondId = element2.toString();
            if (firstId.startsWith(APTANA_NATURE_PREFIX)) {
                if (secondId.startsWith(APTANA_NATURE_PREFIX)) {
                    // Compare 2 aptana natures by name
                    return firstId.compareTo(secondId);
                } else {
                    // Put aptana as first
                    return -1;
                }//from   w  w  w . ja  v  a  2  s  .  co  m
            } else if (secondId.startsWith(APTANA_NATURE_PREFIX)) {
                // put aptana as first
                return 1;
            }
            // The natures does not belong to Aptana, so return a simple string comparison
            return firstId.compareTo(secondId);
        }
    });
}

From source file:com.aptana.ui.properties.ProjectNaturesPage.java

License:Open Source License

private ViewerComparator getViewerComperator() {
    return new ViewerComparator(new Comparator<String>() {

        public int compare(String o1, String o2) {
            // set Aptana natures ahead of others
            if (ResourceUtil.isAptanaNature(o1)) {
                return ResourceUtil.isAptanaNature(o2) ? o1.compareTo(o2) : -1;
            }//from  www  .  j a  v a  2s  .c  o m
            return ResourceUtil.isAptanaNature(o2) ? 1 : o1.compareTo(o2);
        }
    });
}

From source file:com.archimatetool.hammer.view.ValidatorViewer.java

License:Open Source License

private void sort(final int columnIndex) {
    setComparator(new ViewerComparator(Collator.getInstance()) {
        @Override//from w ww .j av  a2  s.  c  om
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof IIssueCategory && e2 instanceof IIssueCategory) {
                return 0;
            }

            ITableLabelProvider provider = (ITableLabelProvider) getLabelProvider();
            String s1 = provider.getColumnText(e1, columnIndex);
            String s2 = provider.getColumnText(e2, columnIndex);

            if (s1 == null) {
                s1 = ""; //$NON-NLS-1$
            }
            if (s2 == null) {
                s2 = ""; //$NON-NLS-1$
            }

            return columnSort[columnIndex] == ASCENDING ? getComparator().compare(s1, s2)
                    : getComparator().compare(s2, s1);
        }
    });
}

From source file:com.dubture.twig.ui.preferences.TwigSyntaxColoringPage.java

License:Open Source License

private StructuredViewer createStylesViewer(Composite parent) {
    StructuredViewer stylesViewer = new ListViewer(parent,
            SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    stylesViewer.setComparator(new ViewerComparator(Collator.getInstance()));
    stylesViewer.setLabelProvider(new LabelProvider() {
        @Override/*  w  ww .j a va 2s  .  c om*/
        public String getText(Object element) {
            Object description = fStyleToDescriptionMap.get(element);
            if (description != null)
                return description.toString();

            return super.getText(element);
        }
    });
    stylesViewer.setContentProvider(new ITreeContentProvider() {
        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return getStylePreferenceKeys().toArray();
        }

        public Object[] getElements(Object inputElement) {
            return getChildren(inputElement);
        }

        public Object getParent(Object element) {
            return getStylePreferenceKeys();
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    return stylesViewer;
}

From source file:com.github.sdbg.debug.ui.internal.dialogs.ManageLaunchesDialog.java

License:Open Source License

private void createDialogUI(Composite parent) {
    GridLayoutFactory.fillDefaults().margins(12, 6).applyTo(parent);

    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).hint(725, 370).applyTo(sashForm);

    Composite leftComposite = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(leftComposite);
    GridDataFactory.swtDefaults().grab(false, true).align(SWT.FILL, SWT.FILL).applyTo(leftComposite);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(leftComposite);
    toolBar.setBackground(parent.getBackground());
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.BEGINNING, SWT.FILL).applyTo(toolBar);

    launchesViewer = new TableViewer(leftComposite, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);
    launchesViewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new LaunchConfigLabelProvider()));
    launchesViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER));
    launchesViewer.setContentProvider(new LaunchConfigContentProvider());
    launchesViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    launchesViewer.getTable().setFocus();
    launchesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override/*  w w  w.  j  a va 2s. c  o m*/
        public void selectionChanged(SelectionChangedEvent event) {
            handleSelectedConfigChanged();
        }
    });

    GridDataFactory.swtDefaults().grab(false, true).align(SWT.FILL, SWT.FILL).hint(50, 50)
            .applyTo(launchesViewer.getControl());

    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

    for (final ILaunchConfigurationType configType : manager.getLaunchConfigurationTypes()) {
        // remove chrome app and pub serve launch icons from toolbar, unless user has opted in
        if (!configType.getIdentifier().contains("pubServe")
                && !configType.getIdentifier().contains("chromeApp")) {
            CreateLaunchAction action = new CreateLaunchAction(this, configType);
            toolBarManager.add(action);
        } else {
            if ((configType.getIdentifier().contains("pubServe") && DartCoreDebug.ENABLE_PUB_SERVE_LAUNCH)
                    || (configType.getIdentifier().contains("chromeApp")
                            && DartCoreDebug.ENABLE_CHROME_APP_LAUNCH_CONFIG)) {

                CreateLaunchAction action = new CreateLaunchAction(this, configType);
                toolBarManager.add(action);
            }
        }
    }

    //toolBarManager.add(new Separator());
    toolBarManager.add(getDeleteAction());

    toolBarManager.update(true);

    configUI = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(configUI);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(configUI);

    toolBar.pack();
    Label toolbarSpacer = new Label(configUI, SWT.NONE);
    GridDataFactory.swtDefaults().hint(SWT.NONE, toolBar.getSize().y).applyTo(toolbarSpacer);

    Composite nameComposite = new Composite(configUI, SWT.NONE);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(nameComposite);
    GridLayoutFactory.swtDefaults().margins(6, 0).applyTo(nameComposite);

    configNameText = new Text(nameComposite, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(configNameText);
    configNameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            if (workingCopy != null) {
                workingCopy.rename(configNameText.getText());
            }
        }
    });

    launchConfigArea = new ScrolledComposite(configUI, SWT.V_SCROLL);
    GridDataFactory.swtDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(launchConfigArea);
    launchConfigArea.setExpandVertical(false);
    launchConfigArea.setExpandHorizontal(true);

    configNameText.setVisible(false);

    sashForm.setWeights(new int[] { 33, 67 });

    selectLaunchConfigFromPage();
}

From source file:com.google.dart.tools.debug.ui.internal.dialogs.ManageLaunchesDialog.java

License:Open Source License

private void createDialogUI(Composite parent) {
    GridLayoutFactory.fillDefaults().margins(12, 6).applyTo(parent);

    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).hint(675, 350).applyTo(sashForm);

    Composite leftComposite = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(leftComposite);
    GridDataFactory.swtDefaults().grab(false, true).align(SWT.FILL, SWT.FILL).applyTo(leftComposite);

    ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
    ToolBar toolBar = toolBarManager.createControl(leftComposite);
    toolBar.setBackground(parent.getBackground());
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.BEGINNING, SWT.FILL).applyTo(toolBar);

    launchesViewer = new TableViewer(leftComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    launchesViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(),
            PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
    launchesViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER));
    launchesViewer.setContentProvider(new LaunchConfigContentProvider());
    launchesViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
    launchesViewer.getTable().setFocus();
    launchesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override/*from  www .  j  av a 2s . c o  m*/
        public void selectionChanged(SelectionChangedEvent event) {
            handleSelectedConfigChanged();
        }
    });

    GridDataFactory.swtDefaults().grab(false, true).align(SWT.FILL, SWT.FILL).hint(50, 50)
            .applyTo(launchesViewer.getControl());

    GridDataFactory.swtDefaults().grab(false, true).align(SWT.FILL, SWT.FILL).hint(50, 50)
            .applyTo(launchesViewer.getControl());

    toolBarManager.add(getCreateAction());
    toolBarManager.add(getDeleteAction());

    toolBarManager.update(true);

    configUI = new Composite(sashForm, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(configUI);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(configUI);

    toolBar.pack();
    Label toolbarSpacer = new Label(configUI, SWT.NONE);
    GridDataFactory.swtDefaults().hint(SWT.NONE, toolBar.getSize().y).applyTo(toolbarSpacer);

    Composite nameComposite = new Composite(configUI, SWT.NONE);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(nameComposite);
    GridLayoutFactory.swtDefaults().margins(6, 0).applyTo(nameComposite);

    configNameText = new Text(nameComposite, SWT.SINGLE | SWT.BORDER);
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(configNameText);
    configNameText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            if (workingCopy != null) {
                workingCopy.rename(configNameText.getText());
            }
        }
    });

    configNameText.setVisible(false);

    sashForm.setWeights(new int[] { 30, 70 });

    selectLaunchConfigFromPage();
}

From source file:com.google.dart.tools.ui.internal.testing.DartUnitViewPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    treeViewer.setAutoExpandLevel(2);/*from w  ww . j a v a  2s . co  m*/

    if (project != null) {
        treeViewer.setLabelProvider(new WorkbenchLabelProvider());
        treeViewer.setContentProvider(new TestsContentProvider(project));
        treeViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER));
        treeViewer.setInput(project);
    }
}

From source file:com.xse.optstack.persconftool.ui.resources.ResourcesTable.java

License:Open Source License

public ResourcesTable(final Composite parent) {
    super(parent, SWT.BORDER | SWT.FULL_SELECTION);

    this.getViewer().setComparator(new ViewerComparator(new Comparator<String>() {
        @Override/*  w w w . j  a v  a  2 s . c  om*/
        public int compare(final String o1, final String o2) {
            return o1.compareTo(o2);
        }
    }));
}

From source file:ext.org.eclipse.jdt.internal.ui.workingsets.WorkingSetConfigurationDialog.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww w.  java  2s. c  o  m*/
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);

    createMessageArea(composite);
    Composite inner = new Composite(composite, SWT.NONE);
    inner.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    inner.setLayout(layout);
    createTableViewer(inner);
    createOrderButtons(inner);
    createModifyButtons(composite);
    if (fIsSortingEnabled) {
        fTableViewer.setComparator(new ViewerComparator(getComparator()) {
            /*
             * @see ViewerComparator#compare(Viewer, Object, Object)
             * @since 3.5
             */
            @Override
            public int compare(Viewer viewer, Object e1, Object e2) {
                return getComparator().compare(e1, e2);
            }
        });
    }
    fTableViewer.setInput(fAllWorkingSets);
    applyDialogFont(composite);

    return composite;
}

From source file:ext.org.eclipse.jdt.internal.ui.workingsets.WorkingSetConfigurationDialog.java

License:Open Source License

private void createOrderButtons(Composite parent) {
    Composite buttons = new Composite(parent, SWT.NONE);
    buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;/*from w  w  w.  ja  v  a2s . c o m*/
    layout.marginWidth = 0;
    buttons.setLayout(layout);

    fUpButton = new Button(buttons, SWT.PUSH);
    fUpButton.setText(WorkingSetMessages.WorkingSetConfigurationDialog_up_label);
    setButtonLayoutData(fUpButton);
    fUpButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp(((IStructuredSelection) fTableViewer.getSelection()).toList());
        }
    });

    fDownButton = new Button(buttons, SWT.PUSH);
    fDownButton.setText(WorkingSetMessages.WorkingSetConfigurationDialog_down_label);
    setButtonLayoutData(fDownButton);
    fDownButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown(((IStructuredSelection) fTableViewer.getSelection()).toList());
        }
    });

    fSelectAll = new Button(buttons, SWT.PUSH);
    fSelectAll.setText(WorkingSetMessages.WorkingSetConfigurationDialog_selectAll_label);
    setButtonLayoutData(fSelectAll);
    fSelectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectAll();
        }
    });

    fDeselectAll = new Button(buttons, SWT.PUSH);
    fDeselectAll.setText(WorkingSetMessages.WorkingSetConfigurationDialog_deselectAll_label);
    setButtonLayoutData(fDeselectAll);
    fDeselectAll.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            deselectAll();
        }
    });
    /**
     * A check box that has persistence to sort the working sets alphabetically in the
     * WorkingSetConfigurationDialog. It restores the unsorted order of the working sets when
     * unchecked.
     * 
     * @since 3.5
     */
    fSortWorkingSet = new Button(parent, SWT.CHECK);
    fSortWorkingSet.setText(WorkingSetMessages.WorkingSetConfigurationDialog_sort_working_sets);
    fSortWorkingSet.setLayoutData(new GridData(SWT.LEAD, SWT.CENTER, true, false));
    fSortWorkingSet.setSelection(fIsSortingEnabled);
    fSortWorkingSet.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            fIsSortingEnabled = fSortWorkingSet.getSelection();
            updateButtonAvailability();
            if (fIsSortingEnabled) {
                fTableViewer.setComparator(new ViewerComparator(getComparator()) {
                    /*
                     * @see ViewerComparator#compare(Viewer, Object, Object)
                     * @since 3.5
                     */
                    @Override
                    public int compare(Viewer viewer, Object e1, Object e2) {
                        return getComparator().compare(e1, e2);
                    }
                });
            } else {
                fTableViewer.setComparator(null);
            }
        }
    });
}