List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.bdaum.zoom.ui.internal.preferences.PerspectivesPreferencePage.java
License:Open Source License
@Override protected void doUpdateButtons() { IStructuredSelection sel = viewer.getStructuredSelection(); deleteButton.setEnabled(!sel.isEmpty() && !isPredefined((IPerspectiveDescriptor) sel.getFirstElement())); }
From source file:com.bdaum.zoom.ui.internal.views.BookmarkView.java
License:Open Source License
private void makeActions() { gotoBookmarkAction = new GotoBookmarkAction(null, this); deleteAction = new Action(Messages.getString("BookmarkView.delete_bookmark"), Icons.delete //$NON-NLS-1$ .getDescriptor()) {/* www . j a v a2 s. c om*/ @Override public void run() { IStructuredSelection selection = viewer.getStructuredSelection(); if (!selection.isEmpty()) { Bookmark bookmark = (Bookmark) selection.getFirstElement(); Core.getCore().getDbManager().safeTransaction(bookmark, null); int i = 0; while (true) { Object element = viewer.getElementAt(i++); if (element == null || element == bookmark) break; } Object nextSelection = viewer.getElementAt(i); if (nextSelection == null && i >= 2) nextSelection = viewer.getElementAt(i - 2); viewer.remove(bookmark); if (nextSelection != null) viewer.setSelection(new StructuredSelection(nextSelection)); updateActions(); } } }; deleteAction.setToolTipText(Messages.getString("BookmarkView.delete_bookmark_tooltip")); //$NON-NLS-1$ }
From source file:com.bdaum.zoom.ui.internal.views.BookmarkView.java
License:Open Source License
private void hookDoubleClickAction() { viewer.addDoubleClickListener(new IDoubleClickListener() { public void doubleClick(DoubleClickEvent event) { IStructuredSelection selection = viewer.getStructuredSelection(); if (!selection.isEmpty()) { gotoBookmarkAction.setBookmark((Bookmark) selection.getFirstElement()); gotoBookmarkAction.run(); }/*ww w . j a va2 s .com*/ } }); }
From source file:com.bdaum.zoom.ui.internal.views.CatalogView.java
License:Open Source License
public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) { IStructuredSelection selection = viewer.getStructuredSelection(); if (!selection.isEmpty()) { Object selected = selection.getFirstElement(); Object newSelection = null; for (IViewReference ref : page.getViewReferences()) { IViewPart view = ref.getView(false); if (view instanceof BasicView) { Object content = ((BasicView) view).getContent(); if (selected == content && !UiActivator.getDefault().isPresentationPerspective(perspective.getId())) return; if (content instanceof SmartCollection) newSelection = content; }/*from w ww.j a v a2s . c o m*/ } if (newSelection != null) setViewerSelection(new StructuredSelection(newSelection), true); } }
From source file:com.bdaum.zoom.ui.internal.views.CatalogView.java
License:Open Source License
@Override protected void updateActions(IStructuredSelection selection, boolean force) { if (deleteAction != null) { super.updateActions(selection, force); boolean writable = !dbIsReadonly(); createGroup.setEnabled(writable); if (selection.isEmpty()) { deleteAction.setEnabled(false); cutCollection.setEnabled(false); copyCollection.setEnabled(false); createSlideShowAction.setEnabled(false); createWebGalleryAction.setEnabled(false); createExhibitionAction.setEnabled(false); createCollectionAction.setEnabled(false); createAlbumAction.setEnabled(false); addSubAlbumAction.setEnabled(false); addSubCollectionAction.setEnabled(false); addSubGroupAction.setEnabled(false); playSlideshowAction.setEnabled(false); refreshAction.setEnabled(false); } else {/*from w w w . ja v a 2s.c om*/ Object obj = selection.getFirstElement(); if ((obj instanceof GroupImpl)) { GroupImpl group = (GroupImpl) obj; boolean exhibition = !group.getExhibition().isEmpty(); boolean slideshow = !group.getSlideshow().isEmpty(); boolean webgallery = group.getWebGallery() != null && !group.getWebGallery().isEmpty(); boolean collection = !group.getRootCollection().isEmpty(); String groupId = group.getStringId(); if (!exhibition && !slideshow && !webgallery && !collection) { exhibition = Constants.GROUP_ID_EXHIBITION.equals(groupId); slideshow = Constants.GROUP_ID_SLIDESHOW.equals(groupId); webgallery = Constants.GROUP_ID_WEBGALLERY.equals(groupId); if (!exhibition && !slideshow && !webgallery) collection = exhibition = slideshow = webgallery = true; } addSubGroupAction.setEnabled((!group.getSystem() || isPersonGroup(group)) && writable); createWebGalleryAction.setEnabled(webgallery && writable); createSlideShowAction.setEnabled(slideshow && writable); createExhibitionAction.setEnabled(exhibition && writable); createCollectionAction.setEnabled(collection && writable); createAlbumAction.setEnabled(collection && writable); deleteAction.setEnabled(!hasChildren(group) && !group.getSystem() && writable); cutCollection.setEnabled(false); copyCollection.setEnabled(false); addSubCollectionAction.setEnabled(false); addSubAlbumAction.setEnabled(false); refreshAction.setEnabled(true); } else { refreshAction.setEnabled(false); addSubGroupAction.setEnabled(false); createSlideShowAction.setEnabled(false); createExhibitionAction.setEnabled(false); createWebGalleryAction.setEnabled(false); createCollectionAction.setEnabled(false); createAlbumAction.setEnabled(false); if (obj instanceof SmartCollection) { SmartCollection coll = (SmartCollection) obj; boolean enabled = !coll.getSystem() && writable; boolean deleteEnabled = enabled; if (!enabled) { deleteEnabled = coll.getName() == null || coll.getName().isEmpty(); if (!deleteEnabled) { String collId = coll.getStringId(); String key = QueryField.URI.getKey() + '='; if (collId.startsWith(key)) try { deleteEnabled = !new File(new URI(collId.substring(key.length()))).exists(); } catch (URISyntaxException e) { deleteEnabled = true; } } } deleteAction.setEnabled(deleteEnabled); cutCollection.setEnabled(enabled); copyCollection.setEnabled(enabled); boolean isFinal = (coll.getCriterion().size() == 1 && coll.getCriterion(0).getField().startsWith("*")); //$NON-NLS-1$ addSubCollectionAction.setEnabled(!isFinal && writable); addSubAlbumAction.setEnabled(!coll.getSystem() && coll.getAlbum() && writable); } else { deleteAction.setEnabled(writable); cutCollection.setEnabled(writable); copyCollection.setEnabled(writable); addSubCollectionAction.setEnabled(false); } } } Object contents = clipboard.getContents(LocalSelectionTransfer.getTransfer()); pasteCollection.setEnabled((contents instanceof IStructuredSelection && ((IStructuredSelection) contents).getFirstElement() instanceof SmartCollectionImpl) && writable); } }
From source file:com.bdaum.zoom.ui.internal.views.CatalogView.java
License:Open Source License
@Override public void collectionChanged(IWorkbenchPart part, IStructuredSelection selection) { if (part != this && selection != null && !selection.isEmpty()) setViewerSelection(selection, true); }
From source file:com.byterefinery.rmbench.database.mysql.EnumAndSetDialog.java
License:Open Source License
private void createListViewer(Composite parent) { typesViewer = new TableViewer(parent, SWT.BORDER); GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.verticalSpan = 4;// w w w .j ava 2s. c o m typesViewer.getControl().setLayoutData(gd); typesViewer.setLabelProvider(new TypeLabelProvider()); typesViewer.setContentProvider(new TypesContentProvider()); typesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection sel = (IStructuredSelection) event.getSelection(); if (sel.isEmpty()) { deleteButton.setEnabled(false); return; } inputText.setText((String) sel.getFirstElement()); deleteButton.setEnabled(true); } }); }
From source file:com.byterefinery.rmbench.dialogs.export.ExportWizard.java
License:Open Source License
public void init(IWorkbench workbench, IStructuredSelection selection) { if (!selection.isEmpty()) { IExportable exportable = (IExportable) selection.getFirstElement(); diagramExport = exportable.getDiagramExport(); modelExport = exportable.getModelExport(); }/*from w w w.j a v a 2s. c o m*/ if (diagramExport == null) { IWorkbenchWindow ww = workbench.getActiveWorkbenchWindow(); if (ww != null && ww.getActivePage() != null) { IEditorPart ep = ww.getActivePage().getActiveEditor(); if (ep instanceof DiagramEditor) { DiagramEditor de = (DiagramEditor) ep; diagramExport = de.getDiagramPart(); } } } if (modelExport == null) modelExport = RMBenchPlugin.getDefault().getModelExport(); }
From source file:com.byterefinery.rmbench.util.keyboardsupport.TableViewerKeyBoardSupporter.java
License:Open Source License
private Object getSelectedElement() { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); if (selection == null || selection.isEmpty()) return null; return selection.getFirstElement(); }
From source file:com.cea.papyrus.views.cpp.views.CppPanelView.java
License:Open Source License
public void selectionChanged(IWorkbenchPart part, ISelection selection) { IStructuredSelection sSelection = null; if (selection instanceof IStructuredSelection) { sSelection = (IStructuredSelection) selection; }// ww w. j av a 2 s.com // exclude case of an empty selection which is not a Tree selection, since changing views provokes an // empty selection (selection gets lost, although same element remains selected) if ((selection != null) && (sSelection != null) && sSelection.isEmpty()) { return; } currentTarget = null; // No available selection: switch to default panel if ((sSelection == null) || (sSelection.size() != 1)) { switchUI(); return; } // Retrieve selected object Object currentObject = sSelection.getFirstElement(); // If the object is an edit part, try to get semantic bridge if (currentObject instanceof GraphicalEditPart) { GraphicalEditPart editPart = (GraphicalEditPart) currentObject; if (editPart.getModel() instanceof View) { View view = (View) editPart.getModel(); if (view.getElement() instanceof Element) { currentObject = (Element) view.getElement(); } } } else if (currentObject instanceof IAdaptable) { // modisco ModelElementItem supports IAdaptable (cleaner than cast / dependency with modisco) currentObject = ((IAdaptable) currentObject).getAdapter(EObject.class); } if (currentObject instanceof Element) { currentTarget = (Element) currentObject; switchUI(); } }