Example usage for org.eclipse.jface.viewers TreeViewer setContentProvider

List of usage examples for org.eclipse.jface.viewers TreeViewer setContentProvider

Introduction

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

Prototype

@Override
public void setContentProvider(IContentProvider provider) 

Source Link

Document

Sets the content provider used by this TreeViewer.

Usage

From source file:eu.udig.omsbox.ui.CoverageCatalogTreeViewer.java

License:Open Source License

public CoverageCatalogTreeViewer(Composite parent, int style, int selectionStyle) {
    super(parent, style);
    setLayout(new GridLayout(1, false));
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    setLayoutData(gridData);//from  ww  w . j av  a  2 s  .co m

    try {
        getCoverageResources();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Create the tree viewer to display the file tree
    PatternFilter patternFilter = new PatternFilter();
    final FilteredTree filter = new FilteredTree(this, selectionStyle, patternFilter, true);
    final TreeViewer tv = filter.getViewer();
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new MyContentProvider());
    MyLabelProvider labelProvider = new MyLabelProvider();
    tv.setLabelProvider(labelProvider);
    tv.setInput(itemsMap);
    tv.addSelectionChangedListener(this);
}

From source file:eu.udig.omsbox.ui.CoverageLayersTreeViewer.java

License:Open Source License

public CoverageLayersTreeViewer(Composite parent, int style, int selectionStyle) {
    super(parent, style);
    setLayout(new GridLayout(1, false));
    GridData gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    setLayoutData(gridData);/*  w w  w .j a va2 s  .  c om*/

    try {
        getCoverageResources();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Create the tree viewer to display the file tree
    PatternFilter patternFilter = new PatternFilter();
    final FilteredTree filter = new FilteredTree(this, selectionStyle, patternFilter, true);
    final TreeViewer tv = filter.getViewer();
    tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    tv.setContentProvider(new MyContentProvider());
    MyLabelProvider labelProvider = new MyLabelProvider();
    tv.setLabelProvider(labelProvider);
    tv.setInput(itemsMap);
    tv.addSelectionChangedListener(this);
}

From source file:eu.udig.omsbox.view.OmsBoxView.java

License:Open Source License

private TreeViewer createTreeViewer(Composite modulesComposite) {

    PatternFilter patternFilter = new PatternFilter();
    final FilteredTree filter = new FilteredTree(modulesComposite, SWT.SINGLE | SWT.BORDER, patternFilter,
            true);/*  w w w  .j  a va  2 s .com*/
    final TreeViewer modulesViewer = filter.getViewer();

    Control control = modulesViewer.getControl();
    GridData controlGD = new GridData(SWT.FILL, SWT.FILL, true, true);
    control.setLayoutData(controlGD);
    modulesViewer.setContentProvider(new ITreeContentProvider() {
        public Object[] getElements(Object inputElement) {
            return getChildren(inputElement);
        }

        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof List<?>) {
                List<?> list = (List<?>) parentElement;
                Object[] array = list.toArray();
                return array;
            }
            if (parentElement instanceof ViewerFolder) {
                ViewerFolder folder = (ViewerFolder) parentElement;
                List<ViewerFolder> subFolders = folder.getSubFolders();
                List<ViewerModule> modules = folder.getModules();
                List<Object> allObjs = new ArrayList<Object>();
                allObjs.addAll(subFolders);
                allObjs.addAll(modules);

                return allObjs.toArray();
            }
            return new Object[0];
        }

        public Object getParent(Object element) {
            if (element instanceof ViewerFolder) {
                ViewerFolder folder = (ViewerFolder) element;
                return folder.getParentFolder();
            }
            if (element instanceof ViewerModule) {
                ViewerModule module = (ViewerModule) element;
                return module.getParentFolder();
            }
            return null;
        }

        public boolean hasChildren(Object element) {
            return getChildren(element).length > 0;
        }

        public void dispose() {
        }

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

    });

    modulesViewer.setLabelProvider(new LabelProvider() {
        public Image getImage(Object element) {
            if (element instanceof ViewerFolder) {
                return ImageCache.getInstance().getImage(ImageCache.CATEGORY);
            }
            if (element instanceof ViewerModule) {
                ModuleDescription md = ((ViewerModule) element).getModuleDescription();
                Status status = md.getStatus();
                if (status == Status.experimental) {
                    return ImageCache.getInstance().getImage(ImageCache.MODULEEXP);
                } else {
                    return ImageCache.getInstance().getImage(ImageCache.MODULE);
                }
            }
            return null;
        }

        public String getText(Object element) {
            if (element instanceof ViewerFolder) {
                ViewerFolder categoryFolder = (ViewerFolder) element;
                return categoryFolder.getName();
            }
            if (element instanceof ViewerModule) {
                ModuleDescription module = ((ViewerModule) element).getModuleDescription();
                return module.getName().replaceAll("\\_\\_", ".");
            }
            return ""; //$NON-NLS-1$
        }
    });

    modulesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!(event.getSelection() instanceof IStructuredSelection)) {
                return;
            }
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();

            Object selectedItem = sel.getFirstElement();
            if (selectedItem == null) {
                // unselected, show empty panel
                putUnselected();
                return;
            }

            if (selectedItem instanceof ViewerModule) {
                ModuleDescription currentSelectedModule = ((ViewerModule) selectedItem).getModuleDescription();
                currentSelectedModuleGui = new ModuleGui(currentSelectedModule);

                Control control = currentSelectedModuleGui.makeGui(modulesGuiComposite, false);

                // Label dummyLabel = new Label(modulesGuiComposite, SWT.NONE);
                // dummyLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
                // false));
                // dummyLabel.setText(currentSelectedModule.toString());

                modulesGuiStackLayout.topControl = control;
                modulesGuiComposite.layout(true);
            } else {
                putUnselected();
            }
        }

    });

    return modulesViewer;
}

From source file:eu.udig.style.advanced.lines.LinePropertiesEditor.java

License:Open Source License

private TreeViewer createGroupRulesTableViewer(Composite rulesGroup) {
    final TreeViewer rulesViewer = new TreeViewer(rulesGroup, SWT.SINGLE | SWT.BORDER);
    Control treeControl = rulesViewer.getControl();
    // table.setSize(PREVIEWWIDTH, -1);
    GridData treeGD = new GridData(SWT.FILL, SWT.TOP, true, false);
    treeGD.horizontalSpan = 6;//from  w  ww.  j av  a  2s . co  m
    treeGD.heightHint = 100;
    // tableGD.minimumWidth = PREVIEWWIDTH;
    treeControl.setLayoutData(treeGD);
    rulesViewer.setContentProvider(new GroupRulesTreeContentProvider());

    rulesViewer.setLabelProvider(new GroupRulesTreeLabelProvider(SLD.LINE));

    rulesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        private LinePropertiesComposite linePropertieComposite;

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (!(selection instanceof IStructuredSelection)) {
                return;
            }
            IStructuredSelection sel = (IStructuredSelection) selection;

            if (sel.isEmpty()) {
                showEmptyLabel();
                return;
            }

            Object selectedItem = sel.getFirstElement();
            if (selectedItem == null) {
                // unselected, show empty panel
                return;
            }

            if (selectedItem instanceof FeatureTypeStyleWrapper) {
                showEmptyLabel();
            }

            if (selectedItem instanceof RuleWrapper) {
                RuleWrapper currentSelectedRule = (RuleWrapper) selectedItem;
                if (propertiesComposite != null) {
                    if (linePropertieComposite == null) {
                        linePropertieComposite = new LinePropertiesComposite(LinePropertiesEditor.this,
                                propertiesComposite);
                    }
                    linePropertieComposite.setRule(currentSelectedRule);
                    propertiesStackLayout.topControl = linePropertieComposite.getComposite();
                    propertiesComposite.layout();
                }

            }
        }

        private void showEmptyLabel() {
            Label emptyLabel = new Label(propertiesComposite, SWT.NONE);
            emptyLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
            emptyLabel.setText(Messages.LinePropertiesEditor_3);
            propertiesStackLayout.topControl = emptyLabel;
            propertiesComposite.layout();
        }

    });
    return rulesViewer;
}

From source file:eu.udig.style.advanced.points.PointPropertiesEditor.java

License:Open Source License

private TreeViewer createGroupRulesTreeViewer(Composite rulesGroup) {
    final TreeViewer rulesViewer = new TreeViewer(rulesGroup, SWT.SINGLE | SWT.BORDER);
    Control treeControl = rulesViewer.getControl();
    GridData treeGD = new GridData(SWT.FILL, SWT.TOP, true, false);
    treeGD.horizontalSpan = 6;//from  w  w  w .j a v a2  s . com
    treeGD.heightHint = 100;
    treeControl.setLayoutData(treeGD);

    rulesViewer.setContentProvider(new GroupRulesTreeContentProvider());
    rulesViewer.setLabelProvider(new GroupRulesTreeLabelProvider(SLD.POINT));

    rulesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        private PointPropertiesComposite pointPropertieComposite;

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (!(selection instanceof IStructuredSelection)) {
                return;
            }
            IStructuredSelection sel = (IStructuredSelection) selection;

            if (sel.isEmpty()) {
                showEmptyLabel();
                return;
            }

            Object selectedItem = sel.getFirstElement();
            if (selectedItem == null) {
                // unselected, show empty panel
                return;
            }

            if (selectedItem instanceof FeatureTypeStyleWrapper) {
                showEmptyLabel();
            }

            if (selectedItem instanceof RuleWrapper) {
                RuleWrapper currentSelectedRule = (RuleWrapper) selectedItem;
                if (propertiesComposite != null) {
                    if (pointPropertieComposite == null) {
                        pointPropertieComposite = new PointPropertiesComposite(PointPropertiesEditor.this,
                                propertiesComposite);
                    }
                    pointPropertieComposite.setRule(currentSelectedRule);
                    propertiesStackLayout.topControl = pointPropertieComposite.getComposite();
                    propertiesComposite.layout();
                }

            }
        }

        private void showEmptyLabel() {
            Label emptyLabel = new Label(propertiesComposite, SWT.NONE);
            emptyLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
            emptyLabel.setText(Messages.PointPropertiesEditor_3);
            propertiesStackLayout.topControl = emptyLabel;
            propertiesComposite.layout();
        }

    });
    return rulesViewer;
}

From source file:eu.udig.style.advanced.polygons.PolygonPropertiesEditor.java

License:Open Source License

private TreeViewer createGroupRulesTableViewer(Composite rulesGroup) {
    final TreeViewer rulesViewer = new TreeViewer(rulesGroup, SWT.SINGLE | SWT.BORDER);
    Control treeControl = rulesViewer.getControl();
    // table.setSize(PREVIEWWIDTH, -1);
    GridData treeGD = new GridData(SWT.FILL, SWT.TOP, true, false);
    treeGD.horizontalSpan = 6;//from ww w .  j a va 2  s  .  com
    treeGD.heightHint = 100;
    // tableGD.minimumWidth = PREVIEWWIDTH;
    treeControl.setLayoutData(treeGD);
    rulesViewer.setContentProvider(new GroupRulesTreeContentProvider());

    rulesViewer.setLabelProvider(new GroupRulesTreeLabelProvider(SLD.POLYGON));

    rulesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        private PolygonPropertiesComposite polygonPropertieComposite;

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (!(selection instanceof IStructuredSelection)) {
                return;
            }
            IStructuredSelection sel = (IStructuredSelection) selection;

            if (sel.isEmpty()) {
                showEmptyLabel();
                return;
            }

            Object selectedItem = sel.getFirstElement();
            if (selectedItem == null) {
                // unselected, show empty panel
                return;
            }
            if (selectedItem instanceof FeatureTypeStyleWrapper) {
                showEmptyLabel();
            }

            if (selectedItem instanceof RuleWrapper) {
                RuleWrapper currentSelectedRule = (RuleWrapper) selectedItem;
                if (propertiesComposite != null) {
                    if (polygonPropertieComposite == null) {
                        polygonPropertieComposite = new PolygonPropertiesComposite(PolygonPropertiesEditor.this,
                                propertiesComposite);
                    }
                    polygonPropertieComposite.setRule(currentSelectedRule);
                    propertiesStackLayout.topControl = polygonPropertieComposite.getComposite();
                    propertiesComposite.layout();
                }

            }
        }

        private void showEmptyLabel() {
            Label emptyLabel = new Label(propertiesComposite, SWT.NONE);
            emptyLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
            emptyLabel.setText(Messages.PolygonPropertiesEditor_3);
            propertiesStackLayout.topControl = emptyLabel;
            propertiesComposite.layout();
        }

    });
    return rulesViewer;
}

From source file:eu.xsdi.mdlui.views.MismatchPropertiesBlock.java

License:LGPL

@Override
protected void createMasterPart(final IManagedForm managedForm, Composite parent) {
    FormToolkit toolkit = managedForm.getToolkit();

    Section section = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
    section.setText("Mismatches"); //$NON-NLS-1$
    section.setDescription("Select the Mismatch or one of it's children to view and edit it."); //$NON-NLS-1$
    section.marginWidth = 10;// w w  w  .j a  v  a2 s. c o  m
    section.marginHeight = 5;

    Composite client = toolkit.createComposite(section, SWT.WRAP);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 2;
    layout.marginHeight = 2;
    client.setLayout(layout);
    Tree tree = toolkit.createTree(client, SWT.NULL);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 20;
    gd.widthHint = 250;
    tree.setLayoutData(gd);
    toolkit.paintBordersFor(client);
    section.setClient(client);

    final SectionPart spart = new SectionPart(section);
    managedForm.addPart(spart);
    TreeViewer mismatchTreeViewer = new TreeViewer(tree);
    mismatchTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            managedForm.fireSelectionChanged(spart, event.getSelection());
        }
    });
    mismatchTreeViewer.setContentProvider(new MismatchTreeContentProvider());
    mismatchTreeViewer.setLabelProvider(new MismatchTreeLabelProvider());
    mismatchTreeViewer.setInput(getDummyCell());
}

From source file:example.debug.ui.views.DataStackView.java

License:Open Source License

protected Viewer createViewer(Composite parent) {
    TreeViewer viewer = new TreeViewer(parent);
    viewer.setLabelProvider(DebugUITools.newDebugModelPresentation());
    viewer.setContentProvider(new StackViewContentProvider());
    getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(IDebugUIConstants.ID_DEBUG_VIEW,
            this);
    getSite().setSelectionProvider(viewer);
    return viewer;
}

From source file:ext.org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgUserInputPage.java

License:Open Source License

private TreeViewer createViewer(Composite parent) {
    TreeViewer treeViewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(40);
    gd.heightHint = convertHeightInCharsToPixels(15);
    treeViewer.getTree().setLayoutData(gd);
    treeViewer.setLabelProvider(new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_SMALL_ICONS));
    treeViewer.setContentProvider(new DestinationContentProvider(getDestinationValidator()));
    treeViewer.setComparator(new JavaElementComparator());
    treeViewer.setInput(JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()));
    return treeViewer;
}

From source file:ext.org.eclipse.jdt.internal.ui.search.JavaSearchResultPage.java

License:Open Source License

@Override
protected void configureTreeViewer(TreeViewer viewer) {
    PostfixLabelProvider postfixLabelProvider = new PostfixLabelProvider(this);
    viewer.setUseHashlookup(true);//  w  w w  . j av a2 s . com
    viewer.setComparator(new DecoratorIgnoringViewerSorter(postfixLabelProvider));
    viewer.setLabelProvider(new DecoratingJavaLabelProvider(postfixLabelProvider, false));
    fContentProvider = new LevelTreeContentProvider(this, fCurrentGrouping);
    viewer.setContentProvider(fContentProvider);
    addDragAdapters(viewer);
}