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() 

Source Link

Document

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

Usage

From source file:org.eclipse.jdt.internal.debug.ui.jres.VMTypePage.java

License:Open Source License

public void createControl(Composite parent) {
    Composite composite = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH);

    SWTFactory.createLabel(composite, JREMessages.VMTypePage_3, 1);

    fTypesViewer = new ListViewer(composite, SWT.SINGLE | SWT.BORDER);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.heightHint = 250;// ww w  .j a  v a2 s  . c  om
    data.widthHint = 300;
    fTypesViewer.getControl().setFont(composite.getFont());
    fTypesViewer.getControl().setLayoutData(data);
    fTypesViewer.setContentProvider(new ArrayContentProvider());
    fTypesViewer.setLabelProvider(new TypeLabelProvider());
    fTypesViewer.setComparator(new ViewerComparator());
    fTypesViewer.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            setPageComplete(true);
            updateNextPage();
            getWizard().getContainer().showPage(getNextPage());
        }
    });
    fTypesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                setPageComplete(false);
            } else {
                setPageComplete(true);
                updateNextPage();
            }
        }
    });
    fTypesViewer.setInput(JavaRuntime.getVMInstallTypes());
    setControl(composite);
    fTypesViewer.setSelection(
            new StructuredSelection(JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE)));
    updateNextPage();
    PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
            IJavaDebugHelpContextIds.ADD_NEW_JRE_WIZARD_PAGE);
}

From source file:org.eclipse.jface.examples.databinding.snippets.Snippet020TreeViewerWithSetFactory.java

License:Open Source License

/**
 * Create contents of the window/*from  ww w . ja va  2s  . c  o m*/
 */
protected void createContents() {
    shell = new Shell();
    final GridLayout gridLayout_1 = new GridLayout();
    gridLayout_1.numColumns = 2;
    shell.setLayout(gridLayout_1);
    shell.setSize(535, 397);
    shell.setText("SWT Application");

    final Composite group = new Composite(shell, SWT.NONE);
    final RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 0;
    rowLayout.marginRight = 0;
    rowLayout.marginLeft = 0;
    rowLayout.marginBottom = 0;
    rowLayout.pack = false;
    group.setLayout(rowLayout);
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));

    final Button addRootButton = new Button(group, SWT.NONE);
    addRootButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            Set<Bean> set = input.getSet();
            Bean root = createBean("root");
            set.add(root);
            input.setSet(set);

            beanViewer.setSelection(new StructuredSelection(root));
            beanText.selectAll();
            beanText.setFocus();
        }
    });
    addRootButton.setText("Add Root");

    addChildBeanButton = new Button(group, SWT.NONE);
    addChildBeanButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            Bean parent = getSelectedBean();
            Set<Bean> set = new HashSet<>(parent.getSet());
            Bean child = createBean("child" + (counter++));
            set.add(child);
            parent.setSet(set);

            // beanViewer.setSelection(new StructuredSelection(parent));
            // beanText.selectAll();
            // beanText.setFocus();
        }
    });
    addChildBeanButton.setText("Add Child");

    removeBeanButton = new Button(group, SWT.NONE);
    removeBeanButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            TreeItem selectedItem = beanViewer.getTree().getSelection()[0];
            Bean bean = (Bean) selectedItem.getData();
            TreeItem parentItem = selectedItem.getParentItem();
            Bean parent;
            if (parentItem == null)
                parent = input;
            else
                parent = (Bean) parentItem.getData();

            Set<Bean> set = new HashSet<>(parent.getSet());
            set.remove(bean);
            parent.setSet(set);
        }
    });
    removeBeanButton.setText("Remove");

    copyButton = new Button(group, SWT.NONE);
    copyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            clipboard.setValue(getSelectedBean());
        }
    });
    copyButton.setText("Copy");

    pasteButton = new Button(group, SWT.NONE);
    pasteButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            Bean copy = clipboard.getValue();
            if (copy == null)
                return;
            Bean parent = getSelectedBean();
            if (parent == null)
                parent = input;

            Set<Bean> set = new HashSet<>(parent.getSet());
            set.add(copy);
            parent.setSet(set);

            beanViewer.setSelection(new StructuredSelection(copy));
            beanText.selectAll();
            beanText.setFocus();
        }
    });
    pasteButton.setText("Paste");

    final Button refreshButton = new Button(group, SWT.NONE);
    refreshButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            beanViewer.refresh();
        }
    });
    refreshButton.setText("Refresh");

    beanViewer = new TreeViewer(shell, SWT.FULL_SELECTION | SWT.BORDER);
    beanViewer.setUseHashlookup(true);
    beanViewer.setComparator(new ViewerComparator());
    tree = beanViewer.getTree();
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    final Label itemNameLabel = new Label(shell, SWT.NONE);
    itemNameLabel.setText("Item Name");

    beanText = new Text(shell, SWT.BORDER);
    final GridData gd_beanValue = new GridData(SWT.FILL, SWT.CENTER, true, false);
    beanText.setLayoutData(gd_beanValue);
    m_bindingContext = initDataBindings();
    //
    initExtraBindings(m_bindingContext);
}

From source file:org.eclipse.jface.snippets.viewers.Snippet045TableViewerFillFromBackgroundThread.java

License:Open Source License

public Snippet045TableViewerFillFromBackgroundThread(final Shell shell) {
    final TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
    v.setLabelProvider(new MyLabelProvider());
    v.setContentProvider(ArrayContentProvider.getInstance());

    TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
    column.setWidth(200);/*from  w  ww  . j  av a2 s . com*/
    column.setText("Column 1");

    column = new TableColumn(v.getTable(), SWT.NONE);
    column.setWidth(200);
    column.setText("Column 2");

    final List<MyModel> model = new ArrayList<>();
    model.add(new MyModel(0));
    model.add(new MyModel(0));
    model.add(new MyModel(0));
    v.setInput(model);
    v.setComparator(new ViewerComparator() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            MyModel m1 = (MyModel) e1;
            MyModel m2 = (MyModel) e2;
            return m2.counter - m1.counter;
        }

    });
    v.getTable().setLinesVisible(true);
    v.getTable().setHeaderVisible(true);

    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            shell.getDisplay().syncExec(() -> {
                MyModel el = new MyModel(++COUNTER);
                v.add(el);
                model.add(el);
            });
        }
    };

    Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(task, 3000, 1000);
}

From source file:org.eclipse.jface.snippets.viewers.Snippet064TreeViewerReplacingElements.java

License:Open Source License

public Snippet064TreeViewerReplacingElements(Shell shell) {
    Random random = new Random();
    final Composite c = new Composite(shell, SWT.NONE);
    c.setLayout(new FillLayout(SWT.VERTICAL));
    Label l = new Label(c, SWT.NONE);
    l.setText(//from  w w w  .  ja v  a  2 s .  c om
            "The elements are ordered lexicografically, i.e. 11 comes before 2,\nPress q, to rename one root element.\nPress w, to rename one child element.");
    final TreeViewer v = new TreeViewer(c);

    // Every observable in this example gets typed as Object, since the
    // input element is an Object
    List<Object> rootElements = Arrays.asList("root 1", "root 2", "root 3");
    Object input = new Object();
    AtomicReference<IObservableList<Object>> recentlyCreatedChildList = new AtomicReference<>();
    final IObservableList<Object> rootElementList = new WritableList<>(
            DisplayRealm.getRealm(shell.getDisplay()), Arrays.asList(rootElements), String.class);
    ITreeContentProvider contentProvider = new ObservableListTreeContentProvider<>(target -> {
        if (target == input)
            return rootElementList;
        if (target.toString().startsWith("root")) {
            recentlyCreatedChildList.set(new WritableList<>(DisplayRealm.getRealm(shell.getDisplay()),
                    Arrays.asList("child 1", "child 2"), String.class));
            return recentlyCreatedChildList.get();
        }
        return null;
    }, null);
    v.setContentProvider(contentProvider);
    v.setComparator(new ViewerComparator());
    v.setInput(input);
    v.getTree().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            // don't use 'r' and 'c', because they would iterate through the
            // root... / child... elements
            if (e.character == 'q') {
                rootElementList.set(0, "root " + random.nextInt());
            }
            if (e.character == 'w') {
                IObservableList<Object> childElementsList = recentlyCreatedChildList.get();
                if (childElementsList != null) {
                    childElementsList.set(0, "child " + random.nextInt());
                } else {
                    System.out.println("no children list present");
                }
            }
        }
    });
}

From source file:org.eclipse.jface.snippets.viewers.Snippet065TableViewerReplacingElements.java

License:Open Source License

public Snippet065TableViewerReplacingElements(Shell shell) {
    Random random = new Random();
    final Composite c = new Composite(shell, SWT.NONE);
    c.setLayout(new FillLayout(SWT.VERTICAL));
    Label l = new Label(c, SWT.NONE);
    l.setText(/*w w  w . j a v  a2s.c o m*/
            "The elements are ordered lexicografically, i.e. 11 comes before 2,\nPress q, to rename one element.");
    final TableViewer v = new TableViewer(c);
    String[] rootElements = new String[] { "root 1", "root 2", "root 3" };
    final IObservableList<String> input = new WritableList<>(DisplayRealm.getRealm(shell.getDisplay()));
    input.addAll(Arrays.asList(rootElements));
    IContentProvider contentProvider = new ObservableListContentProvider();
    v.setContentProvider(contentProvider);
    v.setComparator(new ViewerComparator());
    v.setInput(input);
    v.getControl().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            // don't use 'r' and 'c', because they would iterate through the
            // root... / child... elements
            if (e.character == 'q') {
                input.set(0, "root " + random.nextInt());
            }
        }
    });
}

From source file:org.eclipse.jst.common.project.facet.ui.libprov.user.UserLibraryProviderInstallPanel.java

License:Open Source License

/**
 * Creates the panel control.//from w w  w . j a  v a 2  s .  c  o  m
 * 
 * @param parent the parent composite
 * @return the created control
 */

@Override
public Control createControl(final Composite parent) {
    this.rootComposite = new Composite(parent, SWT.NONE);
    this.rootComposite.setLayout(gl(1, 0, 0));

    final Composite tableComposite = new Composite(this.rootComposite, SWT.NONE);
    tableComposite.setLayoutData(gdhfill());
    tableComposite.setLayout(gl(2, 0, 0));

    final Table libsTable = new Table(tableComposite, SWT.CHECK | SWT.BORDER);
    libsTable.setLayoutData(gdhhint(gdhfill(), 60));

    this.libsTableViewer = new CheckboxTableViewer(libsTable);
    this.libsTableViewer.setContentProvider(new LibrariesContentProvider());
    this.libsTableViewer.setLabelProvider(new LibrariesLabelProvider());
    this.libsTableViewer.setComparator(new ViewerComparator());
    this.libsTableViewer.setInput(new Object());

    final UserLibraryProviderInstallOperationConfig cfg = (UserLibraryProviderInstallOperationConfig) getOperationConfig();

    this.libsTableViewer.setCheckedElements(cfg.getLibraryNames().toArray());

    this.libsTableViewer.addCheckStateListener(new ICheckStateListener() {
        public void checkStateChanged(final CheckStateChangedEvent event) {
            final List<String> libs = new ArrayList<String>();

            for (Object element : UserLibraryProviderInstallPanel.this.libsTableViewer.getCheckedElements()) {
                libs.add((String) element);
            }

            cfg.setLibraryNames(libs);
        }
    });

    final IPropertyChangeListener listener = new IPropertyChangeListener() {
        public void propertyChanged(final String property, final Object oldValue, final Object newValue) {
            handleLibraryNamesChanged();
        }
    };

    cfg.addListener(listener, UserLibraryProviderInstallOperationConfig.PROP_LIBRARY_NAMES);

    final Image manageLibrariesImage = getImageDescriptor(IMG_PATH_BUTTON_MANAGE_LIBRARIES).createImage();
    final Image downloadLibraryImage = getImageDescriptor(IMG_PATH_BUTTON_DOWNLOAD).createImage();

    final Menu menu = new Menu(libsTable);
    libsTable.setMenu(menu);

    final ToolBar toolBar = new ToolBar(tableComposite, SWT.FLAT | SWT.VERTICAL);
    toolBar.setLayoutData(gdvfill());

    final SelectionAdapter manageLibrariesListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            final String id = UserLibraryPreferencePage.ID;
            final Shell shell = libsTable.getShell();

            final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, id,
                    new String[] { id }, null);

            if (dialog.open() == Window.OK) {
                UserLibraryProviderInstallPanel.this.libsTableViewer.refresh();

                // We need to send an event up the listener chain since validation needs to be
                // refreshed. This not an ideal solution, but it does work. The name of the 
                // property is not important since the listener that does validation is global.

                final List<String> libNames = cfg.getLibraryNames();
                cfg.notifyListeners("validation", libNames, libNames); //$NON-NLS-1$
            }
        }
    };

    final MenuItem manageLibrariesMenuItem = new MenuItem(menu, SWT.PUSH);
    manageLibrariesMenuItem.setText(Resources.manageLibrariesMenuItem);
    manageLibrariesMenuItem.setImage(manageLibrariesImage);
    manageLibrariesMenuItem.addSelectionListener(manageLibrariesListener);

    final ToolItem manageLibrariesButton = new ToolItem(toolBar, SWT.PUSH);
    manageLibrariesButton.setImage(manageLibrariesImage);
    manageLibrariesButton.setToolTipText(Resources.manageLibrariesButtonToolTip);
    manageLibrariesButton.addSelectionListener(manageLibrariesListener);

    final SelectionAdapter downloadLibraryListener = new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent event) {
            final UserLibraryProviderInstallOperationConfig cfg = (UserLibraryProviderInstallOperationConfig) getOperationConfig();

            final String downloadedLibraryName = DownloadLibraryWizard.open(cfg);

            if (downloadedLibraryName != null) {
                refreshLibrariesList();
                cfg.addLibraryName(downloadedLibraryName);
            }
        }
    };

    this.downloadLibraryMenuItem = new MenuItem(menu, SWT.PUSH);
    this.downloadLibraryMenuItem.setText(Resources.downloadLibraryMenuItem);
    this.downloadLibraryMenuItem.setImage(downloadLibraryImage);
    this.downloadLibraryMenuItem.setEnabled(this.downloadCommandEnabled);
    this.downloadLibraryMenuItem.addSelectionListener(downloadLibraryListener);

    this.downloadLibraryButton = new ToolItem(toolBar, SWT.PUSH);
    this.downloadLibraryButton.setImage(downloadLibraryImage);
    this.downloadLibraryButton.setToolTipText(Resources.downloadLibraryButtonToolTip);
    this.downloadLibraryButton.setEnabled(this.downloadCommandEnabled);
    this.downloadLibraryButton.addSelectionListener(downloadLibraryListener);

    final Control footerControl = createFooter(this.rootComposite);

    if (footerControl != null) {
        footerControl.setLayoutData(gdhfill());
    }

    this.rootComposite.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(final DisposeEvent event) {
            cfg.removeListener(listener);
            manageLibrariesImage.dispose();
            downloadLibraryImage.dispose();
        }
    });

    return this.rootComposite;
}

From source file:org.eclipse.jubula.client.ui.rcp.editors.CentralTestDataEditor.java

License:Open Source License

/** {@inheritDoc} */
protected void createPartControlImpl(Composite parent) {
    createMainPart(parent);//from w  w  w.j a va  2 s.c  o m
    GridData gridData = new GridData(GridData.FILL_BOTH);
    getMainTreeViewer().getControl().setLayoutData(gridData);
    setControl(getMainTreeViewer().getControl());
    getMainTreeViewer().setContentProvider(new CentralTestDataContentProvider());

    DecoratingLabelProvider lp = new DecoratingLabelProvider(new CentralTestDataLabelProvider(),
            Plugin.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator());

    getMainTreeViewer().setLabelProvider(lp);
    getMainTreeViewer().setComparator(new ViewerComparator() {
        @Override
        public int category(Object element) {
            if (element instanceof ITestDataCategoryPO) {
                return 0;
            }

            if (element instanceof ITestDataCubePO) {
                return 1;
            }

            return 2;
        }
    });

    int ops = DND.DROP_MOVE;
    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    ViewerDropAdapter dropSupport = new CentralTestDataDropSupport(getMainTreeViewer());
    dropSupport.setFeedbackEnabled(false);
    getMainTreeViewer().addDragSupport(ops, transfers,
            new LimitingDragSourceListener(getMainTreeViewer(), null));
    getMainTreeViewer().addDropSupport(ops, transfers, dropSupport);

    addDoubleClickListener(RCPCommandIDs.EDIT_PARAMETERS, getMainTreeViewer());
    addFocusListener(getMainTreeViewer());
    getEditorHelper().addListeners();
    setActionHandlers();
    setInitialInput();
    DataEventDispatcher ded = DataEventDispatcher.getInstance();
    ded.addPropertyChangedListener(this, true);
    ded.addParamChangedListener(this, true);
    GuiEventDispatcher.getInstance().addEditorDirtyStateListener(this, true);
}

From source file:org.eclipse.jubula.client.ui.rcp.search.SearchResultPage.java

License:Open Source License

/** {@inheritDoc} */
public void createControl(Composite parent) {
    Composite topLevelComposite = new Composite(parent, SWT.NONE);
    setControl(topLevelComposite);/*from  w w  w. jav  a2s.  co m*/
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.verticalSpacing = 2;
    layout.marginWidth = LayoutUtil.MARGIN_WIDTH;
    layout.marginHeight = LayoutUtil.MARGIN_HEIGHT;
    topLevelComposite.setLayout(layout);

    GridData layoutData = new GridData(GridData.FILL_BOTH);
    layoutData.grabExcessHorizontalSpace = true;
    topLevelComposite.setLayoutData(layoutData);

    final FilteredTree ft = new JBFilteredTree(topLevelComposite,
            SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new JBPatternFilter(), true);

    setTreeViewer(ft.getViewer());

    ColumnViewerToolTipSupport.enableFor(getTreeViewer());
    getTreeViewer().addDoubleClickListener(m_doubleClickListener);
    getTreeViewer().setContentProvider(new SearchResultContentProvider());
    getTreeViewer().setLabelProvider(new DecoratingLabelProvider(new LabelProvider(),
            Plugin.getDefault().getWorkbench().getDecoratorManager().getLabelDecorator()));
    getTreeViewer().setComparator(new ViewerComparator());
    getSite().setSelectionProvider(getTreeViewer());

    DataEventDispatcher.getInstance().addProjectLoadedListener(this, true);

    Plugin.getHelpSystem().setHelp(parent, ContextHelpIds.JB_SEARCH_RESULT_VIEW);

    // Create menu manager and menu
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(getTreeViewer().getControl());
    getTreeViewer().getControl().setMenu(menu);
    // Register menu for extension.
    getSite().registerContextMenu(getID(), menuMgr, getTreeViewer());

}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.AutIdListComposite.java

License:Open Source License

/**
 * Creates the necessary components and sets their initial values.
 * /*  w  w  w  .  j a va  2  s . c o  m*/
 * @param autIdValidator The validator for the AUT ID text field.
 */
@SuppressWarnings("unchecked")
private void init(final IValidator autIdValidator) {
    GridLayout compositeLayout = new GridLayout();
    compositeLayout.numColumns = 2;
    compositeLayout.marginHeight = 0;
    compositeLayout.marginWidth = 0;
    setLayout(compositeLayout);
    Label idLabel = new Label(this, SWT.NONE);
    idLabel.setText(Messages.AUTPropertiesDialogAutId);
    ControlDecorator.createInfo(idLabel, I18n.getString("AUTPropertiesDialog.AutId.helpText"), false); //$NON-NLS-1$
    GridData data = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
    data.horizontalSpan = 1;
    idLabel.setLayoutData(data);

    // Created to keep layout consistent
    new Label(this, SWT.NONE).setVisible(false);

    final WritableList idListModel = new WritableList(m_aut.getAutIds(), String.class);
    final ListViewer idListViewer = new ListViewer(this, LayoutUtil.MULTI_TEXT_STYLE);
    idListViewer.setContentProvider(new ObservableListContentProvider());
    idListViewer.setComparator(new ViewerComparator());
    idListViewer.setInput(idListModel);
    final List idList = idListViewer.getList();
    data = new GridData(SWT.FILL, SWT.FILL, true, false);
    data.verticalSpan = 3;
    data.widthHint = Dialog.convertHeightInCharsToPixels(LayoutUtil.getFontMetrics(idList), 4);
    idList.setLayoutData(data);

    createButtons(this, autIdValidator, idList, idListModel);
}

From source file:org.eclipse.languageserver.ui.NewContentTypeLSPLaunchDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite res = (Composite) super.createDialogArea(parent);
    res.setLayout(new GridLayout(2, false));
    new Label(res, SWT.NONE).setText(Messages.NewContentTypeLSPLaunchDialog_associateContentType);
    new Label(res, SWT.NONE).setText(Messages.NewContentTypeLSPLaunchDialog_withLSPLaunch);
    // copied from ContentTypesPreferencePage
    FilteredTree contentTypesFilteredTree = new FilteredTree(res, SWT.BORDER, new PatternFilter(), true);
    TreeViewer contentTypesViewer = contentTypesFilteredTree.getViewer();
    contentTypesFilteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    contentTypesViewer.setContentProvider(new ContentTypesContentProvider());
    contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider());
    contentTypesViewer.setComparator(new ViewerComparator());
    contentTypesViewer.setInput(Platform.getContentTypeManager());
    contentTypesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override/* w ww. j a  v a2  s .  c o  m*/
        public void selectionChanged(SelectionChangedEvent event) {
            IContentType newContentType = null;
            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) event.getSelection();
                if (sel.size() == 1 && sel.getFirstElement() instanceof IContentType) {
                    newContentType = (IContentType) sel.getFirstElement();
                }
            }
            contentType = newContentType;
            updateButtons();
        }
    });
    // copied from LaunchConfigurationDialog : todo use LaunchConfigurationFilteredTree
    FilteredTree launchersFilteredTree = new FilteredTree(res, SWT.BORDER, new PatternFilter(), true);
    TreeViewer launchConfigViewer = launchersFilteredTree.getViewer();
    launchersFilteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    launchConfigViewer.setLabelProvider(new DecoratingLabelProvider(DebugUITools.newDebugModelPresentation(),
            PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
    launchConfigViewer.setContentProvider(new LaunchConfigurationTreeContentProvider(null, getShell()));
    launchConfigViewer.setInput(DebugPlugin.getDefault().getLaunchManager());
    ComboViewer launchModeViewer = new ComboViewer(res);
    GridData comboGridData = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false, 2, 1);
    comboGridData.widthHint = 100;
    launchModeViewer.getControl().setLayoutData(comboGridData);
    launchModeViewer.setContentProvider(new ArrayContentProvider());
    launchModeViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object o) {
            StringBuilder res = new StringBuilder();
            for (String s : (Set<String>) o) {
                res.append(s);
                res.append(',');
            }
            if (res.length() > 0) {
                res.deleteCharAt(res.length() - 1);
            }
            return res.toString();
        }
    });
    launchConfigViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ILaunchConfiguration newLaunchConfig = null;
            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) event.getSelection();
                if (sel.size() == 1 && sel.getFirstElement() instanceof ILaunchConfiguration) {
                    newLaunchConfig = (ILaunchConfiguration) sel.getFirstElement();
                }
            }
            launchConfig = newLaunchConfig;
            updateLaunchModes(launchModeViewer);
            updateButtons();
        }
    });
    launchModeViewer.addSelectionChangedListener(event -> {
        ISelection sel = event.getSelection();
        if (sel.isEmpty()) {
            launchMode = null;
        } else if (sel instanceof IStructuredSelection) {
            launchMode = (Set<String>) ((IStructuredSelection) sel).getFirstElement();
        }
        updateButtons();
    });
    return res;
}