List of usage examples for org.eclipse.jface.viewers StructuredSelection iterator
@Override
public Iterator iterator()
From source file:org.eclipse.ajdt.internal.ui.wizards.SuperInterfaceSelectionDialog.java
License:Open Source License
private void addSelectedInterfaces() { StructuredSelection selection = getSelectedItems(); if (selection == null) return;/*from ww w.j a v a 2 s . c o m*/ for (Iterator iter = selection.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof TypeNameMatch) { accessedHistoryItem(obj); TypeNameMatch type = (TypeNameMatch) obj; String qualifiedName = getNameWithTypeParameters(type.getType()); String message; if (fTypeWizardPage.addSuperInterface(qualifiedName)) { message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info, BasicElementLabels.getJavaElementName(qualifiedName)); } else { message = Messages.format( NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info, BasicElementLabels.getJavaElementName(qualifiedName)); } updateStatus(new StatusInfo(IStatus.INFO, message)); } } }
From source file:org.eclipse.birt.report.designer.internal.ui.editors.parts.GraphicalEditorWithFlyoutPalette.java
License:Open Source License
private List getModelList(ISelection selection) { List list = new ArrayList(); if (selection == null) return list; if (!(selection instanceof StructuredSelection)) return list; StructuredSelection structured = (StructuredSelection) selection; if (structured.getFirstElement() instanceof ReportElementEditPart) { boolean bool = false; for (Iterator it = structured.iterator(); it.hasNext();) { ReportElementEditPart object = (ReportElementEditPart) it.next(); if (object instanceof DummyEditpart) { list.add(object.getModel()); bool = true;//www . ja va 2 s .c o m } if (!bool) { list.add(object.getModel()); } } } else { list = structured.toList(); } return list; }
From source file:org.eclipse.birt.report.designer.internal.ui.views.property.ReportPropertySheetPage.java
License:Open Source License
/** * @param selection/* w w w . j av a 2s . co m*/ * @return */ private List<Object> getModelList(ISelection selection) { List<Object> list = new ArrayList<Object>(); if (selection == null) return list; if (!(selection instanceof StructuredSelection)) return list; StructuredSelection structured = (StructuredSelection) selection; if (structured.getFirstElement() instanceof ReportElementEditPart) { for (Iterator it = structured.iterator(); it.hasNext();) { ReportElementEditPart object = (ReportElementEditPart) it.next(); if (object instanceof DummyEditpart) { list.clear(); list.add(object.getModel()); break; } list.add(object.getModel()); } } else { list = structured.toList(); if (list != null && list.size() > 0) { List<Object> modelList = new ArrayList<Object>(); for (int i = 0; i < list.size(); i++) { Object obj = list.get(i); if (obj instanceof IAdaptable) { Object realModel = ((IAdaptable) obj).getAdapter(DesignElementHandle.class); if (realModel != null) modelList.add(realModel); else modelList.add(obj); } else modelList.add(obj); } list = modelList; } } return list; }
From source file:org.eclipse.birt.report.designer.ui.views.attributes.AttributeViewPage.java
License:Open Source License
/** * Parse out the DE models for all kinds of input source. * //w w w . j a v a 2s .c o m * @param selection * the current selection. * @return */ protected List getModelList(ISelection selection) { List list = new ArrayList(); if (selection == null) return list; if (!(selection instanceof StructuredSelection)) return list; StructuredSelection structured = (StructuredSelection) selection; if (structured.getFirstElement() instanceof ReportElementEditPart) { boolean bool = false; for (Iterator it = structured.iterator(); it.hasNext();) { ReportElementEditPart object = (ReportElementEditPart) it.next(); if (object instanceof DummyEditpart) { list.add(object.getModel()); bool = true; } if (!bool) { list.add(object.getModel()); } } } else { list = structured.toList(); } return list; }
From source file:org.eclipse.cdt.mylyn.internal.ui.CDTEditorMonitor.java
License:Open Source License
/** * Only public for testing//w ww. j a v a2 s. co m */ @Override public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) { try { ICElement selectedElement = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.equals(currentSelection)) { return; } currentSelection = structuredSelection; // Object selectedObject = // structuredSelection.getFirstElement(); for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); if (selectedObject instanceof ICElement) { ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary((ICElement) selectedObject); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } if (selectedElement != null) { super.handleElementSelection(part, selectedElement, contributeToContext); } } } else { if (part instanceof CEditor) { currentEditor = (CEditor) part; selectedElement = SelectionConverter.getElementAtOffset(currentEditor); if (selectedElement == null) return; // nothing selected if (selectedElement != null) { if (selectedElement.equals(lastSelectedElement)) { super.handleElementEdit(part, selectedElement, contributeToContext); } else if (!selectedElement.equals(lastSelectedElement)) { super.handleElementSelection(part, selectedElement, contributeToContext); } } ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } } if (selectedElement != null) { lastSelectedElement = selectedElement; } } catch (CModelException e) { // ignore, fine to fail to resolve an element if the model is not // up-to-date } }
From source file:org.eclipse.datatools.sqltools.sqlbuilder.views.SQLTreeViewer.java
License:Open Source License
/** * Override this method to fill in the popup context menu for each MOF object *///from w w w .j av a 2s.c o m public void fillContextMenu() { ISelection selection = this.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; Object element = null; if (structuredSelection.iterator().hasNext()) { element = structuredSelection.iterator().next(); } if (element instanceof QuerySelect) { //createWithTableAction.setElement(element); //commented bcz it was causing NPE //menu.add(createWithTableAction); QuerySelect select = (QuerySelect) element; //add Delete menu if the QuerySelect is part of a Full Select if (select.getCombinedLeft() != null || select.getCombinedRight() != null) { deleteStatementAction.setElement(element); menu.add(deleteStatementAction); convertToFullSelectAction.setElement(element); menu.add(convertToFullSelectAction); } if (select.eContainer() instanceof WithTableSpecification) { convertToFullSelectAction.setElement(element); menu.add(convertToFullSelectAction); } } else if (element instanceof QueryCombined) { QueryCombined queryCombined = (QueryCombined) element; if (!SelectHelper.isNodeFull(queryCombined)) { addSubSelectAction.setElement(element); menu.add(addSubSelectAction); addValuesAction.setElement(element); menu.add(addValuesAction); addSubFullSelectAction.setElement(element); menu.add(addSubFullSelectAction); } deleteStatementAction.setElement(element); menu.add(deleteStatementAction); changeSetOperatorAction.setElement(queryCombined); menu.add(changeSetOperatorAction); // menu.add(new Separator()); //executeStatementAction.setElement(element); //menu.add(executeStatementAction); // // Only enable the Add With and Add Value action for DB2 family // if (domainModel.getVendor().isDB2() && !domainModel.getVendor().isDB2UDBOS390_V6()) { addValuesAction.setEnabled(true); } else { addValuesAction.setEnabled(false); } // Enable the Add Values action for Cloudscape if (domainModel.getVendor().isCloudscape()) { addValuesAction.setEnabled(true); } } else if (element instanceof QueryValues) { addValueRowAction.setElement(element); menu.add(addValueRowAction); menu.add(new Separator()); deleteStatementAction.setElement(element); menu.add(deleteStatementAction); } else if (element instanceof ValuesRow) { deleteStatementAction.setElement(element); menu.add(deleteStatementAction); } else if (element instanceof WithTableSpecification) { deleteStatementAction.setElement(element); menu.add(deleteStatementAction); //executeStatementAction.setElement(element); //menu.add(executeStatementAction); } else if (element instanceof QueryExpressionRoot || element instanceof QuerySelectStatement) { createWithTableAction.setElement(element); menu.add(createWithTableAction); if (element instanceof QuerySelectStatement && SelectHelper.getQuerySelect((QuerySelectStatement) element) != null) { convertToFullSelectAction.setElement(element); menu.add(convertToFullSelectAction); } menu.add(new Separator()); menu.add(changeStatementTypeAction); } else if (element instanceof QueryInsertStatement) { addTableAction.setElement(element); menu.add(addTableAction); menu.add(new Separator()); menu.add(changeStatementTypeAction); //executeStatementAction.setElement(element); //menu.add(executeStatementAction); } else if (element instanceof QueryUpdateStatement) { addTableAction.setElement(element); menu.add(addTableAction); menu.add(new Separator()); menu.add(changeStatementTypeAction); //executeStatementAction.setElement(element); //menu.add(executeStatementAction); } else if (element instanceof QueryDeleteStatement) { addTableAction.setElement(element); menu.add(addTableAction); menu.add(new Separator()); menu.add(changeStatementTypeAction); //executeStatementAction.setElement(element); //menu.add(executeStatementAction); } } enableMenus(); }
From source file:org.eclipse.dltk.internal.mylyn.DLTKEditingMonitor.java
License:Open Source License
/** * Only public for testing. Note: Two sequential selections on the same element are deemed to be an edit of the * selection as this is the best guess that can be made. See bug 252306. *//* w ww . j a v a 2s . c o m*/ @Override public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection, boolean contributeToContext) { try { IModelElement selectedElement = null; if (selection instanceof StructuredSelection) { StructuredSelection structuredSelection = (StructuredSelection) selection; if (structuredSelection.equals(currentSelection)) { return; } currentSelection = structuredSelection; for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) { Object selectedObject = iterator.next(); if (selectedObject instanceof IModelElement) { IModelElement checkedElement = checkIfAcceptedAndPromoteIfNecessary( (IModelElement) selectedObject); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } if (selectedElement != null) { super.handleElementSelection(part, selectedElement, contributeToContext); } } } else { if (selection instanceof TextSelection && part instanceof IEditorPart) { currentEditor = (IEditorPart) part; TextSelection textSelection = (TextSelection) selection; selectedElement = SelectionConverter.resolveEnclosingElement(currentEditor, textSelection); if (selectedElement instanceof IPackageDeclaration) { // HACK: ignoring these selections return; } IModelElement[] resolved = SelectionConverter.codeResolve(currentEditor); if (resolved != null && resolved.length == 1 && !resolved[0].equals(selectedElement)) { lastResolvedElement = resolved[0]; } boolean selectionResolved = false; if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) { // navigation between two elements if (lastResolvedElement != null && lastSelectedElement != null && lastResolvedElement.equals(selectedElement) && !lastSelectedElement.equals(lastResolvedElement)) { super.handleNavigation(part, selectedElement, DLTKReferencesProvider.ID, contributeToContext); selectionResolved = true; } else if (lastSelectedElement != null && lastSelectedElement.equals(lastResolvedElement) && !lastSelectedElement.equals(selectedElement)) { super.handleNavigation(part, selectedElement, DLTKReferencesProvider.ID, contributeToContext); selectionResolved = true; } } else if (selectedElement != null && lastSelectedElement != null && !lastSelectedElement.equals(selectedElement)) { if (lastSelectedElement.getElementName().equals(selectedElement.getElementName())) { // navigation between two elements if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) { super.handleNavigation(part, selectedElement, DLTKImplementorsProvider.ID, contributeToContext); selectionResolved = true; } else if (selectedElement instanceof IType && lastSelectedElement instanceof IType) { super.handleNavigation(part, selectedElement, DLTKImplementorsProvider.ID, contributeToContext); selectionResolved = true; } } } if (selectedElement != null) { // selection of an element if (!selectionResolved && selectedElement.equals(lastSelectedElement)) { super.handleElementEdit(part, selectedElement, contributeToContext); } else if (!selectedElement.equals(lastSelectedElement)) { super.handleElementSelection(part, selectedElement, contributeToContext); } } IModelElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement); if (checkedElement == null) { return; } else { selectedElement = checkedElement; } } } if (selectedElement != null) { lastSelectedElement = selectedElement; } } catch (ModelException e) { // ignore, fine to fail to resolve an element if the model is not up-to-date } catch (Throwable t) { StatusHandler.log(new Status(IStatus.ERROR, DLTKUiBridgePlugin.ID_PLUGIN, "Failed to update model based on selection", t)); //$NON-NLS-1$ } }
From source file:org.eclipse.edt.ide.egldoc.actions.GenerateEGLDoc.java
License:Open Source License
protected Map<IEGLProject, Set<PartKey>> gatherParts(StructuredSelection selection, IProgressMonitor monitor) throws CoreException { monitor.subTask(Messages.GatheringParts); Map<IEGLProject, Set<PartKey>> parts = new HashMap<IEGLProject, Set<PartKey>>(); for (Iterator it = selection.iterator(); it.hasNext();) { Object next = it.next();/* w w w.j a va 2s . c om*/ if (next instanceof IProject && ((IProject) next).hasNature(EGLCore.NATURE_ID)) { IEGLProject project = EGLCore.create((IProject) next); if (project.exists() && project.isOpen()) { gatherParts(project, parts, monitor); } } } return parts; }
From source file:org.eclipse.emf.cdo.dawn.examples.acore.diagram.sheet.AcorePropertySection.java
License:Open Source License
/** * @generated/* ww w. j a v a 2s .co m*/ */ @Override public void setInput(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty() || false == selection instanceof StructuredSelection) { super.setInput(part, selection); return; } 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.emf.ecoretools.internal.views.EcoreToolsViewsDragTargetAdapter.java
License:Open Source License
/** * {@inheritDoc}//from w w w. j a va 2s .c om * * @see org.eclipse.swt.dnd.DragSourceAdapter#dragStart(org.eclipse.swt.dnd.DragSourceEvent) */ @Override public void dragStart(final DragSourceEvent event) { final ISelection selection = provider.getSelection(); if (selection instanceof StructuredSelection) { StructuredSelection sSelection = (StructuredSelection) selection; List<EObject> ecoreObjects = new ArrayList<EObject>(sSelection.size()); Iterator<Object> it = sSelection.iterator(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof EObject) { ecoreObjects.add((EObject) obj); } else if (obj instanceof WrappedEClass) { ecoreObjects.add(((WrappedEClass) obj).getWrappedEClass()); } } ISelection unwrapped = new StructuredSelection(ecoreObjects); LocalSelectionTransfer.getInstance().setSelection(unwrapped); LocalSelectionTransfer.getInstance().setSelectionSetTime(event.time & 0xFFFFFFFFL); event.doit = true; } }