Java Code Examples for org.eclipse.jface.viewers.IStructuredSelection#toArray()
The following examples show how to use
org.eclipse.jface.viewers.IStructuredSelection#toArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EnginePreferencesPage.java From thym with Eclipse Public License 1.0 | 6 votes |
@Override public boolean performOk() { IStructuredSelection sel = (IStructuredSelection) engineSection.getSelection(); if(sel.isEmpty()){ getPreferenceStore().setToDefault(PlatformConstants.PREF_DEFAULT_ENGINE); }else{ StringBuilder prefVal = new StringBuilder(); Object[] selections = sel.toArray(); for(int i=0; i< selections.length; i++){ HybridMobileEngine engine =(HybridMobileEngine) selections[i]; prefVal.append(engine.getName()); prefVal.append(":"); prefVal.append(engine.getSpec()); prefVal.append(","); } getPreferenceStore().setValue(PlatformConstants.PREF_DEFAULT_ENGINE, prefVal.toString()); } return true; }
Example 2
Source File: ResourcesView.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override protected void fillTimeEventContextMenu(@NonNull IMenuManager menuManager) { ISelection selection = getSite().getSelectionProvider().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection sSel = (IStructuredSelection) selection; if (sSel.getFirstElement() instanceof TimeGraphEntry) { TimeGraphEntry resourcesEntry = (TimeGraphEntry) sSel.getFirstElement(); ITmfTreeDataModel model = resourcesEntry.getEntryModel(); if (sSel.toArray()[1] instanceof NamedTimeEvent && ((ResourcesEntryModel) model).getType() == Type.CURRENT_THREAD) { ITmfTrace trace = getTrace(resourcesEntry); NamedTimeEvent event = (NamedTimeEvent) sSel.toArray()[1]; TmfTraceContext ctx = TmfTraceManager.getInstance().getCurrentTraceContext(); HostThread data = (HostThread) ctx.getData(HostThread.SELECTED_HOST_THREAD_KEY); if (data != null) { menuManager.add(new UnfollowThreadAction(ResourcesView.this)); } else { menuManager.add(new FollowThreadAction(ResourcesView.this, null, event.getValue(), trace)); } } } } super.fillTimeEventContextMenu(menuManager); }
Example 3
Source File: ExportTracePackageWizard.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public void init(IWorkbench workbench, IStructuredSelection selection) { fSelection = selection; for (Object item : selection.toArray()) { if (item instanceof TmfExperimentElement) { TmfExperimentElement experimentElement = (TmfExperimentElement) item; fSelectedTraces.add(experimentElement); for (TmfTraceElement expTrace : experimentElement.getTraces()) { TmfTraceElement trace = expTrace.getElementUnderTraceFolder(); if (!fSelectedTraces.contains(trace)) { fSelectedTraces.add(trace); } } } } setWindowTitle(Messages.ExportTracePackageWizardPage_Title); setNeedsProgressMonitor(true); }
Example 4
Source File: DuplicatedCode.java From JDeodorant with MIT License | 6 votes |
private CloneInstance[] getSelectedCloneInstances() { CloneInstance[] toReturn = new CloneInstance[] {}; IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection(); if(selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection)selection; Object[] selectedItems = structuredSelection.toArray(); if (selectedItems.length == 2) { if(selectedItems[0] instanceof CloneInstance && selectedItems[1] instanceof CloneInstance) { final CloneInstance instance1 = (CloneInstance) selectedItems[0]; final CloneInstance instance2 = (CloneInstance) selectedItems[1]; if (instance1.getBelongingCloneGroup().equals(instance2.getBelongingCloneGroup()) && !instance1.getStatus().equals(CloneInstanceStatus.TAMPERED) && !instance2.getStatus().equals(CloneInstanceStatus.TAMPERED)) { return new CloneInstance[] {instance1, instance2 }; } } } } return toReturn; }
Example 5
Source File: BaseDataProviderTimeGraphView.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Fill context menu * * @param menuManager * a menuManager to fill * @since 5.2 */ protected void fillTimeEventContextMenu(@NonNull IMenuManager menuManager) { ISelection selection = getSite().getSelectionProvider().getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection sSel = (IStructuredSelection) selection; for (Object element : sSel.toArray()) { if (element instanceof TimeEvent) { TimeEvent event = (TimeEvent) element; IContributionItem contribItem = createOpenSourceCodeAction(getPresentationProvider().getEventHoverToolTipInfo(event, getTimeGraphViewer().getSelectionBegin())); if (contribItem != null) { menuManager.add(contribItem); break; } } } } }
Example 6
Source File: JarImportWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Handles the package fragment root changed event. */ protected void handlePackageFragmentRootChanged() { if (fTreeViewer != null) { final IStructuredSelection selection= (IStructuredSelection) fTreeViewer.getSelection(); final Object[] elements= selection.toArray(); if (elements.length != 1) { setErrorMessage(JarImportMessages.JarImportWizardPage_select_single_jar); setPageComplete(false); return; } else { final JarImportData data= fWizard.getImportData(); final Object element= elements[0]; if (element instanceof IPackageFragmentRoot) data.setPackageFragmentRoot((IPackageFragmentRoot) element); else if (element instanceof IPackageFragment) { data.setPackageFragmentRoot((IPackageFragmentRoot) ((IJavaElement) element).getParent()); } else { setErrorMessage(JarImportMessages.JarImportWizardPage_select_single_jar); setPageComplete(false); } } } }
Example 7
Source File: LaunchShortcutUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static IStructuredSelection replaceWithJavaElementDelegates(IStructuredSelection selection, Class<? extends JavaElementDelegate> delegateType) { Object[] originalSelection = selection.toArray(); Object[] fakeSelection = new Object[originalSelection.length]; for(int i = 0; i < originalSelection.length; i++) { Object original = originalSelection[i]; if (original == null || original instanceof IJavaElement || original instanceof JavaElementDelegate || !(original instanceof IAdaptable)) { fakeSelection[i] = original; } else { JavaElementDelegate javaElementDelegate = Adapters.adapt(original, delegateType); if (javaElementDelegate != null) { fakeSelection[i] = javaElementDelegate; } else { fakeSelection[i] = original; } } } StructuredSelection newSelection = new StructuredSelection(fakeSelection); return newSelection; }
Example 8
Source File: HideWorkingSetAction.java From n4js with Eclipse Public License 1.0 | 6 votes |
@Override public void run() { final IStructuredSelection selection = getStructuredSelection(); final Object[] selectionElements = selection.toArray(); final WorkingSet[] selectedWorkingSets = Arrays2.filter(selectionElements, WorkingSet.class); final WorkingSetManager manager = selectedWorkingSets[0].getWorkingSetManager(); final WorkingSetDiffBuilder builder = new WorkingSetDiffBuilder(manager); final WorkingSet[] newAllItems = manager.getAllWorkingSets(); final List<WorkingSet> newItems = newArrayList(manager.getWorkingSets()); for (final WorkingSet toHide : selectedWorkingSets) { newItems.remove(toHide); } final Diff<WorkingSet> diff = builder.build(Iterables.toArray(newItems, WorkingSet.class), newAllItems); if (!diff.isEmpty()) { manager.updateState(diff); manager.saveState(new NullProgressMonitor()); manager.getWorkingSetManagerBroker().refreshNavigator(); } }
Example 9
Source File: N4JSProjectActionGroup.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void performSelectionChanged(final IStructuredSelection structuredSelection) { final Object[] array = structuredSelection.toArray(); final ArrayList<IProject> openProjects = new ArrayList<>(); final int selectionStatus = evaluateSelection(array, openProjects); final StructuredSelection sel = new StructuredSelection(openProjects); // If only projects are selected, disable this action group, as all of // the project-related contributions will be provided by default action providers enableContribution = (selectionStatus & NON_PROJECT_SELECTED) != 0; openAction.setEnabled(hasClosedProjectsInWorkspace()); enableOpenInContextMenu = (selectionStatus & CLOSED_PROJECTS_SELECTED) != 0 || (selectionStatus == 0 && array.length == 0 && hasClosedProjectsInWorkspace()); closeAction.selectionChanged(sel); closeUnrelatedAction.selectionChanged(sel); }
Example 10
Source File: AbstractWorkingSetWizardPage.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Moves selected elements in the tree into the table */ private void addTreeSelection() { IStructuredSelection selection= (IStructuredSelection) fTree.getSelection(); fSelectedElements.addAll(selection.toList()); Object[] selectedElements= selection.toArray(); fTable.add(selectedElements); fTree.remove(selectedElements); fTable.setSelection(selection); fTable.getControl().setFocus(); validateInput(); }
Example 11
Source File: WorkspaceSpecManager.java From tlaplus with MIT License | 5 votes |
/** * Sets the spec loaded */ public void setSelection(ISelection selection) { if (selection == null) { setSpecLoaded(null); return; } if (selection instanceof IStructuredSelection) { IStructuredSelection sSelection = (IStructuredSelection) selection; if (sSelection.toArray() instanceof Spec[]) { Spec[] specs = (Spec[]) sSelection.toArray(); if (specs.length == 0) { setSpecLoaded(null); } else if (specs.length == 1) { setSpecLoaded(specs[0]); } else { throw new IllegalArgumentException("Only one specification can be selected"); } } else { throw new IllegalArgumentException( "Workspace specification manager only accepts specification objects to be selected"); } } else { throw new IllegalArgumentException( "Workspace specification manager only accepts specification object in a StructuredSelection"); } }
Example 12
Source File: CleanUpAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public ICompilationUnit[] getCompilationUnits(IStructuredSelection selection) { HashSet<IJavaElement> result= new HashSet<IJavaElement>(); Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { Object element= selected[i]; collectCompilationUnits(element, result); } return result.toArray(new ICompilationUnit[result.size()]); }
Example 13
Source File: ExportProjectWizard.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void init(final IWorkbench workbench, final IStructuredSelection selection) { setDefaultPageImageDescriptor(GamaIcons.create("navigator/navigator.import.project2").descriptor()); final Object[] all = selection.toArray(); for (int i = 0; i < all.length; i++) { all[i] = ResourceManager.getResource(all[i]); } this.currentSelection = new StructuredSelection(all); }
Example 14
Source File: BaseHandler.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override public void setEnabled(Object evaluationContext) { // clear cached selection this.clearFileStores(); if (evaluationContext instanceof IEvaluationContext) { IEvaluationContext context = (IEvaluationContext) evaluationContext; Object value = context.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME); if (value instanceof ISelection) { ISelection selection = (ISelection) value; if (selection instanceof IStructuredSelection && selection.isEmpty() == false) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Object object : structuredSelection.toArray()) { if (object instanceof IProject || object instanceof IFolder || object instanceof IFile) { IResource resource = (IResource) object; IFileStore fileStore = EFSUtils.getFileStore(resource); if (this.isValid(fileStore)) { this.addFileStore(fileStore); } } } } } } }
Example 15
Source File: CleanUpAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private boolean isEnabled(IStructuredSelection selection) { Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { try { if (selected[i] instanceof IJavaElement) { IJavaElement elem= (IJavaElement)selected[i]; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.TYPE: return elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT; // for browsing perspective case IJavaElement.COMPILATION_UNIT: return true; case IJavaElement.IMPORT_CONTAINER: return true; case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot)elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); return (root.getKind() == IPackageFragmentRoot.K_SOURCE); case IJavaElement.JAVA_PROJECT: // https://bugs.eclipse.org/bugs/show_bug.cgi?id=65638 return true; } } } else if (selected[i] instanceof LogicalPackage) { return true; } else if (selected[i] instanceof IWorkingSet) { IWorkingSet workingSet= (IWorkingSet) selected[i]; return IWorkingSetIDs.JAVA.equals(workingSet.getId()); } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { JavaPlugin.log(e); } } } return false; }
Example 16
Source File: OpenProjectAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int evaluateSelection(IStructuredSelection selection, List<Object> allClosedProjects) { Object[] array= selection.toArray(); int selectionStatus = 0; for (int i= 0; i < array.length; i++) { Object curr= array[i]; if (isClosedProject(curr)) { if (allClosedProjects != null) allClosedProjects.add(curr); selectionStatus |= CLOSED_PROJECTS_SELECTED; } else { if (curr instanceof IWorkingSet) { IAdaptable[] elements= ((IWorkingSet) curr).getElements(); for (int k= 0; k < elements.length; k++) { Object elem= elements[k]; if (isClosedProject(elem)) { if (allClosedProjects != null) allClosedProjects.add(elem); selectionStatus |= CLOSED_PROJECTS_SELECTED; } } } selectionStatus |= OTHER_ELEMENTS_SELECTED; } } return selectionStatus; }
Example 17
Source File: JavaUIHelp.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Creates and returns a help context provider for the given part. * * @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, String contextId) { IStructuredSelection selection; try { selection= SelectionConverter.getStructuredSelection(part); } catch (JavaModelException ex) { JavaPlugin.log(ex); selection= StructuredSelection.EMPTY; } Object[] elements= selection.toArray(); return new JavaUIHelpContextProvider(contextId, elements); }
Example 18
Source File: WorkingSetDropAdapter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private void initializeState(Object target, ISelection s) { fWorkingSet= (IWorkingSet)target; fSelection= (IStructuredSelection)s; fElementsToAdds= fSelection.toArray(); fCurrentElements= new HashSet<IAdaptable>(Arrays.asList(fWorkingSet.getElements())); }
Example 19
Source File: FindBrokenNLSKeysAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean canEnable(IStructuredSelection selection) { Object[] selected= selection.toArray(); for (int i= 0; i < selected.length; i++) { try { if (selected[i] instanceof IJavaElement) { IJavaElement elem= (IJavaElement) selected[i]; if (elem.exists()) { switch (elem.getElementType()) { case IJavaElement.TYPE: if (elem.getParent().getElementType() == IJavaElement.COMPILATION_UNIT) { return true; } return false; case IJavaElement.COMPILATION_UNIT: return true; case IJavaElement.IMPORT_CONTAINER: return false; case IJavaElement.PACKAGE_FRAGMENT: case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot root= (IPackageFragmentRoot) elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); return (root.getKind() == IPackageFragmentRoot.K_SOURCE); case IJavaElement.JAVA_PROJECT: return true; } } } else if (selected[i] instanceof LogicalPackage) { return true; } else if (selected[i] instanceof IFile) { IFile file= (IFile)selected[i]; if ("properties".equalsIgnoreCase(file.getFileExtension())) //$NON-NLS-1$ return true; } else if (selected[i] instanceof IWorkingSet) { IWorkingSet workingSet= (IWorkingSet) selected[i]; return IWorkingSetIDs.JAVA.equals(workingSet.getId()); } } catch (JavaModelException e) { if (!e.isDoesNotExist()) { JavaPlugin.log(e); } } } return false; }
Example 20
Source File: RenameSelectionState.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void restore(Object newElement) { if (fDisplay == null) return; for (int i= 0; i < fParts.size(); i++) { IStructuredSelection currentSelection= fSelections.get(i); boolean changed= false; final ISetSelectionTarget target= (ISetSelectionTarget)fParts.get(i); final IStructuredSelection[] newSelection= new IStructuredSelection[1]; newSelection[0]= currentSelection; if (currentSelection instanceof TreeSelection) { TreeSelection treeSelection= (TreeSelection)currentSelection; TreePath[] paths= treeSelection.getPaths(); for (int p= 0; p < paths.length; p++) { TreePath path= paths[p]; if (path.getSegmentCount() > 0 && path.getLastSegment().equals(fElement)) { paths[p]= createTreePath(path, newElement); changed= true; } } if (changed) { newSelection[0]= new TreeSelection(paths, treeSelection.getElementComparer()); } } else { Object[] elements= currentSelection.toArray(); for (int e= 0; e < elements.length; e++) { if (elements[e].equals(fElement)) { elements[e]= newElement; changed= true; } } if (changed) { newSelection[0]= new StructuredSelection(elements); } } if (changed) { fDisplay.asyncExec(new Runnable() { public void run() { target.selectReveal(newSelection[0]); } }); } } }