List of usage examples for org.eclipse.jface.viewers TreeViewer setSelection
@Override public void setSelection(ISelection selection, boolean reveal)
From source file:org.eclipse.e4.xwt.tools.ui.designer.databinding.ui.ObserveModelGroup.java
License:Open Source License
protected void selectAndReveal(PropertyChangeEvent evt) { Object newValue = evt.getNewValue(); if ("model".equals(evt.getPropertyName())) { TreeViewer treeViewer = observableList.getTreeViewer(); treeViewer.setSelection(createSelection(newValue), true); } else if ("modelProperty".equals(evt.getPropertyName())) { propertiesTree.setSelection(createSelection(newValue), true); }/*from ww w . ja v a 2 s. c o m*/ }
From source file:org.eclipse.e4.xwt.tools.ui.designer.databinding.ui.ObserveTargetGroup.java
License:Open Source License
protected void selectAndReveal(PropertyChangeEvent evt) { Object newValue = evt.getNewValue(); if ("target".equals(evt.getPropertyName())) { TreeViewer treeViewer = observableList.getTreeViewer(); treeViewer.setExpandedElements(new Object[] { newValue }); treeViewer.setSelection(createSelection(newValue), true); } else if ("targetProperty".equals(evt.getPropertyName())) { propertiesTree.setSelection(createSelection(newValue), true); }//from w w w . j a v a 2 s.c o m }
From source file:org.eclipse.emf.cdo.dawn.ecoretools.diagram.part.DawnEcoreCreationWizardPage.java
License:Open Source License
@Override protected boolean loadModelFile() { if (semanticModelURI == null) { return false; }//from ww w . j a v a2s . com Resource resource = getResourceSet().getResource(semanticModelURI, true); if (resource != null) { ComposedAdapterFactory adapterFactory = getAdapterFactory(); TreeViewer viewer = (TreeViewer) getField("viewer"); // Set the tree providers of the domain file contents AdapterFactoryContentProvider adapterContentProvider = new AdapterFactoryContentProvider( adapterFactory); adapterContentProvider.inputChanged(viewer, null, null); viewer.setContentProvider(new WizardContentProvider(adapterContentProvider)); viewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); viewer.setInput(resource.getContents()); viewer.refresh(); viewer.setSelection(new StructuredSelection(resource.getContents()), true); return true; } return false; }
From source file:org.eclipse.emf.eef.runtime.impl.utils.ModelViewerHelper.java
License:Open Source License
/** * Sets the selected existing container. * // www .j a v a 2s . c om * @param container */ public static void setSelectedElement(TreeViewer treeViewer, IResource resource) { // expand to and select the specified container List<IContainer> itemsToExpand = new ArrayList<IContainer>(); IContainer parent = resource.getParent(); while (parent != null) { itemsToExpand.add(0, parent); parent = parent.getParent(); } treeViewer.setExpandedElements(itemsToExpand.toArray()); treeViewer.setSelection(new StructuredSelection(resource), true); }
From source file:org.eclipse.emfforms.spi.swt.treemasterdetail.TreeViewerSWTBuilder.java
License:Open Source License
/** * Creates a {@link TreeViewer}./*from w w w. ja v a 2 s . c o m*/ * * @param behaviour the {@link TreeViewerCustomization} * @param composite the parent {@link Composite} * @param editingDomain the {@link EditingDomain} * @param input the input * @return the viewer */ static TreeViewer create(TreeViewerCustomization behaviour, Composite composite, EditingDomain editingDomain, Object input) { final TreeViewer treeViewer = behaviour.createTree(composite); GridDataFactory.fillDefaults().grab(true, true).applyTo(treeViewer.getControl()); if (behaviour.hasDND()) { treeViewer.addDragSupport(behaviour.getDragOperations(), behaviour.getDragTransferTypes(), behaviour.getDragListener(treeViewer)); treeViewer.addDropSupport(behaviour.getDropOperations(), behaviour.getDropTransferTypes(), behaviour.getDropListener(editingDomain, treeViewer)); } treeViewer.setContentProvider(behaviour.getContentProvider()); treeViewer.setLabelProvider(behaviour.getLabelProvider()); treeViewer.setFilters(behaviour.getViewerFilters()); treeViewer.getControl().setMenu(behaviour.getMenu(treeViewer, editingDomain)); treeViewer.setInput(input); final EObject initialSelection = behaviour.getInitialSelection(input); if (initialSelection != null) { treeViewer.setSelection(new StructuredSelection(initialSelection), true); } return treeViewer; }
From source file:org.eclipse.jubula.client.ui.rcp.businessprocess.UINodeBP.java
License:Open Source License
/** * sets the given selection in the given TreeViewer and also gives the given * tree viewer focus//from www. j a v a 2 s. c o m * * @param sel * the selection to set * @param tv * the tree viewer to use */ public static void setFocusAndSelection(ISelection sel, TreeViewer tv) { tv.getTree().setFocus(); tv.setSelection(sel, true); }
From source file:org.eclipse.lsp4e.outline.CNFOutlinePage.java
License:Open Source License
public static void refreshTreeSelection(TreeViewer viewer, int offset, IDocument document) { ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider(); Object[] objects = contentProvider.getElements(null); SymbolInformation bestSymbol = null; int level = 0; while (objects != null && objects.length > 0) { SymbolInformation nextChild = null; for (Object object : objects) { SymbolInformation symbol = object instanceof SymbolInformation ? (SymbolInformation) object : Adapters.adapt(object, SymbolInformation.class); if (symbol != null) { if (isOffsetInSymbolRange(offset, symbol, document)) { nextChild = symbol;//from w w w . j a v a2 s .co m objects = contentProvider.getChildren(symbol); break; } } } if (nextChild == null) break; level++; bestSymbol = nextChild; } if (bestSymbol != null) { if (bestSymbol.equals(viewer.getStructuredSelection().getFirstElement())) { // the symbol to select is the same than current selected symbol, don't select // it. return; } final int finalLevel = level; final SymbolInformation finalBestSymbol = bestSymbol; Display.getDefault().asyncExec(() -> { viewer.expandToLevel(finalLevel); viewer.setSelection(new StructuredSelection(finalBestSymbol), true); }); } }
From source file:org.eclipse.mylyn.internal.bugzilla.ui.wizard.BugzillaProductPage.java
License:Open Source License
@SuppressWarnings("deprecation") public void createControl(Composite parent) { // create the composite to hold the widgets Composite composite = new Composite(parent, SWT.NULL); // create the desired layout for this wizard page composite.setLayout(new GridLayout()); // create the list of bug reports // TODO e3.5 move to new FilteredTree API productList = new FilteredTree(composite, SWT.SINGLE | SWT.BORDER, new ComponentFilter()); productList.setLayoutData(GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true) .hint(SWT.DEFAULT, 200).create()); final TreeViewer productViewer = productList.getViewer(); productViewer.setLabelProvider(new LabelProvider()); productViewer.setContentProvider(new ITreeContentProvider() { public Object[] getChildren(Object parentElement) { if (parentElement instanceof Collection<?>) { return ((Collection<?>) parentElement).toArray(); }//from w w w.ja v a 2 s .com return null; } public Object getParent(Object element) { return null; } public boolean hasChildren(Object element) { return false; } public Object[] getElements(Object inputElement) { return getChildren(inputElement); } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); productViewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { if (getWizard().canFinish()) { if (getWizard().performFinish()) { ((WizardDialog) getContainer()).close(); } } } }); initProducts(); productViewer.setInput(products); productViewer.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // Initialize a variable with the no error status Status status = new Status(IStatus.OK, BugzillaUiPlugin.ID_PLUGIN, 0, "", null); //$NON-NLS-1$ if (productViewer.getSelection().isEmpty()) { status = new Status(IStatus.ERROR, BugzillaUiPlugin.ID_PLUGIN, 0, Messages.BugzillaProductPage_YOU_MUST_SELECT_PRODUCT, null); } // Show the most serious error applyToStatusLine(status); isPageComplete(); getWizard().getContainer().updateButtons(); } }); // HACK: waiting on delayed refresh of filtered tree final String[] selectedProducts = getSelectedProducts(); if (selectedProducts.length > 0) { new UIJob("") { //$NON-NLS-1$ @Override public IStatus runInUIThread(IProgressMonitor monitor) { if (BugzillaProductPage.this.getControl() != null && BugzillaProductPage.this.getControl().isDisposed()) { return Status.OK_STATUS; } productViewer.setSelection(new StructuredSelection(selectedProducts), true); productViewer.getControl().setFocus(); return Status.OK_STATUS; } }.schedule(300L); } else { productList.setFocus(); } Button updateButton = new Button(composite, SWT.LEFT | SWT.PUSH); updateButton.setText(LABEL_UPDATE); updateButton.setLayoutData(new GridData()); updateButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateProdcts(); productViewer.setInput(products); } }); Dialog.applyDialogFont(composite); // set the composite as the control for this page setControl(composite); isPageComplete(); getWizard().getContainer().updateButtons(); }
From source file:org.eclipse.mylyn.internal.java.PackageExplorerManager.java
License:Open Source License
public void selectionChanged(IWorkbenchPart part, ISelection changedSelection) { if (!(part instanceof PackageExplorerPart)) { return;/*from w w w . j a va2s . c o m*/ } AbstractFocusViewAction applyAction = AbstractFocusViewAction.getActionForPart((PackageExplorerPart) part); if (!ContextCorePlugin.getContextManager().isContextActive() || (applyAction != null && !applyAction.isChecked())) { return; } try { Object elementToSelect = null; if (changedSelection instanceof TextSelection && part instanceof JavaEditor) { TextSelection textSelection = (TextSelection) changedSelection; IJavaElement javaElement = SelectionConverter.resolveEnclosingElement((JavaEditor) part, textSelection); if (javaElement != null) elementToSelect = javaElement; } else if (changedSelection instanceof TextSelection) { // if (part instanceof EditorPart) { // elementToSelect = ((EditorPart) part).getEditorInput().getAdapter(IResource.class); // } } else { return; } if (elementToSelect != null) { PackageExplorerPart packageExplorer = PackageExplorerPart.getFromActivePerspective(); if (packageExplorer != null) { TreeViewer viewer = packageExplorer.getTreeViewer(); StructuredSelection currentSelection = (StructuredSelection) viewer.getSelection(); if (currentSelection.size() <= 1) { boolean membersFilteredMode = false; for (ViewerFilter filter : Arrays.asList(viewer.getFilters())) { if (filter instanceof JavaDeclarationsFilter) membersFilteredMode = true; } if (membersFilteredMode) { if (elementToSelect instanceof IMember) { ICompilationUnit toSelect = ((IMember) elementToSelect).getCompilationUnit(); if (toSelect != null) { viewer.setSelection(new StructuredSelection(toSelect), true); } } } else if (elementToSelect != null) { if (!elementToSelect.equals(currentSelection.getFirstElement())) { viewer.setSelection(new StructuredSelection(elementToSelect), true); } } } // if (elementToSelect != null // && MylarJavaPlugin.getDefault().getPluginPreferences().getBoolean( // MylarJavaPrefConstants.PACKAGE_EXPLORER_AUTO_EXPAND)) { // viewer.expandAll(); // } } } } catch (Throwable t) { MylarStatusHandler.log(t, "Could not update package explorer"); } }
From source file:org.eclipse.mylyn.internal.tasks.ui.commands.GoToUnreadTaskHandler.java
License:Open Source License
@Override protected void execute(ExecutionEvent event, TaskListView taskListView, IRepositoryElement item) { TreeViewer treeViewer = taskListView.getViewer(); Tree tree = treeViewer.getTree();/*from ww w . ja v a2 s. c o m*/ // need to expand nodes to traverse the tree, disable redraw to avoid flickering TreePath treePath = null; try { tree.setRedraw(false); treePath = getUnreadItem(treeViewer, tree); } finally { tree.setRedraw(true); } if (treePath != null) { treeViewer.expandToLevel(treePath, 0); treeViewer.setSelection(new TreeSelection(treePath), true); } }