List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.aptana.ide.debug.internal.ui.preferences.JSDetailFormattersPreferencePage.java
License:Open Source License
private void updatePage(IStructuredSelection selection) { removeFormatterButton.setEnabled(!selection.isEmpty()); editFormatterButton.setEnabled(selection.size() == 1); sourceViewer.getDocument()//w w w. j av a 2s. c om .set(selection.size() == 1 ? ((DetailFormatter) selection.getFirstElement()).getSnippet() : StringUtils.EMPTY); }
From source file:com.aptana.ide.editors.wizards.SimpleNewWizardPage.java
License:Open Source License
/** * Tests if the current workbench selection is a suitable container to use. *//*from w ww .jav a 2 s . c om*/ private void initialize() { if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) { IStructuredSelection ssel = (IStructuredSelection) selection; if (ssel.size() > 1) { return; } Object obj = ssel.getFirstElement(); if (!(obj instanceof IResource) && (obj instanceof IAdaptable)) { IAdaptable adaptable = (IAdaptable) obj; Object resource = adaptable.getAdapter(IResource.class); if (resource != null) { obj = resource; } } if (obj instanceof IResource) { IContainer container; if (obj instanceof IContainer) { container = (IContainer) obj; } else { container = ((IResource) obj).getParent(); } containerText.setText(container.getFullPath().toString()); } } if (defaultFileName != null) { fileText.setText(defaultFileName); } }
From source file:com.aptana.ide.search.epl.ResourceTransferDragAdapter.java
License:Open Source License
private List convertSelection() { ISelection s = fProvider.getSelection(); if (!(s instanceof IStructuredSelection)) return Collections.EMPTY_LIST; IStructuredSelection selection = (IStructuredSelection) s; List result = new ArrayList(selection.size()); for (Iterator iter = selection.iterator(); iter.hasNext();) { Object element = iter.next(); if (element instanceof IResource) { result.add(element);//from w w w . ja va 2 s .c om } } return result; }
From source file:com.aptana.ide.ui.io.IOUIPlugin.java
License:Open Source License
private void handleProjectExplorerListeners(final IWorkbenchPart part) { CommonViewer viewer = ((ProjectExplorer) part).getCommonViewer(); viewer.setComparer(new FileSystemElementComparer()); final Tree tree = viewer.getTree(); viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); Object element = selection.getFirstElement(); if (selection.size() == 1 && (element instanceof IResource) && ((IResource) element).getType() == IResource.PROJECT) { OpenResourceAction openResourceAction = new OpenResourceAction( PlatformUI.getWorkbench().getActiveWorkbenchWindow()); openResourceAction.selectionChanged((IStructuredSelection) event.getViewer().getSelection()); if (openResourceAction.isEnabled()) { openResourceAction.run(); }/* w ww . j a va 2 s. c o m*/ } } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { if (tree.getItem(new Point(e.x, e.y)) == null) { tree.deselectAll(); tree.notifyListeners(SWT.Selection, new Event()); } } }); }
From source file:com.aptana.ide.ui.io.navigator.actions.OpenActionProvider.java
License:Open Source License
private void addOpenWithMenu(IMenuManager menu) { IStructuredSelection selection = getSelection(); if (selection == null || selection.size() != 1) { return;/*from www. j a v a 2s . co m*/ } Object element = selection.getFirstElement(); if (!(element instanceof IAdaptable)) { return; } IMenuManager submenu = new MenuManager(Messages.OpenActionProvider_LBL_OpenWith, ICommonMenuConstants.GROUP_OPEN_WITH); submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP)); submenu.add(new OpenWithMenu(fSite.getPage(), (IAdaptable) element, new Client() { public void openEditor(IFileStore file, IEditorDescriptor editorDescriptor) { EditorUtils.openFileInEditor(file, editorDescriptor); } })); submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS)); // adds the submenu if (submenu.getItems().length > 2 && submenu.isEnabled()) { menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu); } }
From source file:com.aptana.ide.views.outline.UnifiedOutlinePage.java
License:Open Source License
/** * createTreeViewer//from w w w. jav a2 s. c o m * * @param parent * @return TreeViewer */ private TreeViewer createTreeViewer(Composite parent, PatternFilter filter) { FilteredTree tree = null; try { // When available (3.5+) use new constructor Constructor<FilteredTree> cons = FilteredTree.class.getConstructor(Composite.class, int.class, PatternFilter.class, boolean.class); tree = cons.newInstance(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, filter, true); } catch (Exception e) { // fallback to deprecated old constructor when new one not available tree = new FilteredTree(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, filter); } TreeViewer result = tree.getViewer(); outlineProvider = UnifiedOutlineProvider.getInstance(); outlineProvider.setOutlinePage(this); result.setLabelProvider(outlineProvider); result.setContentProvider(outlineProvider); result.setInput(this._editor); // add selection changed listener result.addSelectionChangedListener(new ISelectionChangedListener() { /** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() == 1) { Object item = selection.getFirstElement(); if (item != null && item instanceof OutlineItem) { OutlineItem outlineItem = (OutlineItem) selection.getFirstElement(); // Only select and reveal in editor if the tree viewer is focused meaning the selection // originated from a user selection on the tree itself // move cursor to start of this item's text if (_treeViewer != null && _treeViewer.getTree() != null && !_treeViewer.getTree().isDisposed() && _treeViewer.getTree().isFocusControl()) { _editor.selectAndReveal(outlineItem.getStartingOffset(), 0); } // TODO: activate the editor window // Note this code works, but should only be called on mouse clicks so users can // navigate through outline items using the keyboard // IWorkbenchWindow window = JSPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); // // if (window != null) // { // IWorkbenchPage page = window.getActivePage(); // // page.activate(_editor); // } } } } }); result.setComparer(new IElementComparer() { /** * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, java.lang.Object) */ public boolean equals(Object a, Object b) { boolean result = false; if (a instanceof OutlineItem && b instanceof OutlineItem) { OutlineItem item1 = (OutlineItem) a; OutlineItem item2 = (OutlineItem) b; result = item1.equals(item2); } else if (a instanceof IParseNode && b instanceof IParseNode) { if (a == b) { result = true; } else { IParseNode node1 = (IParseNode) a; IParseNode node2 = (IParseNode) b; String path1 = node1.getUniquePath(); String path2 = node2.getUniquePath(); result = path1.equals(path2); } } else { result = (a == b); } return result; } /** * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object) */ public int hashCode(Object element) { return 0; } }); return result; }
From source file:com.aptana.ide.views.outline.UnifiedOutlinePage.java
License:Open Source License
/** * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) *///from ww w . java 2s . co m public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); // If a node in the outline view is selected if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element instanceof IResolvableItem) { IResolvableItem item = (IResolvableItem) element; // if item is resolvable and is targeting on external content if (item.isResolvable()) { // removing all item if needed if (openAction != null) { _actionBars.getToolBarManager().remove(openAction); } openAction = new ActionContributionItem(new OpenExternalAction(item)); _actionBars.getToolBarManager().add(openAction); _actionBars.getToolBarManager().update(false); // while item is not able to be resolved in current file // getting parent item while (!item.stillHighlight()) { item = item.getParentItem(); if (item == null) { return; } } // selecting it in editor if (item instanceof IParseNode) { int position = ((IParseNode) item).getStartingOffset(); this._editor.selectAndReveal(position, 0); return; } } else { // removing item from toolbar removeOpenActionIfNeeded(); } } removeOpenActionIfNeeded(); if (element instanceof IRange) { int position = ((IRange) element).getStartingOffset(); this._editor.selectAndReveal(position, 0); } } else { removeOpenActionIfNeeded(); this._editor.getViewer().removeRangeIndication(); } }
From source file:com.aptana.ide.views.outline.UnifiedQuickOutlinePage.java
License:Open Source License
/** * {@inheritDoc}/*from w ww.j a va 2s . c o m*/ */ public void open(OpenEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); // If a node in the outline view is selected if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element instanceof IResolvableItem) { IResolvableItem item = (IResolvableItem) element; // if item is resolvable and is targeting on external content if (item.isResolvable()) { // selecting it in editor if (item instanceof IParseNode) { int position = ((IParseNode) item).getStartingOffset(); this._editor.selectAndReveal(position, 0); return; } } else { if (item instanceof OutlineItem) { OutlineItem outlineItem = (OutlineItem) selection.getFirstElement(); // Only select and reveal in editor if the tree viewer is focused meaning the selection // originated from a user selection on the tree itself // move cursor to start of this item's text if (_treeViewer != null && _treeViewer.getTree() != null && !_treeViewer.getTree().isDisposed() && _treeViewer.getTree().isFocusControl()) { _editor.selectAndReveal(outlineItem.getStartingOffset(), 0); } } } } if (element instanceof IRange) { int position = ((IRange) element).getStartingOffset(); this._editor.selectAndReveal(position, 0); } notifyCloseListeners(); } else { removeOpenActionIfNeeded(); this._editor.getViewer().removeRangeIndication(); } }
From source file:com.aptana.ide.views.outline.UnifiedQuickOutlinePage.java
License:Open Source License
/** * {@inheritDoc}/*from w w w .j a v a 2 s . c o m*/ */ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (openAction != null) { _toolbarManager.remove(openAction); _toolbarManager.update(true); _toolbarManager.getControl().getParent().layout(true, true); } // If a node in the outline view is selected if (selection.size() == 1) { Object element = selection.getFirstElement(); if (element instanceof IResolvableItem) { IResolvableItem item = (IResolvableItem) element; // if item is resolvable and is targeting on external content // removing all item if needed if (item.isResolvable()) { openAction = new ActionContributionItem(new OpenExternalAction(item)); _toolbarManager.add(openAction); _toolbarManager.update(true); _toolbarManager.getControl().getParent().layout(true, true); // while item is not able to be resolved in current file // getting parent item while (!item.stillHighlight()) { item = item.getParentItem(); if (item == null) { return; } } // selecting it in editor if (item instanceof IParseNode) { int position = ((IParseNode) item).getStartingOffset(); this._editor.selectAndReveal(position, 0); return; } } else { // removing item from toolbar removeOpenActionIfNeeded(); } } removeOpenActionIfNeeded(); } else { removeOpenActionIfNeeded(); this._editor.getViewer().removeRangeIndication(); } }
From source file:com.aptana.ide.xul.FirefoxOutline.java
License:Open Source License
/** * @see com.aptana.ide.editors.unified.ContributedOutline#createControl(org.eclipse.swt.widgets.Composite) *//*from ww w.j av a 2 s.c o m*/ public void createControl(Composite parent) { treeViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); treeViewer.getTree().setLayout(new GridLayout(1, true)); treeViewer.setLabelProvider(new DOMLabelProvider()); treeViewer.setAutoExpandLevel(3); treeViewer.setContentProvider(new DOMContentProvider()); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() == 1) { nsIDOMNode node = (nsIDOMNode) selection.getFirstElement(); browser.highlightElement(node); } } }); treeViewer.addFilter(new InternalNodeFilter()); filter = new PatternFilter() { protected boolean isLeafMatch(Viewer viewer, Object element) { if (element instanceof nsIDOMNode) { if (((nsIDOMNode) element).getNodeType() == nsIDOMNode.ELEMENT_NODE) { nsIDOMElement e = (nsIDOMElement) ((nsIDOMNode) element) .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID); if (Activator.INTERNAL_ID.equals(e.getAttribute("class"))) //$NON-NLS-1$ { return false; } } DOMLabelProvider prov = (DOMLabelProvider) treeViewer.getLabelProvider(); return this.wordMatches(prov.getText(element)); } return true; } }; treeViewer.addFilter(filter); refreshJob = new WorkbenchJob("Refresh Filter") {//$NON-NLS-1$ /* * (non-Javadoc) * * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) */ public IStatus runInUIThread(IProgressMonitor monitor) { if (treeViewer.getControl().isDisposed()) { return Status.CANCEL_STATUS; } if (pattern == null) { return Status.OK_STATUS; } filter.setPattern(pattern); try { // don't want the user to see updates that will be made to the tree treeViewer.getControl().setRedraw(false); treeViewer.refresh(true); if (pattern.length() > 0) { /* * Expand elements one at a time. After each is expanded, check to see if the filter text has * been modified. If it has, then cancel the refresh job so the user doesn't have to endure * expansion of all the nodes. */ IStructuredContentProvider provider = (IStructuredContentProvider) treeViewer .getContentProvider(); Object[] elements = provider.getElements(treeViewer.getInput()); for (int i = 0; i < elements.length; i++) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } treeViewer.expandToLevel(elements[i], AbstractTreeViewer.ALL_LEVELS); } TreeItem[] items = treeViewer.getTree().getItems(); if (items.length > 0) { // to prevent scrolling treeViewer.getTree().showItem(items[0]); } } } finally { // done updating the tree - set redraw back to true treeViewer.getControl().setRedraw(true); } return Status.OK_STATUS; } }; TreeItem item = new TreeItem(treeViewer.getTree(), SWT.NONE); item.setText(Messages.getString("FirefoxOutline.Select_Tab_To_Load_Outline")); //$NON-NLS-1$ refreshJob.setSystem(true); refresh(); }