List of usage examples for org.eclipse.jface.viewers IStructuredSelection size
public int size();
From source file:com.nokia.carbide.cpp.uiq.ui.vieweditor.CommandElementDragListener.java
License:Open Source License
/** * Method declared on DragSourceListener *//*from w w w.ja v a 2 s .c o m*/ public void dragStart(DragSourceEvent event) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); Object[] elements = (Object[]) selection.toList().toArray(new Object[selection.size()]); if (elements[0] instanceof CommandList) { event.detail = DND.DROP_NONE; event.doit = false; return; } event.doit = !viewer.getSelection().isEmpty(); }
From source file:com.nokia.carbide.internal.discovery.ui.extension.AbstractDiscoveryPortalPageLayer.java
License:Open Source License
protected IAction[] makeActions(final IEditorPart part) { this.part = part; selectionListeners = new ArrayList<ISelectionChangedListener>(); List<IAction> actions = new ArrayList<IAction>(); IAction action;//from w ww. java 2s .c o m // install action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_InstallActionLabel) { public void run() { installCatalogItems(viewer.getCheckedItems()); }; protected boolean updateSelection(IStructuredSelection selection) { scheduleUpdateAllActionUIs(); return !selection.isEmpty(); }; }; action.setToolTipText(Messages.AbstractDiscoveryPortalPageLayer_InstallActionTooltip); action.setId(INSTALL_ACTION_ID); selectionListeners.add((ISelectionChangedListener) action); actions.add(action); // refresh action = new Action(Messages.AbstractDiscoveryPortalPageLayer_RefreshActionLabel) { public void run() { viewer.setSelection(StructuredSelection.EMPTY); viewer.updateCatalog(); viewer.refresh(); } }; action.setId(REFRESH_ACTION_ID); actions.add(action); // check all action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_CheckAllActionLabel) { public void run() { viewer.setSelection(StructuredSelection.EMPTY); viewer.setSelection(getAllItemsSelection()); viewer.refresh(); } private IStructuredSelection getAllItemsSelection() { List<CatalogItem> catalogItems = new ArrayList<CatalogItem>(); for (CatalogItem catalogItem : viewer.getCatalog().getItems()) { if (!catalogItem.isInstalled()) catalogItems.add(catalogItem); } return new StructuredSelection(catalogItems); } protected boolean updateSelection(IStructuredSelection selection) { scheduleUpdateAllActionUIs(); return !getAllItemsSelection().equals(selection); } }; action.setId(CHECK_ALL_ACTION_ID); selectionListeners.add((ISelectionChangedListener) action); actions.add(action); // uncheck all action = new BaseSelectionListenerAction(Messages.AbstractDiscoveryPortalPageLayer_UncheckAllActionLabel) { public void run() { viewer.setSelection(StructuredSelection.EMPTY); viewer.refresh(); }; protected boolean updateSelection(IStructuredSelection selection) { scheduleUpdateAllActionUIs(); return !selection.isEmpty(); }; }; action.setId(UNCHECK_ALL_ACTION_ID); selectionListeners.add((ISelectionChangedListener) action); actions.add(action); // advanced install action = new Action(Messages.AbstractDiscoveryPortalPageLayer_AdvancedInstallActionLabel) { public void run() { showInstallWizard(); } }; action.setId(ADV_INSTALL_ACTION_ID); actions.add(action); ISelectionChangedListener selectionListener = new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); IActionBars bars = part.getEditorSite().getActionBars(); bars.getStatusLineManager() .setMessage(selection.isEmpty() ? null : MessageFormat.format( Messages.AbstractDiscoveryPortalPageLayer_CheckedItemsStatusMessage, selection.size())); } }; selectionListeners.add(selectionListener); return (IAction[]) actions.toArray(new IAction[actions.size()]); }
From source file:com.nokia.carbide.search.system.internal.ui.text.NewTextSearchActionGroup.java
License:Open Source License
public void fillContextMenu(IMenuManager menu) { // view must exist if we create a context menu for it. ISelection selection = getContext().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structured = (IStructuredSelection) selection; addOpenWithMenu(menu, structured); if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && fOpenPropertiesDialog.isApplicableForSelection(structured)) if (structured.size() > 0 && structured.getFirstElement() instanceof IFileStore) { IFileStore fileStore = (IFileStore) structured.getFirstElement(); IFile[] ifiles = null;/*from ww w .ja v a 2 s . co m*/ try { ifiles = fWorkspaceRoot.findFilesForLocation( new Path(fileStore.toLocalFile(EFS.NONE, null).getAbsolutePath())); } catch (CoreException e) { } if (ifiles != null && ifiles.length > 0) { structured = new StructuredSelection(ifiles[0]); fProvider.setSelection(structured); fOpenPropertiesDialog.selectionChanged(structured); menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog); } } } }
From source file:com.nokia.carbide.search.system.internal.ui.text.NewTextSearchActionGroup.java
License:Open Source License
private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) { if (selection == null) return;//from w w w . j a v a 2s .c om fOpenAction.selectionChanged(selection); if (fOpenAction.isEnabled()) { menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction); } if (selection.size() != 1) { return; } Object o = selection.getFirstElement(); if (!(o instanceof IAdaptable)) return; // Open With... context submenu IMenuManager submenu = new MenuManager(SearchMessages.OpenWithMenu_label); if (o instanceof IFileStore) { // see if o is in the workspace IFileStore fileStore = (IFileStore) o; IFile[] ifiles = null; try { ifiles = fWorkspaceRoot .findFilesForLocation(new Path(fileStore.toLocalFile(EFS.NONE, null).getAbsolutePath())); } catch (CoreException e) { } if (ifiles == null || ifiles.length == 0) { // file is not in the workspace fSelectedFile = fileStore; // Open item Action action = new Action() { public void run() { String editorID = null; IEditorDescriptor des = getDefaultEditor(fSelectedFile); if (des != null) { editorID = des.getId(); } else { editorID = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$ } try { IDE.openEditor(fPage, fSelectedFile.toURI(), editorID, true); } catch (PartInitException e) { String msg = NLS.bind(IDEWorkbenchMessages.OpenLocalFileAction_message_errorOnOpen, fSelectedFile.getName()); IDEWorkbenchPlugin.log(msg, e.getStatus()); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), IDEWorkbenchMessages.OpenLocalFileAction_title, msg); } } }; action.setText(SearchMessages.NewTextSearchActionGroup_open); action.setToolTipText(SearchMessages.NewTextSearchActionGroup_openToolTip); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action); // OpenWith submenu submenu.add(new SystemOpenWithMenu(fPage, (IAdaptable) fileStore)); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); return; } else { // file is in the workspace o = ifiles[0]; // fall through } } // OpenWith submenu submenu.add(new OpenWithMenu(fPage, (IAdaptable) o)); menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu); }
From source file:com.nokia.carbide.search.system.internal.ui.text.ReplaceDialog2.java
License:Open Source License
private void selectEntry(Match marker) { ISelection sel = fPage.getViewer().getSelection(); if (!(sel instanceof IStructuredSelection)) return;//from w w w .java2 s.com IStructuredSelection ss = (IStructuredSelection) sel; IFileStore file = (IFileStore) marker.getElement(); if (ss.size() == 1 && file.equals(ss.getFirstElement())) return; fPage.getViewer().setSelection(new StructuredSelection(marker.getElement())); }
From source file:com.nokia.carbide.search.system.ui.text.AbstractTextSearchViewPage.java
License:Open Source License
private Object getFirstSelectedElement() { IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); if (selection.size() > 0) return selection.getFirstElement(); return null;// w w w.j av a 2 s . c om }
From source file:com.nokia.cdt.internal.debug.launch.ui.FilesBlock.java
License:Open Source License
private void removeFiles() { IStructuredSelection selection = (IStructuredSelection) fFileList.getSelection(); FileToTransfer[] files = new FileToTransfer[selection.size()]; Iterator<?> iter = selection.iterator(); int i = 0;// w w w. ja v a 2 s . co m while (iter.hasNext()) { files[i] = (FileToTransfer) iter.next(); i++; } removeFiles(files); }
From source file:com.nokia.s60ct.cenrep.gui.Actions.AddKeyAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { repository = null;//from w w w. j a va2 s . com if (selection instanceof IStructuredSelection) { IStructuredSelection structedSelection = (IStructuredSelection) selection; if (structedSelection.size() > 0) { repository = (EObject) structedSelection.getFirstElement(); } } }
From source file:com.nokia.s60ct.gui.actions.AddBasedOnAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { rootConf = null;// www .j a v a 2s. com if (selection instanceof IStructuredSelection) { IStructuredSelection structedSelection = (IStructuredSelection) selection; if (structedSelection.size() > 0) { rootConf = (RootConf) structedSelection.getFirstElement(); } } if (rootConf != null && !rootConf.isReadOnly()) action.setEnabled(true); else action.setEnabled(false); }
From source file:com.nokia.s60ct.gui.actions.AddChildAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { selectedObject = null;/*from w ww. j a v a2s.com*/ if (selection instanceof IStructuredSelection) { IStructuredSelection structedSelection = (IStructuredSelection) selection; if (structedSelection.size() > 0) { selectedObject = (EObject) structedSelection.getFirstElement(); } } if (selectedObject != null && !isObjectReadOnly(selectedObject)) action.setEnabled(true); else action.setEnabled(false); }