List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.google.dart.tools.ui.callhierarchy.LocationCopyAction.java
License:Open Source License
@Override public void run() { IStructuredSelection selection = (IStructuredSelection) locationViewer.getSelection(); StringBuffer buf = new StringBuffer(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { CallLocation location = (CallLocation) iterator.next(); buf.append(location.getLineNumber()).append('\t').append(location.getCallText()); buf.append('\n'); }// w ww. j ava2s. c om TextTransfer plainTextTransfer = TextTransfer.getInstance(); try { clipboard.setContents(new String[] { CopyCallHierarchyAction.convertLineTerminators(buf.toString()) }, new Transfer[] { plainTextTransfer }); } catch (SWTError e) { if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) { throw e; } if (MessageDialog.openQuestion(viewSite.getShell(), CallHierarchyMessages.CopyCallHierarchyAction_problem, CallHierarchyMessages.CopyCallHierarchyAction_clipboard_busy)) { run(); } } }
From source file:com.google.dart.tools.ui.callhierarchy.OpenLocationAction.java
License:Open Source License
@Override public void run(IStructuredSelection selection) { if (!checkEnabled(selection)) { return;/* w w w. j ava2 s.c om*/ } for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { boolean noError = CallHierarchyUI.openInEditor(iter.next(), getShell(), OpenStrategy.activateOnOpen()); if (!noError) { return; } } }
From source file:com.google.dart.tools.ui.callhierarchy.OpenLocationAction.java
License:Open Source License
private boolean checkEnabled(IStructuredSelection selection) { if (selection.isEmpty()) { return false; }//from w w w .j a v a 2s. c o m for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object element = iter.next(); if (element instanceof MethodWrapper) { continue; } else if (element instanceof CallLocation) { continue; } return false; } return true; }
From source file:com.google.dart.tools.ui.callhierarchy.RefreshElementAction.java
License:Open Source License
@Override public void run() { IStructuredSelection selection = (IStructuredSelection) getSelection(); if (selection.isEmpty()) { viewer.getPart().refresh();/* w w w . jav a 2 s. c o m*/ return; } List<MethodWrapper> toExpand = new ArrayList<MethodWrapper>(); for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { MethodWrapper element = (MethodWrapper) iter.next(); boolean isExpanded = viewer.getExpandedState(element); element.removeFromCache(); if (isExpanded) { viewer.setExpandedState(element, false); toExpand.add(element); } viewer.refresh(element); } for (Iterator<MethodWrapper> iter = toExpand.iterator(); iter.hasNext();) { MethodWrapper elem = iter.next(); viewer.setExpandedState(elem, true); } }
From source file:com.google.dart.tools.ui.callhierarchy.RemoveFromViewAction.java
License:Open Source License
/** * Checks whether this action can be added for the selected element in the call hierarchy. * /*from www. java 2 s. c o m*/ * @return <code> true</code> if the action can be added, <code>false</code> otherwise */ protected boolean canActionBeAdded() { IStructuredSelection selection = (IStructuredSelection) getSelection(); if (selection.isEmpty()) { return false; } Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object element = iter.next(); if (!(element instanceof MethodWrapper)) { return false; } } TreeItem[] items = callHierarchyViewer.getTree().getSelection(); for (int k = 0; k < items.length; k++) { if (!checkForChildren(items[k])) { return false; } } return true; }
From source file:com.google.dart.tools.ui.internal.actions.SelectionConverter.java
License:Open Source License
/** * Converts the given structured selection into an array of Java elements. An empty array is * returned if one of the elements stored in the structured selection is not of type * <code>DartElement</code>/*from w w w .j a v a2s.c o m*/ */ public static DartElement[] getElements(IStructuredSelection selection) { if (!selection.isEmpty()) { DartElement[] result = new DartElement[selection.size()]; int i = 0; for (Iterator<?> iter = selection.iterator(); iter.hasNext(); i++) { Object element = iter.next(); if (!(element instanceof DartElement)) { return EMPTY_RESULT; } result[i] = (DartElement) element; } return result; } return EMPTY_RESULT; }
From source file:com.google.dart.tools.ui.internal.filesview.FilesView.java
License:Open Source License
private static boolean allElementsAreProjects(IStructuredSelection selection) { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selectedElement = iterator.next(); if (!(selectedElement instanceof IProject)) { return false; }/*w w w . ja v a 2 s.c o m*/ } return true; }
From source file:com.google.dart.tools.ui.internal.filesview.FilesView.java
License:Open Source License
private static boolean allElementsAreResources(IStructuredSelection selection) { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selectedElement = iterator.next(); if (!(selectedElement instanceof IResource)) { return false; }/*from w ww .j av a 2s. co m*/ } return true; }
From source file:com.google.gwt.eclipse.core.clientbundle.ui.AddResourcesToClientBundleAction.java
License:Open Source License
public void selectionChanged(IAction action, ISelection selection) { // Reset our old initial selections project = null;/* w w w . j a v a 2s . com*/ clientBundleType = null; List<IFile> selectedFiles = new ArrayList<IFile>(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator<?> iter = structuredSelection.iterator(); while (iter.hasNext()) { Object element = iter.next(); IFile file = AdapterUtilities.getAdapter(element, IFile.class); if (file != null) { // Set initial project if it's not already set if (project == null) { project = file.getProject(); } // Try to set the initial ClientBundle type if it's not already set if (clientBundleType == null) { clientBundleType = findFirstTopLevelClientBundleType(file); if (clientBundleType != null) { // Ensure that initial project is the one containing the initial // ClientBundle type project = clientBundleType.getJavaProject().getProject(); } } // If the file looks like a ClientBundle resource, add it if (ClientBundleResource.isProbableClientBundleResource(file)) { selectedFiles.add(file); } } } } files = selectedFiles.toArray(new IFile[0]); }
From source file:com.google.gwt.eclipse.core.wizards.NewClientBundleWizardPage.java
License:Open Source License
private void initBundledResources(IJavaProject javaProject, IStructuredSelection selection) { List<ClientBundleResource> resources = new ArrayList<ClientBundleResource>(); Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object element = iter.next(); // Turn each file in the selection into a bundled resource IFile file = AdapterUtilities.getAdapter(element, IFile.class); if (file != null) { ClientBundleResource resource = ClientBundleResource.createFromFile(javaProject, file); if (resource != null) { resources.add(resource); }/*from ww w . j a va2s. c o m*/ } } bundledResourcesBlock.setResources(resources); }