List of usage examples for org.eclipse.jface.viewers StructuredSelection isEmpty
@Override public boolean isEmpty()
From source file:com.toubassi.jface.Explorer.java
License:Open Source License
/** * Gets the selection from the last view that the user interacted * with that had a selection (either table or tree). * @return/*from w ww . ja va2 s . c o m*/ */ public StructuredSelection getSelection() { StructuredSelection selection = StructuredSelection.EMPTY; if (lastSelectedViewer == tableViewer) { selection = getTableSelection(); if (selection.isEmpty()) { selection = getTreeSelection(); } } else { selection = getTreeSelection(); if (selection.isEmpty()) { selection = getTableSelection(); } } return selection; }
From source file:com.vectrace.MercurialEclipse.history.ChangedPathsPage.java
License:Open Source License
private void contributeActions() { Action toggleShowComments = new Action(Messages.getString("HistoryView.showComments"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_COMMENTS)) { @Override//ww w .j a va2 s . c o m public void run() { showComments = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_COMMENTS, showComments); } }; toggleShowComments.setChecked(showComments); Action toggleShowDiffs = new Action(Messages // TODO create new text & image .getString("HistoryView.showDiffs"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_DIFFS)) { @Override public void run() { showDiffs = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_DIFFS, showDiffs); } }; toggleShowDiffs.setChecked(showDiffs); // Toggle wrap comments action Action toggleWrapCommentsAction = new Action(Messages.getString("HistoryView.wrapComments")) { @Override public void run() { wrapCommentsText = isChecked(); setViewerVisibility(); store.setValue(PREF_WRAP_COMMENTS, wrapCommentsText); } }; toggleWrapCommentsAction.setChecked(wrapCommentsText); // Toggle path visible action Action toggleShowAffectedPathsAction = new Action(Messages.getString("HistoryView.showAffectedPaths"), //$NON-NLS-1$ MercurialEclipsePlugin.getImageDescriptor(IMG_AFFECTED_PATHS_FLAT_MODE)) { @Override public void run() { showAffectedPaths = isChecked(); setViewerVisibility(); store.setValue(PREF_SHOW_PATHS, showAffectedPaths); } }; toggleShowAffectedPathsAction.setChecked(showAffectedPaths); IHistoryPageSite parentSite = getHistoryPageSite(); IPageSite pageSite = parentSite.getWorkbenchPageSite(); IActionBars actionBars = pageSite.getActionBars(); // Contribute toggle text visible to the toolbar drop-down IMenuManager actionBarsMenu = actionBars.getMenuManager(); actionBarsMenu.add(toggleWrapCommentsAction); actionBarsMenu.add(new Separator()); actionBarsMenu.add(toggleShowComments); actionBarsMenu.add(toggleShowAffectedPathsAction); actionBarsMenu.add(toggleShowDiffs); actionBarsMenu.add(new Separator()); for (int i = 0; i < toggleAffectedPathsLayoutActions.length; i++) { actionBarsMenu.add(toggleAffectedPathsLayoutActions[i]); } // Create the local tool bar IToolBarManager tbm = actionBars.getToolBarManager(); tbm.add(toggleShowComments); tbm.add(toggleShowAffectedPathsAction); tbm.add(toggleShowDiffs); tbm.update(false); actionBars.updateActionBars(); final BaseSelectionListenerAction openAction = page.getOpenAction(); final BaseSelectionListenerAction openEditorAction = page.getOpenEditorAction(); final BaseSelectionListenerAction compareWithCurrent = page.getCompareWithCurrentAction(); final BaseSelectionListenerAction compareWithPrevious = page.getCompareWithPreviousAction(); final BaseSelectionListenerAction compareWithOther = page.getCompareWithOtherAction(); final BaseSelectionListenerAction actionRevert = page.getRevertAction(); final BaseSelectionListenerAction focusOnSelected = page.getFocusOnSelectedFileAction(); changePathsViewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { FileStatus fileStatus = (FileStatus) ((IStructuredSelection) event.getSelection()) .getFirstElement(); MercurialRevision derived = getDerivedRevision(fileStatus, getCurrentRevision()); if (derived == null) { return; } StructuredSelection selection = new StructuredSelection(new Object[] { derived, fileStatus }); compareWithPrevious.selectionChanged(selection); compareWithPrevious.run(); } }); // Contribute actions to popup menu final MenuManager menuMgr = new MenuManager(); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager menuMgr1) { IStructuredSelection selection = (IStructuredSelection) changePathsViewer.getSelection(); if (selection.isEmpty()) { return; } FileStatus fileStatus = (FileStatus) selection.getFirstElement(); MercurialRevision base = getCurrentRevision(); MercurialRevision derived = getDerivedRevision(fileStatus, base); if (derived == null) { // XXX currently files outside workspace are not supported... return; } selection = new StructuredSelection(derived); openAction.selectionChanged(selection); focusOnSelected.selectionChanged(selection); openEditorAction.selectionChanged(selection); compareWithCurrent.selectionChanged(selection); compareWithOther.selectionChanged(selection); selection = new StructuredSelection(new Object[] { derived, fileStatus }); compareWithPrevious.selectionChanged(selection); menuMgr1.add(openAction); menuMgr1.add(openEditorAction); menuMgr1.add(focusOnSelected); menuMgr1.add(new Separator(IWorkbenchActionConstants.GROUP_FILE)); menuMgr1.add(compareWithCurrent); menuMgr1.add(compareWithPrevious); menuMgr1.add(compareWithOther); menuMgr1.add(new Separator()); selection = new StructuredSelection(new Object[] { derived }); actionRevert.selectionChanged(selection); menuMgr1.add(actionRevert); menuMgr1.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); } }); menuMgr.setRemoveAllWhenShown(true); changePathsViewer.getTable().setMenu(menuMgr.createContextMenu(changePathsViewer.getTable())); }
From source file:de.walware.ecommons.ui.breadcrumb.AbstractBreadcrumb.java
License:Open Source License
private boolean doOpen(final ISelection selection) { if (!(selection instanceof StructuredSelection)) { return false; }// www . j a va 2s . c o m final StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) { return false; } return open(structuredSelection.getFirstElement()); }
From source file:de.walware.ecommons.ui.breadcrumb.AbstractBreadcrumb.java
License:Open Source License
private boolean doReveal(final ISelection selection) { if (!(selection instanceof StructuredSelection)) { return false; }/*from w w w .ja va 2s. co m*/ final StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.isEmpty()) { return false; } return reveal(structuredSelection.getFirstElement()); }
From source file:de.weingardt.mylyn.gitlab.ui.GitlabQueryPage.java
License:Open Source License
private void removeSelection() { StructuredSelection selection = (StructuredSelection) labelsViewer.getSelection(); if (!selection.isEmpty()) { labelsViewer.remove(selection.toArray()); }//from w w w . j a v a2 s .c o m }
From source file:edu.uchicago.cs.hao.texdojo.bibeditor.editors.EditorUI.java
License:Open Source License
public BibEntry selected() { StructuredSelection sel = (StructuredSelection) table.getSelection(); if (sel.isEmpty()) return null; return (BibEntry) sel.getFirstElement(); }
From source file:edu.uchicago.cs.hao.texdojo.bibeditor.editors.EditorUI.java
License:Open Source License
public BibEntry[] allSelected() { StructuredSelection sel = (StructuredSelection) table.getSelection(); if (sel == null || sel.isEmpty()) return null; Object[] sels = sel.toArray(); BibEntry[] allsels = new BibEntry[sels.length]; for (int i = 0; i < sels.length; i++) { allsels[i] = (BibEntry) sels[i]; }//from ww w .j ava2 s .c o m return allsels; }
From source file:era.foss.objecteditor.specobject.SpecObjectHandler.java
License:Open Source License
/** * Remove specObject and associated hierarchy element in {@link SpecHierarchy} * // w w w. ja v a 2 s.com * @param specObject specObject to be deleted * */ public static void deleteSpecObject(EditingDomain editingDomain, SpecObject specObject) { CompoundCommand compoundCommand = new CompoundCommand(); compoundCommand.setLabel(ErfObjectsEditorPlugin.INSTANCE.getString("_UI_DeleteSpecObject_label")); compoundCommand .setDescription(ErfObjectsEditorPlugin.INSTANCE.getString("_UI_DeleteSpecObject_description")); // delete SpecHierarachy StructuredSelection specHierarchySelection = new StructuredSelection(specObject.getSpecHierarchy()); if (!specHierarchySelection.isEmpty()) { Command deleteSpecHierarachyCommand = new DeleteCommand(editingDomain, specHierarchySelection.toList()); compoundCommand.append(deleteSpecHierarachyCommand); } // delete SpecObject Command deleteSpecObjectCommand = new DeleteCommand(editingDomain, new StructuredSelection(specObject).toList()); compoundCommand.append(deleteSpecObjectCommand); editingDomain.getCommandStack().execute(compoundCommand); }
From source file:es.cv.gvcase.ide.navigator.view.MOSKittModelNavigator.java
License:Open Source License
/** * If linking, propagate the selection in the {@link CommonViewer} to the * active {@link IEditorPart}./*w w w. j a v a2 s . co m*/ * * @param event * the event */ protected void handleSelectionChangedToDiagram(SelectionChangedEvent event) { if (isLinkingEnabled() && startHandlingSelectionChange()) { IEditorPart activeEditor = NavigatorUtil.getActiveEditor(); if (activeEditor instanceof IDiagramWorkbenchPart) { // set editor selection; select EditParts IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) activeEditor).getDiagramGraphicalViewer(); if (viewer == null) { return; } List<EditPart> editPartsToSelect = NavigatorUtil.getEditPartsFromSelection(event.getSelection(), viewer); StructuredSelection selectedEditParts = new StructuredSelection(editPartsToSelect); viewer.setSelection(selectedEditParts); if (!selectedEditParts.isEmpty()) { EditPart editPart = (EditPart) selectedEditParts.getFirstElement(); viewer.reveal(editPart); } } endHandlingSelectionChange(); } }
From source file:es.cv.gvcase.mdt.common.actions.handlers.ClipboardActionHandler.java
License:Open Source License
protected void setSelectionTo(Collection<EObject> eObjects, IGraphicalEditPart editPart) { eObjects = fromViewToEObject(eObjects); Collection<IGraphicalEditPart> editParts = getEditPartsFor(eObjects, editPart); if (editParts != null && !editParts.isEmpty()) { IDiagramGraphicalViewer viewer = ((IDiagramWorkbenchPart) MDTUtil.getActiveEditor()) .getDiagramGraphicalViewer(); if (viewer == null) { return; }// w w w. java 2 s .co m StructuredSelection selectedEditParts = new StructuredSelection(editParts); viewer.setSelection(selectedEditParts); if (!selectedEditParts.isEmpty()) { EditPart firstEditPart = (EditPart) selectedEditParts.getFirstElement(); viewer.reveal(firstEditPart); } } }