List of usage examples for org.eclipse.jface.viewers IStructuredSelection toArray
public Object[] toArray();
From source file:com.google.dart.tools.designer.editor.UndoManager.java
License:Open Source License
/** * Remembers selected/expanded elements for current source. *///from w ww .jav a2 s . c om private void rememberState() { // selection { // prepare selected objects Object[] selectedObjects; { IStructuredSelection structuredSelection = (IStructuredSelection) m_selectionProvider .getSelection(); selectedObjects = structuredSelection.toArray(); } // remember int[][] paths = m_objectPathHelper.getObjectsPaths(selectedObjects); //m_sourceToSelection.put(m_currentSource, paths); m_dumpToSelection.put(m_currentDump, paths); } // expanded { Object[] expandedObjects = m_componentsTree.getExpandedElements(); int[][] paths = m_objectPathHelper.getObjectsPaths(expandedObjects); m_dumpToExpanded.put(m_currentDump, paths); } }
From source file:com.google.dart.tools.internal.corext.refactoring.reorg.RenameSelectionState.java
License:Open Source License
public void restore(Object newElement) { if (fDisplay == null) { return;//from w ww. ja va 2 s.c o m } 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() { @Override public void run() { target.selectReveal(newSelection[0]); } }); } } }
From source file:com.google.dart.tools.internal.search.ui.text.FileSearchPage.java
License:Open Source License
@Override protected void fillContextMenu(IMenuManager mgr) { super.fillContextMenu(mgr); addSortActions(mgr);// ww w. ja v a 2 s . co m fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection())); fActionGroup.fillContextMenu(mgr); FileSearchQuery query = (FileSearchQuery) getInput().getQuery(); if (query.getSearchString().length() > 0) { IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection(); if (!selection.isEmpty()) { ReplaceAction replaceSelection = new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), selection.toArray()); replaceSelection.setText(SearchMessages.ReplaceAction_label_selected); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection); } ReplaceAction replaceAll = new ReplaceAction(getSite().getShell(), (FileSearchResult) getInput(), null); replaceAll.setText(SearchMessages.ReplaceAction_label_all); mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll); } }
From source file:com.google.dart.tools.search.ui.text.AbstractTextSearchViewPage.java
License:Open Source License
/** * Note: this is internal API and should not be called from clients outside of the search plug-in. * <p>/*from w ww . j a v a 2 s . com*/ * Removes the currently selected match. Does nothing if no match is selected. * </p> * * @noreference This method is not intended to be referenced by clients. */ public void internalRemoveSelected() { AbstractTextSearchResult result = getInput(); if (result == null) { return; } StructuredViewer viewer = getViewer(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); HashSet<Match> set = new HashSet<Match>(); if (viewer instanceof TreeViewer) { ITreeContentProvider cp = (ITreeContentProvider) viewer.getContentProvider(); collectAllMatchesBelow(result, set, cp, selection.toArray()); } else { collectAllMatches(set, selection.toArray()); } navigateNext(true); Match[] matches = new Match[set.size()]; set.toArray(matches); result.removeMatches(matches); }
From source file:com.google.dart.tools.ui.actions.CleanFoldersAction.java
License:Open Source License
@Override protected void doRun(IStructuredSelection selection, Event event, UIInstrumentationBuilder instrumentation) { if (!selection.isEmpty()) { List<IProject> projects = new ArrayList<IProject>(); List<String> projectLoc = new ArrayList<String>(); for (Object sel : selection.toArray()) { projects.add((IProject) sel); projectLoc.add(((IProject) sel).getLocation().toOSString()); }/*from ww w .j av a2 s .c o m*/ if (DartCoreDebug.ENABLE_ANALYSIS_SERVER) { DartCore.getAnalysisServer().analysis_reanalyze(projectLoc); } else { CleanLibrariesJob job = new CleanLibrariesJob(projects); job.schedule(); } } }
From source file:com.google.dart.tools.ui.actions.CopyFilePathAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection) { if (isEnabled()) { IResource selectedResource = (IResource) (selection.toArray()[0]); String path = selectedResource.getLocation().toOSString(); copyToClipboard(path, getSite().getShell()); }/*from www . ja v a 2 s .c om*/ }
From source file:com.google.dart.tools.ui.actions.FormatAllAction.java
License:Open Source License
private CompilationUnit[] getCompilationUnits(IStructuredSelection selection) { HashSet<DartElement> result = new HashSet<DartElement>(); Object[] selected = selection.toArray(); for (int i = 0; i < selected.length; i++) { try {/*w w w. jav a 2 s.c o m*/ if (selected[i] instanceof DartElement) { DartElement elem = (DartElement) selected[i]; if (elem.exists()) { switch (elem.getElementType()) { case DartElement.TYPE: if (elem.getParent().getElementType() == DartElement.COMPILATION_UNIT) { result.add(elem.getParent()); } break; case DartElement.COMPILATION_UNIT: result.add(elem); break; case DartElement.LIBRARY: // collectCompilationUnits((DartLibrary) elem, result); break; case DartElement.DART_PROJECT: DartElement[] roots = ((DartProject) elem).getChildren(); for (int k = 0; k < roots.length; k++) { // collectCompilationUnits(roots[k], result); } break; } } } } catch (DartModelException e) { DartToolsPlugin.log(e); } } return result.toArray(new CompilationUnit[result.size()]); }
From source file:com.google.dart.tools.ui.actions.FormatAllAction.java
License:Open Source License
private boolean isEnabled(IStructuredSelection selection) { Object[] selected = selection.toArray(); for (int i = 0; i < selected.length; i++) { if (selected[i] instanceof DartElement) { DartElement elem = (DartElement) selected[i]; if (elem.exists()) { switch (elem.getElementType()) { case DartElement.TYPE: // for browsing perspective return elem.getParent().getElementType() == DartElement.COMPILATION_UNIT; case DartElement.COMPILATION_UNIT: return true; case DartElement.LIBRARY: return true; case DartElement.DART_PROJECT: return true; }/*from w w w . j av a 2 s . c o m*/ } } } return false; }
From source file:com.google.dart.tools.ui.actions.OpenAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection) { EmitInstrumentationCommand();/*from ww w . ja v a 2 s. c o m*/ if (!checkEnabled(selection)) { return; } run(selection.toArray()); }
From source file:com.google.dart.tools.ui.internal.actions.CleanUpAction.java
License:Open Source License
public CompilationUnit[] getCompilationUnits(IStructuredSelection selection) { Set<DartElement> result = Sets.newHashSet(); for (Object element : selection.toArray()) { collectCompilationUnits(element, result); }/*from w w w .j ava 2s. c om*/ CompilationUnit[] units = result.toArray(new CompilationUnit[result.size()]); units = DartModelUtil.getExistingCompilationUnits(units); units = DartModelUtil.getUniqueCompilationUnits(units); units = DartModelUtil.getNotPackageCompilationUnits(units); return units; }