Java Code Examples for org.eclipse.jface.viewers.TreeViewer#getSelection()
The following examples show how to use
org.eclipse.jface.viewers.TreeViewer#getSelection() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptViewContextMenuProvider.java From birt with Eclipse Public License 1.0 | 6 votes |
public void buildContextMenu( IMenuManager menu ) { menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); TreeViewer treeViewer = (TreeViewer) getViewer( ); IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection( ); //temporary solution if ( selection.size( ) == 1 ) { Object obj = selection.getFirstElement( ); ScriptProviderFactory.createProvider( obj ) .createContextMenu( treeViewer, obj, menu ); } else { ScriptProviderFactory.getDefaultProvider( ) .createContextMenu( treeViewer, selection, menu ); } }
Example 2
Source File: AbstractOutlineWorkbenchTest.java From xsemantics with Eclipse Public License 1.0 | 6 votes |
protected void assertSelected(TreeViewer treeViewer, IOutlineNode... expectedSelection) { ISelection selection = treeViewer.getSelection(); assertTrue(selection instanceof IStructuredSelection); assertEquals(expectedSelection.length, ((IStructuredSelection) selection).size()); OUTER: for (Iterator<?> i = ((IStructuredSelection) selection) .iterator(); i.hasNext();) { Object selectedObject = i.next(); assertTrue(selectedObject instanceof IOutlineNode); for (IOutlineNode expectedSelected : expectedSelection) { if (nodeComparer.equals((IOutlineNode) selectedObject, expectedSelected)) continue OUTER; } fail("Unexpected selection " + selectedObject.toString()); } }
Example 3
Source File: XViewerCustomizeDialog.java From nebula with Eclipse Public License 2.0 | 5 votes |
private List<XViewerColumn> getTableSelection(TreeViewer xColTableViewer) { List<XViewerColumn> xCols = new ArrayList<>(); IStructuredSelection selection = (IStructuredSelection) xColTableViewer.getSelection(); if (selection.isEmpty()) { return null; } Iterator<?> i = selection.iterator(); while (i.hasNext()) { xCols.add((XViewerColumn) i.next()); } return xCols; }
Example 4
Source File: AbstractOutlineWorkbenchTest.java From n4js with Eclipse Public License 1.0 | 5 votes |
protected void assertSelected(TreeViewer aTreeViewer, IOutlineNode... expectedSelection) { ISelection selection = aTreeViewer.getSelection(); assertTrue(selection instanceof IStructuredSelection); assertEquals(expectedSelection.length, ((IStructuredSelection) selection).size()); OUTER: for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { Object selectedObject = i.next(); assertTrue(selectedObject instanceof IOutlineNode); for (IOutlineNode expectedSelected : expectedSelection) { if (nodeComparer.equals((IOutlineNode) selectedObject, expectedSelected)) continue OUTER; } fail("Unexpected selection " + selectedObject.toString()); } }
Example 5
Source File: AbstractOutlineWorkbenchTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void assertSelected(TreeViewer treeViewer, IOutlineNode... expectedSelection) { ISelection selection = treeViewer.getSelection(); assertTrue(selection instanceof IStructuredSelection); assertEquals(expectedSelection.length, ((IStructuredSelection) selection).size()); OUTER: for (Iterator<?> i = ((IStructuredSelection) selection).iterator(); i.hasNext();) { Object selectedObject = i.next(); assertTrue(selectedObject instanceof IOutlineNode); for (IOutlineNode expectedSelected : expectedSelection) { if (nodeComparer.equals((IOutlineNode) selectedObject, expectedSelected)) continue OUTER; } fail("Unexpected selection " + selectedObject.toString()); } }
Example 6
Source File: BlockSelector.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public void selectionChanged(SelectionChangedEvent event){ TreeViewer tv = (TreeViewer) event.getSource(); StructuredSelection ss = (StructuredSelection) tv.getSelection(); Object selected = null; Object firstElement = ss.isEmpty() ? null : ss.getFirstElement(); if (firstElement instanceof BlockTreeViewerItem) { selected = ((BlockTreeViewerItem) firstElement).getBlock(); } tvfa.updateSelection((Identifiable) selected); if (selected != null) { ContextServiceHolder.get().getRootContext().setTyped(selected); } }
Example 7
Source File: EigenartikelSelector.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override public void selectionChanged(SelectionChangedEvent event){ TreeViewer tv = (TreeViewer) event.getSource(); StructuredSelection ss = (StructuredSelection) tv.getSelection(); tvfa.updateSelection(ss.isEmpty() ? null : ss.getFirstElement()); if (!ss.isEmpty()) { IArticle ea = (IArticle) ss.getFirstElement(); ContextServiceHolder.get().getRootContext() .setNamed("ch.elexis.core.ui.eigenartikel.selection", ea); } else { ContextServiceHolder.get().getRootContext() .setNamed("ch.elexis.core.ui.eigenartikel.selection", null); } }
Example 8
Source File: ViewContextMenuProvider.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Builds the context menu. Single selection menu and multiple selection * menu are created while selecting just single element or multiple elements * * * @param menu * the menu */ public void buildContextMenu( IMenuManager menu ) { menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); TreeViewer treeViewer = (TreeViewer) getViewer( ); IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection( ); // temporary solution Object input = treeViewer.getInput( ); if ( input instanceof Object[] ) { Object[] inputs = (Object[]) input; if ( inputs.length == 1 && inputs[0] instanceof ReportDesignHandle ) { for ( Iterator iter = selection.iterator( ); iter.hasNext( ); ) { if ( isIncludedLibrary( iter.next( ) ) ) { return; } } } } if ( selection.size( ) == 1 ) { // Create Single Selection Menu Object obj = selection.getFirstElement( ); if ( ProviderFactory.createProvider( obj ) != null ) { ProviderFactory.createProvider( obj ) .createContextMenu( treeViewer, obj, menu ); } if ( Policy.TRACING_MENU_SHOW ) { System.out.println( "Menu(for Views) >> Shows for " + ProviderFactory.createProvider( obj ).getNodeDisplayName( obj ) ); //$NON-NLS-1$ } } else { // Added by ywang on 2004.9.15 // Create Multiple Selection Menu if ( ProviderFactory.getDefaultProvider( ) != null) { ProviderFactory.getDefaultProvider( ) .createContextMenu( treeViewer, selection, menu ); } if ( Policy.TRACING_MENU_SHOW ) { System.out.println( "Menu(for Views) >> Shows for multi-selcetion." ); //$NON-NLS-1$ } } }