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

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

Introduction

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

Prototype

public LabelProvider() 

Source Link

Document

Creates a new label provider.

Usage

From source file:com.ebmwebsourcing.petals.services.su.ui.ServiceOperationDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {

    // Create the parent
    Composite bigContainer = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;/*  w w w  .  j ava2s.co  m*/
    bigContainer.setLayout(layout);
    bigContainer.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite container = new Composite(bigContainer, SWT.NONE);
    container.setLayout(new GridLayout(2, true));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    // Put a viewer on the left
    final TableViewer viewer = new TableViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    viewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(new OperationLabelProvider()));
    viewer.setInput(this.opNameToMep.keySet());

    // Add widgets on the right
    Composite rightPart = new Composite(container, SWT.NONE);
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    rightPart.setLayout(layout);
    rightPart.setLayoutData(new GridData(GridData.FILL_BOTH));

    final Button customOpButton = new Button(rightPart, SWT.CHECK);
    customOpButton.setText("Define a custom operation");
    GridData layoutData = new GridData();
    layoutData.horizontalSpan = 2;
    customOpButton.setLayoutData(layoutData);

    Label l = new Label(rightPart, SWT.NONE);
    l.setText("Name space:");
    l.setToolTipText("The operation's name space");

    this.nsText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("Name:");
    l.setToolTipText("The operation's name");

    this.nameText = new Text(rightPart, SWT.BORDER | SWT.SINGLE);
    this.nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    l = new Label(rightPart, SWT.NONE);
    l.setText("MEP:");
    l.setToolTipText("The Message Exchange Pattern");

    this.mepViewer = new ComboViewer(rightPart, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    this.mepViewer.getCombo().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    this.mepViewer.setContentProvider(new ArrayContentProvider());
    this.mepViewer.setLabelProvider(new LabelProvider());
    this.mepViewer.setInput(Mep.values());

    // Complete the dialog properties
    getShell().setText("Operation Viewer");
    setTitle("Operation Viewer");
    setMessage("View and edit service operations.");

    // Add the listeners
    customOpButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {

            ServiceOperationDialog.this.useCustomOperation = customOpButton.getSelection();
            ServiceOperationDialog.this.nsText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.nameText.setEditable(customOpButton.getSelection());
            ServiceOperationDialog.this.mepViewer.getCombo().setEnabled(customOpButton.getSelection());
            validate();
        }
    });

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            Object o = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            ServiceOperationDialog.this.nsText.setText(((QName) o).getNamespaceURI());
            ServiceOperationDialog.this.nameText.setText(((QName) o).getLocalPart());

            Mep mep = ServiceOperationDialog.this.opNameToMep.get(o);
            ServiceOperationDialog.this.mepViewer.setSelection(new StructuredSelection(mep));
        }
    });

    customOpButton.setSelection(false);
    customOpButton.notifyListeners(SWT.Selection, new Event());

    ModifyListener modifyListener = new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if ((((Text) e.widget).getStyle() & SWT.READ_ONLY) == 0)
                validate();
        }
    };

    this.nameText.addModifyListener(modifyListener);
    this.nsText.addModifyListener(modifyListener);
    this.mepViewer.getCombo().addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            if (((Combo) e.widget).isEnabled())
                validate();
        }
    });

    return bigContainer;
}

From source file:com.ebmwebsourcing.petals.services.su.wizards.pages.ChoicePage.java

License:Open Source License

@Override
public void createControl(Composite parent) {

    // Create the composite container and define its layout
    final Composite container = SwtFactory.createComposite(parent);
    setControl(container);/*from w w  w  .j  a  va  2s . c  o m*/
    SwtFactory.applyNewGridLayout(container, 2, false, 15, 0, 0, 15);
    SwtFactory.applyHorizontalGridData(container);

    // Add a tool tip to display in case of problem
    this.helpTooltip = new FixedShellTooltip(getShell(), true, 90) {
        @Override
        public void populateTooltip(Composite parent) {

            GridLayout layout = new GridLayout();
            layout.verticalSpacing = 2;
            parent.setLayout(layout);
            parent.setLayoutData(new GridData(GridData.FILL_BOTH));
            parent.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));

            try {
                ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(
                        PetalsConstants.PETALS_COMMON_PLUGIN_ID, "icons/petals/thinking_hard.png");

                if (desc != null)
                    ChoicePage.this.helpImg = desc.createImage();

                parent.setBackgroundMode(SWT.INHERIT_DEFAULT);
                Label imgLabel = new Label(parent, SWT.NONE);
                imgLabel.setImage(ChoicePage.this.helpImg);
                imgLabel.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true));

            } catch (Exception e) {
                PetalsServicesPlugin.log(e, IStatus.WARNING);
            }

            FontData[] fd = PlatformUtils.getModifiedFontData(getFont().getFontData(), SWT.BOLD);
            ChoicePage.this.boldFont = new Font(getShell().getDisplay(), fd);
            Label titleLabel = new Label(parent, SWT.NONE);
            titleLabel.setFont(ChoicePage.this.boldFont);
            GridData layoutData = new GridData(SWT.CENTER, SWT.DEFAULT, true, true);
            layoutData.verticalIndent = 5;
            titleLabel.setLayoutData(layoutData);
            titleLabel.setText("What does this error mean?");

            Label l = new Label(parent, SWT.WRAP);
            l.setText("This wizard will generate, among other things, Maven artifacts.");
            layoutData = new GridData();
            layoutData.verticalIndent = 8;
            l.setLayoutData(layoutData);

            RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
            rowLayout.marginLeft = 0;
            rowLayout.marginTop = 0;
            rowLayout.marginRight = 0;
            rowLayout.marginBottom = 0;
            rowLayout.spacing = 0;

            Composite rowComposite = new Composite(parent, SWT.NONE);
            rowComposite.setLayout(rowLayout);
            rowComposite.setLayoutData(new GridData(SWT.CENTER, SWT.DEFAULT, true, true));

            new Label(rowComposite, SWT.WRAP).setText("Unfortunately, there is a problem with the ");
            Link link = new Link(rowComposite, SWT.WRAP | SWT.NO_FOCUS);
            link.setText("<A>the Petals Maven preferences</A>");
            new Label(rowComposite, SWT.WRAP).setText(".");
            new Label(parent, SWT.WRAP).setText("Please, make them correct.");

            link.addSelectionListener(new DefaultSelectionListener() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    try {
                        PreferencesUtil.createPreferenceDialogOn(new Shell(),
                                "com.ebmwebsourcing.petals.services.prefs.maven", null, null).open();

                    } catch (Exception e1) {
                        PetalsServicesPlugin.log(e1, IStatus.ERROR);
                    }
                }
            });
        }
    };

    // Prepare the input
    Comparator<AbstractServiceUnitWizard> comparator = new Comparator<AbstractServiceUnitWizard>() {
        @Override
        public int compare(AbstractServiceUnitWizard o1, AbstractServiceUnitWizard o2) {
            String v1 = o1.getComponentVersionDescription().getComponentVersion();
            String v2 = o2.getComponentVersionDescription().getComponentVersion();
            return -v1.compareTo(v2); // negative so that the most recent is first
        }
    };

    final Map<String, Collection<AbstractServiceUnitWizard>> componentNameToHandler = new TreeMap<String, Collection<AbstractServiceUnitWizard>>();
    final Map<PetalsKeyWords, Set<String>> keywordToComponentName = new TreeMap<PetalsKeyWords, Set<String>>();
    for (AbstractServiceUnitWizard handler : ExtensionManager.INSTANCE.findComponentWizards(this.petalsMode)) {
        for (PetalsKeyWords keyword : handler.getComponentVersionDescription().getKeyWords()) {
            Set<String> list = keywordToComponentName.get(keyword);
            if (list == null)
                list = new TreeSet<String>();

            String componentName = handler.getComponentVersionDescription().getComponentName();
            list.add(componentName);
            keywordToComponentName.put(keyword, list);

            Collection<AbstractServiceUnitWizard> handlers = componentNameToHandler.get(componentName);
            if (handlers == null)
                handlers = new TreeSet<AbstractServiceUnitWizard>(comparator);

            handlers.add(handler);
            componentNameToHandler.put(componentName, handlers);
        }
    }

    // Add the selection area
    final PhantomText searchText = new PhantomText(container, SWT.SINGLE | SWT.BORDER);
    searchText.setDefaultValue("Search...");
    GridDataFactory.swtDefaults().grab(true, false).align(SWT.FILL, SWT.TOP).span(2, 1).applyTo(searchText);

    final TreeViewer componentsViewer = new TreeViewer(container, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    GridDataFactory.fillDefaults().span(2, 1).hint(380, 300).applyTo(componentsViewer.getTree());
    componentsViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {

            String result;
            if (element instanceof String) {
                IComponentDescription desc = componentNameToHandler.get(element).iterator().next()
                        .getComponentVersionDescription();
                String componentName = desc.getComponentName();
                String componentAlias = desc.getComponentAlias();
                String annotation = desc.getComponentAnnotation();

                StringBuilder sb = new StringBuilder();
                if (StringUtils.isEmpty(componentName))
                    sb.append(componentAlias); // Generic component
                else
                    sb.append(componentAlias + "    -  " + componentName);

                if (!StringUtils.isEmpty(annotation))
                    sb.append("    ( " + annotation + " )");

                result = sb.toString();

            } else {
                result = super.getText(element);
            }

            return result;
        }

        @Override
        public Image getImage(Object element) {

            Image result = null;
            if (element instanceof PetalsKeyWords) {
                result = ChoicePage.this.keywordToImage.get(element);
            } else {
                IComponentDescription desc = componentNameToHandler.get(element).iterator().next()
                        .getComponentVersionDescription();
                result = desc.isBc() ? ChoicePage.this.bcImg : ChoicePage.this.seImg;
            }

            return result;
        }
    });

    componentsViewer.setContentProvider(new DefaultTreeContentProvider() {
        @Override
        public Object[] getElements(Object inputElement) {
            return keywordToComponentName.keySet().toArray();
        }

        @Override
        public Object[] getChildren(Object parentElement) {

            Object[] result;
            if (parentElement instanceof PetalsKeyWords) {
                Collection<String> componentNames = keywordToComponentName.get(parentElement);
                result = componentNames == null ? new Object[0] : componentNames.toArray();

            } else {
                result = new Object[0];
            }

            return result;
        }

        @Override
        public boolean hasChildren(Object element) {
            return element instanceof PetalsKeyWords;
        }
    });

    componentsViewer.addFilter(new ViewerFilter() {
        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {

            boolean result = false;
            String filter = searchText.getTextValue().trim().toLowerCase();
            if (filter.length() == 0)
                result = true;

            else if (element instanceof PetalsKeyWords) {
                Set<String> names = keywordToComponentName.get(element);
                if (names != null) {
                    for (String s : names) {
                        if (select(viewer, null, s)) {
                            result = true;
                            break;
                        }
                    }
                }
            }

            else if (element instanceof String)
                result = ((String) element).toLowerCase().contains(filter);

            return result;
        }
    });

    componentsViewer.setInput(new Object());
    if (keywordToComponentName.size() > 0)
        componentsViewer.expandToLevel(keywordToComponentName.keySet().iterator().next(), 1);

    // Display the available versions
    new Label(container, SWT.NONE).setText("Component Version:");
    final ComboViewer versionCombo = new ComboViewer(container, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData layoutData = new GridData();
    layoutData.widthHint = 130;
    versionCombo.getCombo().setLayoutData(layoutData);
    versionCombo.setContentProvider(new ArrayContentProvider());
    versionCombo.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((AbstractServiceUnitWizard) element).getComponentVersionDescription().getComponentVersion();
        }
    });

    final Label descriptionLabel = new Label(container, SWT.NONE);
    GridDataFactory.swtDefaults().span(2, 1).indent(0, 10).applyTo(descriptionLabel);

    // Selection listeners
    searchText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            componentsViewer.refresh();
            if (searchText.getTextValue().trim().length() == 0)
                componentsViewer.collapseAll();
            else
                componentsViewer.expandAll();
        }
    });

    componentsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            // Get the selection
            Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
            Collection<?> input;
            if (o == null || o instanceof PetalsKeyWords)
                input = Collections.emptyList();
            else
                input = componentNameToHandler.get(o);

            // Default selection - there is always one
            versionCombo.setInput(input);
            versionCombo.getCombo().setVisibleItemCount(input.size() > 0 ? input.size() : 1);
            if (!input.isEmpty()) {
                versionCombo.setSelection(new StructuredSelection(input.iterator().next()));
                versionCombo.getCombo().notifyListeners(SWT.Selection, new Event());
            } else {
                setPageComplete(false);
                setSelectedNode(null);
                descriptionLabel.setText("");
                descriptionLabel.getParent().layout();
            }
        }
    });

    versionCombo.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            AbstractServiceUnitWizard suWizard = (AbstractServiceUnitWizard) ((IStructuredSelection) event
                    .getSelection()).getFirstElement();
            if (suWizard == null)
                return;

            setPageComplete(true);
            setSelectedNode(getWizardNode(suWizard));

            String desc = ChoicePage.this.petalsMode == PetalsMode.provides
                    ? suWizard.getComponentVersionDescription().getProvideDescription()
                    : suWizard.getComponentVersionDescription().getConsumeDescription();
            descriptionLabel.setText(desc);
            descriptionLabel.getParent().layout();
        }
    });

    // Initialize
    if (PreferencesManager.isMavenTemplateConfigurationValid())
        this.helpTooltip.hide();

    componentsViewer.getTree().setFocus();
}

From source file:com.ecfeed.ui.common.TestDataValueEditingSupport.java

License:Open Source License

public TestDataValueEditingSupport(MethodNode method, TableViewer viewer,
        ITestDataEditorListener setValueListener) {
    super(viewer);
    fViewer = viewer;//  www. j av a2  s .co  m
    fSetValueListener = setValueListener;
    fMethod = method;

    fComboCellEditor = new ComboBoxViewerCellEditor(fViewer.getTable(), SWT.TRAIL);
    fComboCellEditor.setLabelProvider(new LabelProvider());
    fComboCellEditor.setContentProvider(new ArrayContentProvider());
}

From source file:com.ecfeed.ui.dialogs.GeneratorSetupDialog.java

License:Open Source License

private void createConstraintsViewer(Composite parent) {
    Tree tree = new Tree(parent, SWT.CHECK | SWT.BORDER);
    tree.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, true, 1, 1));
    fConstraintsViewer = new CheckboxTreeViewer(tree);
    fConstraintsViewer.setContentProvider(new ConstraintsViewerContentProvider());
    fConstraintsViewer.setLabelProvider(new LabelProvider() {
        @Override//from ww  w.j  ava 2 s.co  m
        public String getText(Object element) {
            if (element instanceof String) {
                return (String) element;
            }
            if (element instanceof Constraint) {
                return ((Constraint) element).toString();
            }
            return null;
        }
    });
    fConstraintsViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    fConstraintsViewer.setInput(fMethod);
    fConstraintsViewer.addCheckStateListener(new TreeCheckStateListener(fConstraintsViewer));
    fConstraintsViewer.expandAll();
    for (String constraint : fMethod.getConstraintsNames()) {
        fConstraintsViewer.setSubtreeChecked(constraint, true);
    }
    fConstraintsViewer.collapseAll();
}

From source file:com.ecfeed.ui.dialogs.SelectCompatibleMethodDialog.java

License:Open Source License

/**
 * Create contents of the dialog.//ww w . j a va 2  s  . c  o m
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    setTitle(Messages.DIALOG_RENAME_METHOD_TITLE);
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayout(new GridLayout(1, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    Text infoText = new Text(container, SWT.READ_ONLY | SWT.WRAP);
    infoText.setText(Messages.DIALOG_RENAME_METHOD_MESSAGE);
    infoText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));

    Composite tableComposite = new Composite(container, SWT.NONE);
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout tableCompositeLayout = new TableColumnLayout();
    tableComposite.setLayout(tableCompositeLayout);

    fMethodViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    Table methodsTable = fMethodViewer.getTable();
    methodsTable.setHeaderVisible(true);
    methodsTable.setLinesVisible(true);

    TableViewerColumn methodViewerColumn = new TableViewerColumn(fMethodViewer, SWT.NONE);
    TableColumn methodColumn = methodViewerColumn.getColumn();
    tableCompositeLayout.setColumnData(methodColumn, new ColumnPixelData(150, true, true));
    methodColumn.setText("Method");
    fMethodViewer.setContentProvider(new ArrayContentProvider());
    fMethodViewer.setLabelProvider(new LabelProvider() {
        @Override
        public String getText(Object element) {
            return ((MethodNode) element).toString();
        }
    });
    fMethodViewer.setInput(fCompatibleMethods);
    fMethodViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) fMethodViewer.getSelection();
            fSelectedMethod = (MethodNode) selection.getFirstElement();
            fOkButton.setEnabled(true);
        }
    });
    fMethodViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) fMethodViewer.getSelection();
            fSelectedMethod = (MethodNode) selection.getFirstElement();
            okPressed();
        }
    });

    return area;
}

From source file:com.ecfeed.ui.editor.TableViewerSection.java

License:Open Source License

@Override
protected IBaseLabelProvider viewerLabelProvider() {
    return new LabelProvider();
}

From source file:com.exmaple.e4.tableFunctionality.edit.Snippet027ComboBoxCellEditors.java

License:Open Source License

public Snippet027ComboBoxCellEditors(Shell shell) {
    final Table table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
    final TableViewer v = new TableViewer(table);
    final MyCellModifier modifier = new MyCellModifier(v);

    TableColumn column = new TableColumn(table, SWT.NONE);
    column.setWidth(200);//  w ww  . j  a  v a  2s .co  m

    v.setLabelProvider(new LabelProvider());
    v.setContentProvider(ArrayContentProvider.getInstance());
    v.setCellModifier(modifier);
    v.setColumnProperties(new String[] { "column1" });
    v.setCellEditors(new CellEditor[] { new ComboBoxCellEditor(v.getTable(), new String[] { "Zero", "Ten",
            "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" }) });

    v.setInput(createModel());
    v.getTable().setLinesVisible(true);
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.utils.dialogs.TagAndPushDialog.java

License:Open Source License

private void createRepositoriesList(Composite parent) {
    Label l = new Label(parent, SWT.NONE);
    l.setText("List of repositories:");
    l.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));

    TableViewer list = new TableViewer(parent, SWT.V_SCROLL + SWT.H_SCROLL + SWT.BORDER);
    list.setLabelProvider(new LabelProvider() {
        private Image img = UIIcons.REPOSITORY.createImage();

        @Override/*from  w w  w  . j  a v  a2  s.  c  o  m*/
        public Image getImage(Object element) {
            return img;
        }

        @Override
        public void dispose() {
            img.dispose();
        }

        @Override
        public String getText(Object element) {
            return ((Repository) element).getDirectory().getParentFile().getName();
        }
    });
    list.setContentProvider(new ArrayContentProvider());
    list.setInput(repos);
    Table lst = list.getTable();
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = 200;
    lst.setLayoutData(gd);
}

From source file:com.github.sdbg.debug.ui.internal.hover.DebugTooltipControl.java

License:Open Source License

@Override
protected void createContent(Composite parent) {
    sashForm = new SashForm(parent, parent.getStyle());
    sashForm.setOrientation(SWT.VERTICAL);

    // update presentation context
    AbstractDebugView view = getViewToEmulate();
    presentationContext = new PresentationContext(IDebugUIConstants.ID_VARIABLE_VIEW);
    if (view != null) {
        // copy over properties
        IPresentationContext copy = ((TreeModelViewer) view.getViewer()).getPresentationContext();
        String[] properties = copy.getProperties();
        for (int i = 0; i < properties.length; i++) {
            String key = properties[i];
            presentationContext.setProperty(key, copy.getProperty(key));
        }/*from   ww w. java2 s.com*/
    }

    final SDBGDebugModelPresentation presentation = new SDBGDebugModelPresentation();

    treeViewer = new TreeViewer(sashForm, SWT.SINGLE | SWT.V_SCROLL | SWT.FULL_SELECTION);
    treeViewer.setAutoExpandLevel(2);
    treeViewer.setLabelProvider(new LabelProvider() {
        @Override
        public Image getImage(Object element) {
            return presentation.getImage(element);
        }

        @Override
        public String getText(Object element) {
            return presentation.getVariableText((IVariable) element);
        }
    });
    treeViewer.setContentProvider(new ObjectInspectorContentProvider());

    if (view != null) {
        // copy over filters
        StructuredViewer structuredViewer = (StructuredViewer) view.getViewer();
        if (structuredViewer != null) {
            ViewerFilter[] filters = structuredViewer.getFilters();
            for (int i = 0; i < filters.length; i++) {
                treeViewer.addFilter(filters[i]);
            }
        }
    }

    detailPaneComposite = SWTFactory.createComposite(sashForm, 1, 1, GridData.FILL_BOTH);
    Layout layout = detailPaneComposite.getLayout();
    if (layout instanceof GridLayout) {
        GridLayout gl = (GridLayout) layout;
        gl.marginHeight = 0;
        gl.marginWidth = 0;
    }

    detailPane = new DetailPaneProxy(new DetailPaneContainer());
    // Bring up the default pane so the user doesn't see an empty composite.
    detailPane.display(null);

    treeViewer.getTree().addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {

        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            detailPane.display((IStructuredSelection) treeViewer.getSelection());
        }
    });

    initSashWeights();

    // Use the standard tooltip colors on a mac.
    if (DartCore.isMac()) {
        setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    }
}

From source file:com.github.sdbg.debug.ui.internal.util.LaunchTargetComposite.java

License:Open Source License

private IProject chooseProject() {
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new LabelProvider() {
        @Override//from  www .  j  a  v  a 2s .  c o  m
        public String getText(Object element) {
            return ((IProject) element).getName();
        }
    });
    dialog.setTitle(ChromeLaunchMessages.ChromeMainTab_SelectProjectTitle);
    dialog.setMessage(ChromeLaunchMessages.ChromeMainTab_SelectProjectMessage);

    dialog.setElements(ResourcesPlugin.getWorkspace().getRoot().getProjects());

    IProject project = null;

    try {
        project = ResourcesPlugin.getWorkspace().getRoot().getProject(getProject());
    } catch (IllegalArgumentException e) {
        // Best effort
    }

    if (project != null && project.exists()) {
        dialog.setInitialSelections(new Object[] { project });
    }
    if (dialog.open() == Window.OK) {
        return (IProject) dialog.getFirstResult();
    }
    return null;
}