List of usage examples for org.eclipse.jface.viewers StructuredSelection iterator
@Override
public Iterator iterator()
From source file:org.eclipse.mylyn.internal.team.ui.actions.AddToTaskContextAction.java
License:Open Source License
private void run(StructuredSelection selection) { if (!ContextCore.getContextManager().isContextActive()) { MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.AddToTaskContextAction_Add_to_Task_Context, Messages.AddToTaskContextAction_ACTIVATE_TASK_TO_ADD_RESOURCES); }/*ww w. j a va2 s . c om*/ Object element = selection.getFirstElement(); IResource[] resources = null; if (element instanceof ActiveChangeSet) { resources = ((ActiveChangeSet) element).getResources(); } else if (element instanceof DiffChangeSet) { resources = ((DiffChangeSet) element).getResources(); } else if (element instanceof LinkedTaskInfo) { LinkedTaskInfo linkedTaskInfo = (LinkedTaskInfo) element; ChangeSet changeSet = linkedTaskInfo.getChangeSet(); if (changeSet != null) { resources = changeSet.getResources(); } } Set<IResource> resourcesToAdd = new HashSet<IResource>(); if (resources != null) { resourcesToAdd.addAll(Arrays.asList(resources)); } else { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object object = iterator.next(); if (object instanceof IResource) { resourcesToAdd.add((IResource) object); } else if (object instanceof SynchronizeModelElement) { resourcesToAdd.add(((SynchronizeModelElement) object).getResource()); } else if (object instanceof IAdaptable) { Object adapted = ((IAdaptable) object).getAdapter(IResource.class); if (adapted != null) { resourcesToAdd.add((IResource) adapted); } } } } if (!resourcesToAdd.isEmpty()) { ResourcesUi.addResourceToContext(resourcesToAdd, InteractionEvent.Kind.SELECTION); } else { MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.AddToTaskContextAction_Add_to_Task_Context, Messages.AddToTaskContextAction_No_resources_to_add); } }
From source file:org.eclipse.mylyn.internal.xplanner.ui.wizard.XPlannerCustomQueryPage.java
License:Open Source License
private List<Integer> getSelectedContentIds() { ArrayList<Integer> selectedIds = new ArrayList<Integer>(); StructuredSelection selection = (StructuredSelection) projectsViewer.getSelection(); if (selection.size() == 0) { selectedIds.add(XPlannerAttributeMapper.INVALID_ID); } else {/*from w w w . j av a2 s . c o m*/ for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object selectedElement = iter.next(); if (selectedElement instanceof ProjectData) { selectedIds.add(((ProjectData) selectedElement).getId()); } else if (selectedElement instanceof IterationData) { selectedIds.add(((IterationData) selectedElement).getId()); } else if (selectedElement instanceof UserStoryData) { selectedIds.add(((UserStoryData) selectedElement).getId()); } } } return selectedIds; }
From source file:org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingConfiguration.java
License:Open Source License
private boolean validateSelections() { StructuredSelection selectedBaseIMembers = (StructuredSelection) _baseMethListViewer.getSelection(); for (Iterator iter = selectedBaseIMembers.iterator(); iter.hasNext();) { IMember baseIMember = (IMember) iter.next(); try {/* w ww .j a v a 2 s . co m*/ if (Flags.isAbstract(baseIMember.getFlags())) { _methMapBtnComp.deselectAll(); _methMapBtnComp.disableAll(); toggleApplyButton(); return false; } } catch (JavaModelException ex) { return false; } } StructuredSelection selectedRoleIMethod = (StructuredSelection) _roleMethListViewer.getSelection(); if (selectedRoleIMethod.isEmpty()) { return true; } IMethod roleMethod = (IMethod) selectedRoleIMethod.getFirstElement(); try { if (roleMethod.getElementName().equals(FAKED_METHOD_NAME)) { toggleModifierButtons(OT_CALLOUT_OVERRIDE | Modifier.OT_AFTER_CALLIN | Modifier.OT_BEFORE_CALLIN | Modifier.OT_REPLACE_CALLIN, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME) && !Flags.isCallin(roleMethod.getFlags()) && !Flags.isAbstract(roleMethod.getFlags())) { toggleModifierButtons(Modifier.OT_REPLACE_CALLIN | OT_CALLOUT, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } if (!roleMethod.getElementName().equals(FAKED_METHOD_NAME) && Flags.isCallin(roleMethod.getFlags()) && !Flags.isAbstract(roleMethod.getFlags())) { toggleModifierButtons( OT_CALLOUT_OVERRIDE | OT_CALLOUT | Modifier.OT_AFTER_CALLIN | Modifier.OT_BEFORE_CALLIN, DESELECT_DISABLE_BUTTONS); toggleApplyButton(); return false; } } catch (JavaModelException ex) { return false; } return true; }
From source file:org.eclipse.objectteams.otdt.internal.ui.bindingeditor.BindingConfiguration.java
License:Open Source License
private boolean createMethodMapping() { int methMapModifier = 0; boolean calloutOverride = false; boolean signatureFlag = true; _newCallout = true;/* www . j a v a 2 s .c o m*/ Button selectedButton = _methMapBtnComp.getSelectedButton(); if (_calloutBtn.equals(selectedButton)) { methMapModifier = 0; _newCallout = true; } if (_calloutOverrideBtn.equals(selectedButton)) { calloutOverride = true; methMapModifier = 0; _newCallout = true; } if (_callinReplaceBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_REPLACE_CALLIN; _newCallout = false; } if (_callinBeforeBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_BEFORE_CALLIN; _newCallout = false; } if (_callinAfterBtn.equals(selectedButton)) { methMapModifier = Modifier.OT_AFTER_CALLIN; _newCallout = false; } StructuredSelection selectedRoleMethod = (StructuredSelection) _roleMethListViewer.getSelection(); if (selectedRoleMethod.isEmpty()) { return false; } StructuredSelection selectedBaseMethods = (StructuredSelection) _baseMethListViewer.getSelection(); if (selectedBaseMethods.isEmpty()) { return false; } IMethod roleMethod = (IMethod) selectedRoleMethod.getFirstElement(); IMember[] baseMethods = new IMember[selectedBaseMethods.size()]; int baseMethodsCount = 0; for (Iterator iter = selectedBaseMethods.iterator(); iter.hasNext();) { IMember baseMethod = (IMember) iter.next(); baseMethods[baseMethodsCount++] = baseMethod; } AST ast = _selectedRole.getAST(); if (_newCallout) { if (baseMethods[0] instanceof IField) { this._calloutMappings = new CalloutMappingDeclaration[] { createCalloutMapping(ast, roleMethod, baseMethods[0], Modifier.OT_GET_CALLOUT, calloutOverride, signatureFlag), createCalloutMapping(ast, roleMethod, baseMethods[0], Modifier.OT_SET_CALLOUT, calloutOverride, signatureFlag) }; return this._calloutMappings[0] != null && this._calloutMappings[1] != null; } else { this._calloutMappings = new CalloutMappingDeclaration[] { createCalloutMapping(ast, roleMethod, baseMethods[0], methMapModifier, calloutOverride, signatureFlag) }; return this._calloutMappings[0] != null; } } else { return createCallinMapping(ast, roleMethod, baseMethods, methMapModifier, signatureFlag); } }
From source file:org.eclipse.osee.ote.ui.test.manager.actions.AddToTestManagerPopupAction.java
License:Open Source License
public static String[] getSelection() { StructuredSelection sel = AWorkspace.getSelection(); Iterator<?> i = sel.iterator(); List<String> selection = new ArrayList<String>(); while (i.hasNext()) { Object obj = i.next();// w w w.ja va 2 s.c om if (obj instanceof IResource) { IResource resource = (IResource) obj; if (resource != null) { selection.add(resource.getLocation().toOSString()); } } else if (obj instanceof ICompilationUnit) { ICompilationUnit resource = (ICompilationUnit) obj; if (resource != null) { selection.add(resource.getResource().getLocation().toOSString()); } } } return selection.toArray(new String[0]); }
From source file:org.eclipse.osee.ote.ui.test.manager.preferences.environment.EnvironmentPageEventHandler.java
License:Open Source License
public void handleRemoveSelectedViewEvent() { StructuredSelection sel = (StructuredSelection) treeViewer.getSelection(); if (!sel.isEmpty()) { Iterator<?> it = sel.iterator(); while (it.hasNext()) { TreeObject leaf = (TreeObject) it.next(); if (leaf instanceof TreeParent) { treeInputList.remove(leaf); environmentPageDataViewer.setNodeToDisplay(null); } else { leaf.getParent().removeChild(leaf); environmentPageDataViewer.update(); }// w w w . j ava 2s .com } treeViewer.refresh(); } }
From source file:org.eclipse.papyrus.customization.properties.util.ActionUtil.java
License:Open Source License
/** * EMF can only handle ISelection containing EObjects. However, as the * customization plugin relies a lot on EMF Facet, we often have to handle * objects that can be adapted to EObjects, but are not EObjects * themselves. This method adapts a ISelection of such objects to their * underlying EObjects, so that EMF can handle them. * Objects that cannot be adapted remain as-is in the selection. * // ww w .java 2 s . co m * @param sourceSelection * The selection to adapt * @return * The adapted selection */ public static ISelection getAdaptedSelection(ISelection sourceSelection) { if (sourceSelection instanceof StructuredSelection) { StructuredSelection currentSelection = (StructuredSelection) sourceSelection; List<Object> newSelection = new LinkedList<Object>(); Iterator<?> it = currentSelection.iterator(); while (it.hasNext()) { Object object = it.next(); if (object instanceof IAdaptable) { EObject eObject = (EObject) ((IAdaptable) object).getAdapter(EObject.class); if (eObject != null) newSelection.add(eObject); else newSelection.add(object); } } StructuredSelection selection = new StructuredSelection(newSelection); return selection; } else { return sourceSelection; } }
From source file:org.eclipse.papyrus.diagram.common.sheet.UMLPropertySection.java
License:Open Source License
public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return;/*from w w w .j a v a2 s. co m*/ } final StructuredSelection structuredSelection = ((StructuredSelection) selection); ArrayList transformedSelection = new ArrayList(structuredSelection.size()); for (Iterator it = structuredSelection.iterator(); it.hasNext();) { Object r = transformSelection(it.next()); if (r != null) { transformedSelection.add(r); } } super.setInput(part, new StructuredSelection(transformedSelection)); }
From source file:org.eclipse.pde.internal.ui.editor.actions.ToggleExpandStateAction.java
License:Open Source License
public void toggleExpandState(int state, StructuredSelection selection) { TreeItem[] items = fExtensionTree.getTree().getSelection(); if (state == NEEDS_EXPAND) { // expand sub tree traverseChildrenAndSetExpanded(items); // load non-expanded children fExtensionTree.refresh();//ww w.j a v a 2 s .c om expandChildrenElements(selection.toArray(), true); fExtensionTree.setSelection(selection, false); } else { // collapse sub tree for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { fExtensionTree.setExpandedState(iterator.next(), false); } } }
From source file:org.eclipse.php.composer.ui.editor.composer.AuthorSection.java
License:Open Source License
@SuppressWarnings("unchecked") private void handleRemove() { StructuredSelection selection = ((StructuredSelection) authorViewer.getSelection()); Iterator<Object> it = selection.iterator(); String[] names = new String[selection.size()]; List<Person> persons = new ArrayList<Person>(); for (int i = 0; it.hasNext(); i++) { Person person = (Person) it.next(); persons.add(person);//from ww w .j ava2 s . co m names[i] = person.getName(); } String title = selection.size() > 1 ? Messages.AuthorSection_RemoveDialogTitlePlural : Messages.AuthorSection_RemoveDialogTitle; MessageDialog diag = new MessageDialog(authorViewer.getTable().getShell(), title, null, NLS.bind(Messages.AuthorSection_RemoveDialogMessage, StringUtils.join(names, ", ")), //$NON-NLS-1$ MessageDialog.WARNING, new String[] { Messages.AuthorSection_YesButton, Messages.AuthorSection_NoButton }, 0); if (diag.open() == Dialog.OK) { for (Person person : persons) { composerPackage.getAuthors().remove(person); } } }