List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:gov.redhawk.sca.ui.actions.ResourceDropAdapterAssistant.java
License:Open Source License
private ScaFileStore[] getSelectedResource(final IStructuredSelection aDragSelection) { final List<ScaFileStore> retVal = new ArrayList<ScaFileStore>(aDragSelection.size()); for (final Object obj : aDragSelection.toArray()) { if (obj instanceof ScaFileStore) { retVal.add((ScaFileStore) obj); }//ww w .ja v a2s . c o m } return retVal.toArray(new ScaFileStore[retVal.size()]); }
From source file:gov.redhawk.ui.views.namebrowser.internal.command.Refresh.java
License:Open Source License
@Override public Object execute(final ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { NameBrowserView view;/*from ww w . j a v a2 s. c om*/ view = (NameBrowserView) page.findView(NameBrowserView.ID); if (view != null) { if (selection instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) selection; final Set<BindingNode> nodes = new HashSet<BindingNode>(); for (final Object obj : sel.toArray()) { if (obj instanceof BindingNode) { nodes.add((BindingNode) obj); } } view.refresh(nodes.toArray(new BindingNode[nodes.size()])); } else { view.refresh(); } } } return null; }
From source file:gradle4eclipse.actions.AddGradleNature.java
License:Open Source License
public void selectionChanged(IAction _action, ISelection _selection) { if (_selection instanceof IStructuredSelection) { projects = new LinkedHashSet<IProject>(); IStructuredSelection selection = (IStructuredSelection) _selection; if (!selection.isEmpty()) { for (Object element : selection.toArray()) { if (element instanceof IProject) { projects.add((IProject) element); } else if (element instanceof IResource) { projects.add(((IResource) element).getProject()); }//from w ww. jav a 2s. c om } } } }
From source file:ilg.gnuarmeclipse.packs.ui.views.PacksView.java
License:Open Source License
public void updateButtonsEnableStatus(IStructuredSelection selection) { if (selection == null || selection.isEmpty()) { // System.out.println("Empty Selection"); return;/*w w w. j a v a 2 s . c om*/ } if (((Leaf) selection.getFirstElement()).isType(Type.NONE)) { return; } fIsInstallEnabled = false; fIsRemoveEnabled = false; fIsCopyExampleEnabled = false; for (Object obj : selection.toArray()) { Leaf node = (Leaf) obj; String type = node.getType(); boolean isInstalled = false; if (node.isBooleanProperty(Property.INSTALLED)) { isInstalled = true; } // Check if the selection contain any package or // version not installed if (Type.PACKAGE.equals(type)) { if (!isInstalled) { fIsInstallEnabled = true; } } if (Type.VERSION.equals(type)) { int size = 0; try { size = Integer.valueOf(node.getProperty(Property.ARCHIVE_SIZE, "0")); } catch (NumberFormatException e) { ; } if (!isInstalled && size > 0) { fIsInstallEnabled = true; } if (isInstalled) { fIsRemoveEnabled = true; } } if ((Type.EXAMPLE.equals(type))) { fIsCopyExampleEnabled = true; } } fInstallAction.setEnabled(fIsInstallEnabled); fRemoveAction.setEnabled(fIsRemoveEnabled); }
From source file:io.sarl.eclipse.launching.shortcuts.LaunchAgentShortcut.java
License:Apache License
@Override public IResource getLaunchableResource(ISelection selection) { if (selection instanceof IStructuredSelection) { final IStructuredSelection sel = (IStructuredSelection) selection; return findResource(sel.toArray()); }/*from w w w.j av a2 s . c om*/ return null; }
From source file:io.usethesource.impulse.help.IMPHelp.java
License:Open Source License
/** * Creates and returns a help context provider for the given part. * //from w w w .ja v a2 s . co m * @param part the part for which to create the help context provider * @param contextId the optional context ID used to retrieve static help * @return the help context provider */ public static IContextProvider getHelpContextProvider(IWorkbenchPart part, LanguageServiceManager srvcMgr, String contextId) { ISelectionProvider provider = part.getSite().getSelectionProvider(); if (provider != null) { ISelection sel = provider.getSelection(); if (sel instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) sel; return new IMPHelpContextProvider(srvcMgr, contextId, selection.toArray()); } else if (sel instanceof ITextSelection) { ITextSelection textSel = (ITextSelection) sel; // IParseController parseController= srvcMgr.getParseController(); return new IMPHelpContextProvider(srvcMgr, contextId, new Region(textSel.getOffset(), textSel.getLength())); // ISourcePositionLocator nodeLocator= parseController.getNodeLocator(); // Object node= nodeLocator.findNode(parseController.getCurrentAst(), textSel.getOffset(), textSel.getOffset() + textSel.getLength()); // // if (node != null) { // elements= new Object[] { node }; // } else { // elements= NO_ELEMENTS; // } } } return null; }
From source file:it.eng.spagobi.meta.editor.dnd.PhysicalObjectDragListener.java
License:Mozilla Public License
/** * Check if the selected elements are all of the same (supported) type * @return true if selected elements are all of the same (supported) type *///from ww w . jav a2s .c o m public boolean checkSelectionSameType(IStructuredSelection selection) { textToTransfer = ""; int selectionSize = selection.size(); //-------------------- Single Selection if (selectionSize == 1) { if (selection.getFirstElement() instanceof PhysicalTable) { PhysicalTable physicalTable = (PhysicalTable) selection.getFirstElement(); textToTransfer = HEADER_FOR_TABLES_DATA + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalTable).toString(); logger.debug("Dragged physical table [{}]", physicalTable); return true; } else if (selection.getFirstElement() instanceof PhysicalColumn) { PhysicalColumn physicalColumn = (PhysicalColumn) selection.getFirstElement(); textToTransfer = HEADER_FOR_COLUMNS_DATA + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalColumn).toString(); logger.debug("Dragged physical column [{}]", physicalColumn); return true; } else return false; } //-------------------- Multiple Selection else if (selectionSize > 1) { //check if the elements are all instance of PhysicalTable if (selection.getFirstElement() instanceof PhysicalTable) { Object[] selectionArray = selection.toArray(); boolean firstElement = true; for (int i = 0; i < selectionSize; i++) { if (selectionArray[i] instanceof PhysicalTable) { PhysicalTable physicalTable = (PhysicalTable) selectionArray[i]; logger.debug("Dragged physical table [{}]", physicalTable); if (firstElement) { textToTransfer = HEADER_FOR_TABLES_DATA + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalTable).toString(); firstElement = false; } else { textToTransfer = textToTransfer + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalTable).toString(); } } else { //selection of mixed types return false; } } return true; } //check if the elements are all instance of PhysicalColumn else if (selection.getFirstElement() instanceof PhysicalColumn) { Object[] selectionArray = selection.toArray(); boolean firstElement = true; for (int i = 0; i < selectionSize; i++) { if (selectionArray[i] instanceof PhysicalColumn) { PhysicalColumn physicalColumn = (PhysicalColumn) selectionArray[i]; logger.debug("Dragged physical column [{}]", physicalColumn); if (firstElement) { textToTransfer = HEADER_FOR_COLUMNS_DATA + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalColumn).toString(); firstElement = false; } else { textToTransfer = textToTransfer + DATA_CHUNKS_SEPARATOR + EcoreUtil.getURI(physicalColumn).toString(); } } else { //selection of mixed types return false; } } return true; } //no supported elements selected return false; } //no valid selection return false; }
From source file:it.unibz.instasearch.ui.InstaSearchPage.java
License:Open Source License
private void getSelectedResources(HashMap<Field, Set<String>> filter) { if (container.getSelection() instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection) container.getSelection(); for (Object elem : sel.toArray()) { if (elem instanceof IAdaptable) { IResource res = null;/* www.ja va 2 s. co m*/ if (elem instanceof IResource) res = (IResource) elem; else { IAdaptable adaptable = (IAdaptable) elem; res = (IResource) adaptable.getAdapter(IResource.class); } if (res == null) continue; switch (res.getType()) { case IResource.PROJECT: Set<String> projects = filter.containsKey(Field.PROJ) ? filter.get(Field.PROJ) : new TreeSet<String>(); projects.add(((IProject) res).getName()); filter.put(Field.PROJ, projects); break; case IResource.FILE: Set<String> files = filter.containsKey(Field.FILE) ? filter.get(Field.FILE) : new TreeSet<String>(); files.add(((IFile) res).getFullPath().toString()); filter.put(Field.FILE, files); break; case IResource.FOLDER: Set<String> folders = filter.containsKey(Field.DIR) ? filter.get(Field.DIR) : new TreeSet<String>(); folders.add(res.getFullPath().toString()); filter.put(Field.DIR, folders); break; } } } } }
From source file:it.unibz.instasearch.ui.InstaSearchView.java
License:Open Source License
private void deleteSelectedMatch() { if (getResultViewer().getSelection() == null) return;//from ww w . j a v a 2 s .c o m IStructuredSelection selection = (IStructuredSelection) resultViewer.getSelection(); getResultViewer().remove(selection.toArray()); }
From source file:lumina.ui.actions.CutItemsToClipboardHandler.java
/** * Cuts the contents of the object into the clipboard. * // ww w . ja v a2 s. c om * @param event * event * @return null * @throws ExecutionException * never thrown * @see lumina.ui.swt.handlers.InterceptedHandler#execute(ExecutionEvent) */ @Override public Object executeDefault(ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { final IStructuredSelection structSelection = (IStructuredSelection) selection; if (structSelection.size() == 0) { return null; } final Object[] selectionItems = structSelection.toArray(); // verify if the operation is allowed final IWorkbenchPart activePart = HandlerUtil.getActivePart(event); if (activePart instanceof NavigationView && !Capabilities.canDo(Capability.DEVICE_EDIT_TREE)) { return null; } else if (activePart instanceof TimerView && !Capabilities.canDo(Capability.TIMER_EDIT_TREE)) { return null; } try { final ModelItem[] items = ModelUtils.asModelItems(structSelection.toArray()); final Transfer transfer = TransferFactory.getTransferFor(items); final Clipboard targetClipboard = ClipboardUtils.getClipboard(); targetClipboard.clearContents(); if (transfer != null) { targetClipboard.setContents( new Object[] { asText(selectionItems), ModelUtils.asModelItems(selectionItems) }, new Transfer[] { TextTransfer.getInstance(), transfer }); } final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); // Delete the items final Object selected = structSelection.getFirstElement(); if (selected instanceof Device) { Device[] devices = ModelUtils.toDevices(selectionItems); IAction action = new DeleteDevicesAction(devices, workbenchWindow, "Cut"); action.run(); } else if (selected instanceof Area) { Area[] areas = ModelUtils.toAreas(selectionItems); IAction action = new DeleteAreasAction(areas, workbenchWindow, "Cut"); action.run(); } else if (selected instanceof Floor) { Floor[] floors = ModelUtils.toFloors(selectionItems); IAction action = new DeleteFloorsAction(floors, workbenchWindow, "Cut"); action.run(); } else if (selected instanceof Task) { Task[] tasks = ModelUtils.toTasks(selectionItems); IAction action = new DeleteTasksAction(tasks, workbenchWindow, "Cut"); action.run(); } else if (selected instanceof Schedule) { Schedule[] scheds = ModelUtils.toSchedules(selectionItems); IAction action = new DeleteSchedulesAction(scheds, workbenchWindow, "Cut"); action.run(); } else if (selected instanceof DeviceTimer) { DeviceTimer[] timers = ModelUtils.toTimers(selectionItems); IAction action = new DeleteTimersAction(timers, workbenchWindow, "Cut"); action.run(); } // reselect(selection); } catch (SWTError error) { /* * Copy to clipboard failed. This happens when another * application is accessing the clipboard while we copy. Ignore * the error. */ } } return null; }