List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.google.dart.tools.ui.internal.actions.AddTaskAction.java
License:Open Source License
private IResource getElement(IStructuredSelection selection) { if (selection.size() != 1) { return null; }//from w w w . j a v a2s .c om Object element = selection.getFirstElement(); if (!(element instanceof IAdaptable)) { return null; } return (IResource) ((IAdaptable) element).getAdapter(IResource.class); }
From source file:com.google.dart.tools.ui.internal.actions.SelectionConverter.java
License:Open Source License
/** * Converts the given structured selection into an array of Java elements. An empty array is * returned if one of the elements stored in the structured selection is not of type * <code>DartElement</code>//from w w w .j a v a2s .com */ public static DartElement[] getElements(IStructuredSelection selection) { if (!selection.isEmpty()) { DartElement[] result = new DartElement[selection.size()]; int i = 0; for (Iterator<?> iter = selection.iterator(); iter.hasNext(); i++) { Object element = iter.next(); if (!(element instanceof DartElement)) { return EMPTY_RESULT; } result[i] = (DartElement) element; } return result; } return EMPTY_RESULT; }
From source file:com.google.dart.tools.ui.internal.dialogs.TableTextCellEditor.java
License:Open Source License
@Override protected Control createControl(Composite parent) { // workaround for bug 58777: don't accept focus listeners on the text // control/*from ww w . j a va2 s .c o m*/ final Control[] textControl = new Control[1]; Composite result = new Composite(parent, SWT.NONE) { @Override public void addListener(int eventType, final Listener listener) { if (eventType != SWT.FocusIn && eventType != SWT.FocusOut) { textControl[0].addListener(eventType, listener); } } }; result.setFont(parent.getFont()); result.setBackground(parent.getBackground()); result.setLayout(new FillLayout()); text = new Text(result, getStyle()); textControl[0] = text; text.addSelectionListener(new SelectionAdapter() { @Override public void widgetDefaultSelected(SelectionEvent e) { handleDefaultSelection(e); } }); text.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { // support switching rows while editing: if (e.stateMask == SWT.MOD1 || e.stateMask == SWT.MOD2) { if (e.keyCode == SWT.ARROW_UP || e.keyCode == SWT.ARROW_DOWN) { // allow starting multi-selection even if in edit mode deactivate(); e.doit = false; return; } } if (e.stateMask != SWT.NONE) { return; } switch (e.keyCode) { case SWT.ARROW_DOWN: e.doit = false; int nextRow = fTableViewer.getTable().getSelectionIndex() + 1; if (nextRow >= fTableViewer.getTable().getItemCount()) { break; } editRow(nextRow); break; case SWT.ARROW_UP: e.doit = false; int prevRow = fTableViewer.getTable().getSelectionIndex() - 1; if (prevRow < 0) { break; } editRow(prevRow); break; case SWT.F2: e.doit = false; deactivate(); break; } } private void editRow(int row) { fTableViewer.getTable().setSelection(row); IStructuredSelection newSelection = (IStructuredSelection) fTableViewer.getSelection(); if (newSelection.size() == 1) { fTableViewer.editElement(newSelection.getFirstElement(), fColumn); } } }); text.addKeyListener(new KeyAdapter() { // hook key pressed - see PR 14201 @Override public void keyPressed(KeyEvent e) { keyReleaseOccured(e); // as a result of processing the above call, clients may have // disposed this cell editor if ((getControl() == null) || getControl().isDisposed()) { return; } checkSelection(); // see explaination below checkDeleteable(); checkSelectable(); } }); text.addTraverseListener(new TraverseListener() { @Override public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_ESCAPE || e.detail == SWT.TRAVERSE_RETURN) { e.doit = false; } } }); // We really want a selection listener but it is not supported so we // use a key listener and a mouse listener to know when selection changes // may have occured text.addMouseListener(new MouseAdapter() { @Override public void mouseUp(MouseEvent e) { checkSelection(); checkDeleteable(); checkSelectable(); } }); text.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { TableTextCellEditor.this.focusLost(); } }); text.setFont(parent.getFont()); text.setBackground(parent.getBackground()); text.setText("");//$NON-NLS-1$ text.addModifyListener(getModifyListener()); return result; }
From source file:com.google.dart.tools.ui.internal.filesview.FilesView.java
License:Open Source License
protected void fillContextMenu(IMenuManager manager) { IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection(); // New File/ New Folder if (allElementsAreResources(selection)) { manager.add(createFileAction);/*from w w w . j a va 2s. c om*/ } if (selection.size() == 1 && selection.getFirstElement() instanceof IContainer) { manager.add(createFolderAction); } manager.add(createApplicationAction); // OPEN GROUP if (manager.getItems().length > 0) { manager.add(new Separator()); } manager.add(OpenFolderHandler.createCommandAction(getSite().getWorkbenchWindow())); // Close folder action (aka Remove from Editor) if (!selection.isEmpty() && allElementsAreResources(selection)) { // Remove, iff non-empty selection, all elements are IResources if (allElementsAreProjects(selection)) { manager.add(hideContainerAction); } } // EDIT GROUP if (!selection.isEmpty() && allElementsAreResources(selection)) { manager.add(new Separator()); manager.add(copyAction); // Copy File Path iff single element and is an IResource if (selection.size() == 1) { manager.add(copyFilePathAction); } manager.add(pasteAction); if (selection.size() == 1 && selection.getFirstElement() instanceof IFile) { manager.add(openAsTextAction); } manager.add(new Separator()); manager.add(refreshAction); } // REFACTOR GROUP // Refactor iff all elements are IResources if (!selection.isEmpty() && allElementsAreResources(selection)) { manager.add(new Separator()); if (selection.size() == 1) { manager.add(renameAction); manager.add(moveAction); } manager.add(cleanUpAction); manager.add(new Separator()); ignoreResourceAction.updateLabel(); manager.add(ignoreResourceAction); if (enableBuilderAction.shouldBeEnabled()) { enableBuilderAction.updateLabel(); manager.add(enableBuilderAction); } manager.add(new Separator()); manager.add(deleteAction); manager.add(new Separator()); } }
From source file:com.google.dart.tools.ui.internal.libraryview.LibraryExplorerActionGroup.java
License:Open Source License
@Override public void fillContextMenu(IMenuManager menu) { super.fillContextMenu(menu); ISelection selection = getContext().getSelection(); if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) { // Nothing selected - go with New File, New Application, and Open File menu.add(newFileWizardAction);//from w w w .ja v a 2 s .com menu.add(newApplicationWizardAction); menu.add(new Separator()); menu.add(openFileAction); return; } IStructuredSelection ss = (IStructuredSelection) selection; if (ss.size() != 1) { for (Object o : ss.toList()) { if (!(o instanceof DartLibrary)) { return; } } menu.add(closeLibraryAction); return; } Object o = ss.getFirstElement(); if (!(o instanceof IAdaptable)) { return; } IAdaptable element = (IAdaptable) o; if (element instanceof DartLibrary) { // Library container menu.add(newFileWizardAction); menu.add(new Separator()); menu.add(closeLibraryAction); return; } if (element instanceof CompilationUnit) { // .dart file menu.add(navigateActionGroup.getEditAction()); return; } if (element instanceof HTMLFile) { menu.add(navigateActionGroup.getEditAction()); menu.add(new Separator()); menu.add(runInBrowserAction); return; } if (element instanceof DartResource) { menu.add(navigateActionGroup.getEditAction()); return; } }
From source file:com.google.dart.tools.ui.internal.libraryview.LibraryExplorerPart.java
License:Open Source License
@Override public boolean show(ShowInContext context) { ISelection selection = context.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = ((IStructuredSelection) selection); if (structuredSelection.size() == 1) { int res = tryToReveal(structuredSelection.getFirstElement()); if (res == IStatus.OK) { return true; }/* w ww.j av a 2 s. c om*/ if (res == IStatus.CANCEL) { return false; } } else if (structuredSelection.size() > 1) { selectReveal(structuredSelection); return true; } } Object input = context.getInput(); if (input instanceof IEditorInput) { Object elementOfInput = getInputFromEditor((IEditorInput) input); return elementOfInput != null && (tryToReveal(elementOfInput) == IStatus.OK); } return false; }
From source file:com.google.dart.tools.ui.internal.libraryview.LibraryExplorerPart.java
License:Open Source License
private boolean inputIsSelected(IEditorInput input) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.size() != 1) { return false; }/* w w w. jav a 2 s.c o m*/ IEditorInput selectionAsInput; try { selectionAsInput = EditorUtility.getEditorInput(selection.getFirstElement()); } catch (DartModelException dme) { dme.printStackTrace(); return false; } return input.equals(selectionAsInput); }
From source file:com.google.dart.tools.ui.internal.problemsview.ProblemsView.java
License:Open Source License
private void addActionsForSelection(IMenuManager menuManager) { IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); if (selection.size() == 1) { Object element = selection.getFirstElement(); if (!(element instanceof IMarker)) { return; }//from w ww . java 2 s . c om final IMarker marker = (IMarker) element; IMarkerResolution[] resolutions = IDE.getMarkerHelpRegistry().getResolutions(marker); for (final IMarkerResolution resolution : resolutions) { Action action = new Action(escapeSpecialChars(resolution.getLabel())) { @Override public void run() { resolution.run(marker); } }; if (resolution instanceof IMarkerResolution2) { IMarkerResolution2 resolution2 = (IMarkerResolution2) resolution; Image image = resolution2.getImage(); if (image != null) { action.setImageDescriptor(ImageDescriptor.createFromImage(image)); } } menuManager.add(action); } } }
From source file:com.google.dart.tools.ui.internal.problemsview.ProblemsView.java
License:Open Source License
private void updateStatusLine(IStructuredSelection selection) { String message;/*from w w w . jav a2 s . c o m*/ if (selection == null || selection.size() == 0) { message = ""; } else if (selection.size() == 1) { Object sel = selection.getFirstElement(); if (sel instanceof IMarker) { IMarker marker = (IMarker) sel; message = marker.getAttribute(IMarker.MESSAGE, ""); } else { message = ""; } } else { List<IMarker> selMarkers = new ArrayList<IMarker>(); for (Object obj : selection.toList()) { if (obj instanceof IMarker) { selMarkers.add((IMarker) obj); } } message = getStatusSummary(selMarkers.toArray(new IMarker[selMarkers.size()])); } getViewSite().getActionBars().getStatusLineManager().setMessage(message); }
From source file:com.google.dart.tools.ui.internal.refactoring.actions.RenameDartElementAction.java
License:Open Source License
private static DartElement getDartElement(IStructuredSelection selection) { if (selection.size() != 1) { return null; }/*ww w. jav a 2 s .co m*/ Object first = selection.getFirstElement(); if (!(first instanceof DartElement)) { return null; } return (DartElement) first; }