List of usage examples for org.eclipse.jface.viewers TreeViewer setContentProvider
@Override public void setContentProvider(IContentProvider provider)
TreeViewer
. From source file:org.activiti.designer.eclipse.navigator.cloudrepo.dialog.SelectFolderForDownloadDialog.java
License:Apache License
@Override protected Control createDialogArea(Composite parent) { Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(2, false); container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); container.setLayout(layout);/*from www .j ava 2s . c o m*/ // Project tree viewer final TreeViewer projectTreeViewer = new TreeViewer(container, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL); projectTreeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); projectTreeViewer.setContentProvider(new FileTreeContentProvider()); projectTreeViewer.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider()); projectTreeViewer.setInput(ResourcesPlugin.getWorkspace()); // Expand current selection on double click projectTreeViewer.addDoubleClickListener(new OpenFolderOnDoubleClickListener()); // Selection listener for folders projectTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { TreeSelection selection = (TreeSelection) event.getSelection(); Object[] selectedElements = selection.toArray(); if (selectedElements != null && selectedElements.length > 0) { Object selectedElement = selectedElements[0]; // Tree is single selection if (selectedElement instanceof IResource) { currentlySelectedResource = (IResource) selectedElement; Button okButton = getButton(IDialogConstants.OK_ID); if (okButton != null) { okButton.setEnabled(true); } } } else { Button okButton = getButton(IDialogConstants.OK_ID); if (okButton != null) { okButton.setEnabled(false); } } } }); return area; }
From source file:org.activiti.designer.kickstart.eclipse.sync.SelectSyncLocationWizardPage.java
License:Apache License
@Override public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); container.setLayout(layout);//w w w . ja v a 2 s .c om layout.numColumns = 1; setControl(container); final TreeViewer repositoryTreeViewer = new TreeViewer(container, SWT.SINGLE); repositoryTreeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); repositoryTreeViewer.setContentProvider(new CmisContentProvider(".kickproc")); repositoryTreeViewer.setLabelProvider(new CmisLabelProvider()); repositoryTreeViewer.addDoubleClickListener(new OpenFolderOnDoubleClickListener()); repositoryTreeViewer.setInput(new Root()); repositoryTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { setPageComplete(false); if (event.getSelection() instanceof TreeSelection) { TreeSelection selection = (TreeSelection) event.getSelection(); Object[] selectedElements = selection.toArray(); if (selectedElements != null && selectedElements.length > 0 && selectedElements[0] instanceof CmisObject) { synchronizationDataHolder.setDestination((CmisObject) selectedElements[0]); // Only single select is allowed setPageComplete(true); } } } }); setPageComplete(false); }
From source file:org.adorsys.plh.pkix.workbench.navigator.internal.ResourceNavigator.java
License:Open Source License
@Inject public ResourceNavigator(Composite parent, final IEclipseContext context, IWorkspace workspace) { final Realm realm = SWTObservables.getRealm(parent.getDisplay()); this.context = context; parent.setLayout(new FillLayout()); TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection selection = (StructuredSelection) event.getSelection(); selectionService/* w w w. j a va 2 s. c om*/ .setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); // context.modify(IServiceConstants.ACTIVE_SELECTION, selection.size() == 1 ? selection.getFirstElement() : selection.toArray()); } }); IObservableFactory setFactory = new IObservableFactory() { public IObservable createObservable(Object element) { if (element instanceof IContainer && ((IContainer) element).exists()) { IObservableSet observableSet = observableSets.get(element); if (observableSet == null) { observableSet = new WritableSet(realm); try { observableSet.addAll(Arrays.asList(((IContainer) element).members())); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } observableSets.put((IContainer) element, observableSet); } return observableSet; } return Observables.emptyObservableSet(); } }; viewer.setContentProvider(new ObservableSetTreeContentProvider(setFactory, new TreeStructureAdvisor() { public Boolean hasChildren(Object element) { return Boolean.valueOf(element instanceof IContainer); } })); viewer.setLabelProvider(new LabelProvider() { public String getText(Object element) { if (element instanceof IResource) return ((IResource) element).getName(); return element == null ? "" : element.toString(); } }); viewer.setSorter(new ViewerSorter()); viewer.setInput(workspace.getRoot()); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); for (Object o : s.toArray()) { if (o instanceof IFile) { IFile f = (IFile) o; context.set(IFile.class, f); String fExt = f.getFileExtension(); EDITOR: for (MPartDescriptor desc : application.getDescriptors()) { String category = desc.getCategory(); if (category == null) continue; String[] categories = category.split(","); for (String ext : categories) { if (ext.equalsIgnoreCase(fExt)) { context.set(MPartDescriptor.class, desc); System.err.println("Opening with: " + desc); Command cmd = commandService.getCommand("desktop.command.openeditor"); ParameterizedCommand pCmd = ParameterizedCommand.generateCommand(cmd, null); handlerService.executeHandler(pCmd); break EDITOR; } } } } } } }); setupContextMenu(viewer, parent.getShell()); workspace.addResourceChangeListener(listener); }
From source file:org.amanzi.awe.ui.tree.view.AbstractAWETreeView.java
License:Open Source License
protected TreeViewer createTreeViewer(final Composite parent) { final TreeViewer treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL); treeViewer.setContentProvider(createContentProvider()); treeViewer.setLabelProvider(createLabelProvider()); treeViewer.setInput(ObjectUtils.NULL); parent.setLayout(new GridLayout(1, false)); treeViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); return treeViewer; }
From source file:org.antlr.eclipse.ui.editor.outline.AntlrOutlinePage.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w.ja v a 2 s .c o m public void createControl(final Composite aParent) { super.createControl(aParent); fLabelProvider = new AntlrOutlineLabelProvider(); // Init tree viewer TreeViewer viewer = getTreeViewer(); viewer.setContentProvider(new AntlrOutlineContentProvider(fEditor)); viewer.setLabelProvider(fLabelProvider); viewer.addSelectionChangedListener(this); if (fInput != null) { viewer.setInput(fInput); } fIsDisposed = false; // Add collapse all button to viewer's toolbar IToolBarManager mgr = getSite().getActionBars().getToolBarManager(); mgr.add(new CollapseAllAction(viewer)); mgr.add(new LexicalSortingAction(viewer)); // Refresh outline according to initial cursor position update(); }
From source file:org.apache.directory.studio.ldapbrowser.ui.editors.entry.EntryEditorOutlinePage.java
License:Apache License
/** * {@inheritDoc}/*w w w . j av a 2 s. c o m*/ */ public void createControl(Composite parent) { // Creating the composite and fake composite this.composite = new Composite(parent, SWT.NONE); composite.setLayout(new FillLayout()); this.fakeComposite = new Composite(parent, SWT.NONE); // Creating the No Outline composite noOutlineComposite = new Composite(composite, SWT.NONE); noOutlineComposite.setLayout(new FillLayout()); Label label = new Label(noOutlineComposite, SWT.WRAP); label.setText(Messages.getString("EntryEditorOutlinePage.NoOutline")); //$NON-NLS-1$ // Creating the Outline tree viewer super.createControl(parent); final TreeViewer treeViewer = getTreeViewer(); treeViewer.setLabelProvider(new EntryEditorOutlineLabelProvider()); treeViewer.setContentProvider(new EntryEditorOutlineContentProvider()); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) { if (getEntryEditorWidgetTreeViewerInput() != null) { List<Object> selectionList = new ArrayList<Object>(); for (Object element : ((IStructuredSelection) event.getSelection()).toArray()) { if (element instanceof IValue) { // select the value IValue value = (IValue) element; selectionList.add(value); } else if (element instanceof IAttribute) { // select attribute and all values IAttribute attribute = (IAttribute) element; selectionList.add(attribute); selectionList.addAll(Arrays.asList(attribute.getValues())); } else if (element instanceof EntryWrapper) { // select all attributes and values IEntry entry = ((EntryWrapper) element).entry; for (IAttribute attribute : entry.getAttributes()) { selectionList.add(attribute); selectionList.addAll(Arrays.asList(attribute.getValues())); } } } IStructuredSelection selection = new StructuredSelection(selectionList); TreeViewer entryEditorWidgetTreeViewer = getEntryEditorWidgetTreeViewer(); if (entryEditorWidgetTreeViewer != null) { entryEditorWidgetTreeViewer.setSelection(selection); } } } } }); treeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (event.getSelection() instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (treeViewer.getExpandedState(obj)) { treeViewer.collapseToLevel(obj, 1); } else if (((ITreeContentProvider) treeViewer.getContentProvider()).hasChildren(obj)) { treeViewer.expandToLevel(obj, 1); } } } }); this.refresh(); }
From source file:org.apache.directory.studio.ldifeditor.editor.LdifOutlinePage.java
License:Apache License
/** * {@inheritDoc}/* w w w. j a va2s .co m*/ */ public void createControl(Composite parent) { super.createControl(parent); final TreeViewer treeViewer = getTreeViewer(); treeViewer.setLabelProvider(new LdifLabelProvider(ldifEditor, isLinkedToLdapBrowser)); treeViewer.setContentProvider(new LdifContentProvider()); if (isLinkedToLdapBrowser) { treeViewer.setAutoExpandLevel(2); } treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty() && event.getSelection() instanceof IStructuredSelection) { Object element = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (element instanceof LdifRecord) { LdifRecord ldifRecord = (LdifRecord) element; ldifEditor.selectAndReveal(ldifRecord.getDnLine().getOffset(), ldifRecord.getDnLine().getLength()); } else if (element instanceof List) { List<?> list = (List<?>) element; if (!list.isEmpty() && list.get(0) instanceof LdifAttrValLine) { LdifAttrValLine line = (LdifAttrValLine) list.get(0); ldifEditor.selectAndReveal(line.getOffset(), line.getRawAttributeDescription().length()); } } else if (element instanceof LdifAttrValLine) { LdifAttrValLine line = (LdifAttrValLine) element; ldifEditor.selectAndReveal(line.getOffset() + line.getRawAttributeDescription().length() + line.getRawValueType().length(), line.getRawValue().length()); } else if (element instanceof LdifModSpec) { LdifModSpec modSpec = (LdifModSpec) element; ldifEditor.selectAndReveal(modSpec.getOffset(), modSpec.getModSpecType().getLength()); } } } }); treeViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { if (event.getSelection() instanceof IStructuredSelection) { Object obj = ((IStructuredSelection) event.getSelection()).getFirstElement(); if (treeViewer.getExpandedState(obj)) treeViewer.collapseToLevel(obj, 1); else if (((ITreeContentProvider) treeViewer.getContentProvider()).hasChildren(obj)) treeViewer.expandToLevel(obj, 1); } } }); this.refresh(); }
From source file:org.apache.easyant4e.ivyde.extension.page.BuildLifecycleBlock.java
License:Apache License
protected void createBuildLifecyclePart(final IManagedForm managedForm, final Composite parent) { FormToolkit toolkit = managedForm.getToolkit(); Section section = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR); section.setText("Build Lifecycle"); section.setDescription("The build lifecycle has the following build phases:"); section.marginWidth = 10;/* ww w .j av a 2 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); toolkit.paintBordersFor(client); section.setClient(client); final SectionPart spart = new SectionPart(section); managedForm.addPart(spart); TreeViewer viewer = new TreeViewer(client); GridData gd = new GridData(GridData.FILL_BOTH); gd.heightHint = 20; gd.widthHint = 100; viewer.getTree().setLayoutData(gd); viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { managedForm.fireSelectionChanged(spart, event.getSelection()); } }); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (!structuredSelection.isEmpty()) { Object o = structuredSelection.getFirstElement(); if (o instanceof PhaseReport) { runPhase((PhaseReport) o); } else if (o instanceof TargetReport) { runTarget((TargetReport) o); } } } } }); viewer.setContentProvider(buildLifeCycleContentProvider); viewer.setLabelProvider(buildLifecycleLabelProvider); viewer.setInput(page.getEditor().getEditorInput()); // viewer.expandAll(); }
From source file:org.axdt.swc.ui.SwcEditorView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { Composite base = new Composite(parent, SWT.NONE); base.setLayout(new FillLayout()); TreeViewer treeViewer = new TreeViewer(base); treeViewer.setLabelProvider(new SwcLabelProvider()); treeViewer.setContentProvider(new SwcContentProvider()); IEditorInput input = getEditorInput(); SwcInfo info = new SwcInfo(); if (input instanceof IFileEditorInput) { IFileEditorInput fileInput = (IFileEditorInput) input; info.readFile(fileInput.getFile()); }//w w w .j a va 2 s . c om treeViewer.setInput(info.getModel()); treeViewer.expandToLevel(3); }
From source file:org.bbaw.bts.ui.main.test.Snippet047VirtualLazyTreeViewer.java
License:Open Source License
public Snippet047VirtualLazyTreeViewer(Shell shell) { final TreeViewer v = new TreeViewer(shell, SWT.VIRTUAL | SWT.BORDER); v.setLabelProvider(new LabelProvider()); v.setContentProvider(new MyContentProvider(v)); v.setUseHashlookup(true);//from www . j a v a 2 s . c om IntermediateNode[] model = createModel(); v.setInput(model); v.getTree().setItemCount(model.length); }