List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:at.bitandart.zoubek.mervin.comments.CommentsView.java
License:Open Source License
/** * extracts all EObject link targets from the given selection. * //from w ww.ja v a 2 s.c om * @param selection * the selection containing the link targets. * @return a list of EObject link targets, does not return null. */ private List<EObject> extractLinkTargets(IStructuredSelection selection) { List<EObject> targets = new ArrayList<EObject>(selection.size()); Iterator<?> iterator = selection.iterator(); while (iterator.hasNext()) { Object element = iterator.next(); if (element instanceof EObject) { targets.add((EObject) element); } else if (element instanceof GraphicalEditPart) { // GMF edit part -> use semantic model EObject semanticElement = ((GraphicalEditPart) element).resolveSemanticElement(); targets.add(extractFromTemporaryContainer(semanticElement)); } else if (element instanceof ConnectionEditPart) { // GMF edit part -> use semantic model EObject semanticElement = ((ConnectionEditPart) element).resolveSemanticElement(); targets.add(extractFromTemporaryContainer(semanticElement)); } else if (element instanceof EditPart) { // GEF edit part -> use model if it is an EObject Object model = ((EditPart) element).getModel(); if (model instanceof EObject) { targets.add((EObject) model); } } } return targets; }
From source file:at.bitandart.zoubek.mervin.property.diff.PropertyDiffView.java
License:Open Source License
/** * creates the input object for the tree diff viewer based on the given * selection.//from www.ja v a 2 s . c o m * * @param selection * the selection used to create the input object for. * @return the input object for the tree diff viewer. */ private Object createInputFromSelection(IStructuredSelection selection) { Comparison comparison = getComparison(selection); List<SelectionEntry> modelEntries = new ArrayList<>(selection.size()); Iterator<?> selectionIterator = selection.iterator(); int selectionIndex = 1; while (selectionIterator.hasNext()) { Object object = selectionIterator.next(); EObject selectedSemanticModelElement = diagramModelHelper.getSemanticModel(object); View selectedNotationModelElement = diagramModelHelper.getNotationModel(object); ModelReview currentModelReview = getCurrentModelReview(); if (currentModelReview != null) { View originalNotationModelElement = (View) currentModelReview.getUnifiedModelMap().inverse() .get(selectedNotationModelElement); if (originalNotationModelElement != null) { selectedNotationModelElement = originalNotationModelElement; } } Match semanticModelMatch = comparison.getMatch(selectedSemanticModelElement); Match notationModelMatch = comparison.getMatch(selectedNotationModelElement); /* * create an entry only if the selection contains a model element * contained in the comparison */ if (semanticModelMatch != null || notationModelMatch != null) { SelectionEntry modelEntry = new SelectionEntry("#" + selectionIndex, semanticModelMatch, notationModelMatch); modelEntries.add(modelEntry); // TODO add other (referencing, context, etc...) notation models selectionIndex++; } } return modelEntries; }
From source file:at.bitandart.zoubek.mervin.review.HighlightSelectionListener.java
License:Open Source License
@Override public void selectionChanged(SelectionChangedEvent event) { ModelReview review = part.getHighlightedModelReview(); ISelection selection = event.getSelection(); if (part.getHighlightMode() == HighlightMode.SELECTION && review != null) { IReviewHighlightService highlightService = part.getReviewHighlightService(); highlightService.clearHighlights(review); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Iterator<?> iterator = structuredSelection.iterator(); while (iterator.hasNext()) { highlightService.addHighlightFor(review, iterator.next()); }/*from w ww. j av a2s .c om*/ } } }
From source file:at.spardat.xma.guidesign.presentation.action.GuidesignActionBarContributor.java
License:Open Source License
/** * @param sels the currently selected object in the workbench * @return a collection of actions dependend of the type of the selection object *///from ww w . j a va2 s. c o m private Collection generateEditActions(IStructuredSelection sels) { Collection actions = new LinkedList(); Object selection = null; if (((IStructuredSelection) sels).size() == 1) { selection = ((IStructuredSelection) sels).getFirstElement(); //create edit action for all xmawidget that may have Formdata if (selection instanceof XMAWidget && !(selection instanceof HiddenWidget) && !(selection instanceof PageComposite) && !(selection instanceof IGeneratable && ((IGeneratable) selection).isYnGenerated())) { actions.add(new EditFormDataAction("FormData", (XMAWidget) selection, activeEditorPart)); } //create edit action for xmacomponent that may have xma properties if (selection instanceof XMAComponent) { actions.add(new EditComponentPropertyAction("Component Property", (XMAComponent) selection, activeEditorPart)); } //only showable xmawidget may have validator if (selection instanceof IFormaterAttachable && !(selection instanceof IGeneratable && ((IGeneratable) selection).isYnGenerated())) { actions.add( new EditValidatorAction("Validator", (IFormaterAttachable) selection, activeEditorPart)); } //only showable xmawidget is a table with more than 1 columns if (selection instanceof XMATable && ((XMATable) selection).getColumn().size() > 0 && !(selection instanceof IGeneratable && ((IGeneratable) selection).isYnGenerated())) { actions.add(new EditCalculateTablelayoutAction("Calculate Layout", (XMATable) selection, activeEditorPart)); } } else { // we have more than one selection ArrayList selWids = new ArrayList(); for (Iterator it = sels.iterator(); it.hasNext();) { Object selObj = it.next(); if (selObj instanceof XMAWidget && !(selObj instanceof HiddenWidget) && !(selObj instanceof PageComposite)) { selWids.add(selObj); } } if (selWids.size() > 1) { actions.add(new MultiEditFormDataAction("FormData (multi selection)", selWids, activeEditorPart)); } } return actions; }
From source file:at.spardat.xma.guidesign.presentation.NewComponentWizard.java
License:Open Source License
public static IResource getSelectedResource(IStructuredSelection selection) { // Try and get the resource selection to determine a current directory for the file dialog. IResource selectedResource = null;/*from ww w . jav a 2 s . c o m*/ if (selection != null && !selection.isEmpty()) { // Get the resource... // Object selectedElement = selection.iterator().next(); if (selectedElement instanceof IResource) { // Get the resource parent, if its a file. // selectedResource = (IResource) selectedElement; if (selectedResource.getType() == IResource.FILE) { selectedResource = selectedResource.getParent(); } } } return selectedResource; }
From source file:au.gov.ga.earthsci.application.handlers.ShowViewDialog.java
License:Apache License
@Override protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); composite.setLayout(new FillLayout()); TableViewer viewer = new TableViewer(composite, SWT.NONE); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new PartLabelProvider()); //TODO this part collection is simply a list of parts that have been shown before //need to improve this collection so that it removes duplicates, and also contains //parts that are registered but have never been displayed viewer.setInput(application.getDescriptors()); viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override/*from w w w.j a va 2 s. c om*/ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection s = (IStructuredSelection) event.getSelection(); selection = new MPartDescriptor[s.size()]; Iterator<?> iterator = s.iterator(); for (int i = 0; iterator.hasNext(); i++) { MPartDescriptor part = (MPartDescriptor) iterator.next(); selection[i++] = part; } } }); return composite; }
From source file:au.gov.ga.earthsci.application.parts.layer.LayerTreeDragSourceListener.java
License:Apache License
@Override public void dragFinished(DragSourceEvent event) { if (!event.doit) return;//from w w w . j av a2 s. c o m //if the gadget was moved, remove it from the source viewer if (event.detail == DND.DROP_MOVE) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); for (Iterator<?> it = selection.iterator(); it.hasNext();) { ILayerTreeNode node = (ILayerTreeNode) it.next(); node.removeFromParent(); } viewer.refresh(); } }
From source file:au.gov.ga.earthsci.layer.ui.LayerTreeDragSourceListener.java
License:Apache License
@Override public void dragFinished(DragSourceEvent event) { if (!event.doit) { return;/*from w ww . j av a 2s. com*/ } //if the gadget was moved, remove it from the source viewer if (isMoveEvent(event)) { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); for (Iterator<?> it = selection.iterator(); it.hasNext();) { ILayerTreeNode node = (ILayerTreeNode) it.next(); node.removeFromParent(); } viewer.refresh(); } }
From source file:bndtools.editor.components.ComponentListPart.java
License:Open Source License
void createSection(Section section, FormToolkit toolkit) { section.setText(Messages.ComponentListPart_listSectionTitle); Composite composite = toolkit.createComposite(section); section.setClient(composite);// w ww. j av a 2 s .com table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); viewer = new TableViewer(table); viewer.setUseHashlookup(true); viewer.setContentProvider(new ArrayContentProvider()); viewer.setLabelProvider(new ServiceComponentLabelProvider()); final Button btnAdd = toolkit.createButton(composite, Messages.ComponentListPart_addButton, SWT.PUSH); final Button btnRemove = toolkit.createButton(composite, Messages.ComponentListPart_RemoveButton, SWT.PUSH); toolkit.paintBordersFor(section); // Listeners viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); ArrayList<ServiceComponent> selectedComponents = new ArrayList<ServiceComponent>(selection.size()); @SuppressWarnings("rawtypes") Iterator iterator = selection.iterator(); while (iterator.hasNext()) { String name = (String) iterator.next(); ServiceComponent component = componentMap.get(name); if (component != null) selectedComponents.add(component); } managedForm.fireSelectionChanged(ComponentListPart.this, new StructuredSelection(selectedComponents)); btnRemove.setEnabled(!selection.isEmpty()); } }); viewer.addOpenListener(new IOpenListener() { public void open(OpenEvent event) { String name = (String) ((IStructuredSelection) event.getSelection()).getFirstElement(); if (name != null) { doOpenComponent(name); } } }); viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ResourceTransfer.getInstance() }, new ComponentListDropAdapter(viewer)); btnAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { try { doAdd(); } catch (Exception x) { Plugin.logError("Error adding component", x); } } }); btnRemove.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { doRemove(); } }); // Layout GridData gd; section.setLayoutData(new GridData(GridData.FILL_BOTH)); composite.setLayout(new GridLayout(2, false)); gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 3); gd.widthHint = 250; table.setLayoutData(gd); btnAdd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); }
From source file:bndtools.editor.contents.PrivatePackagesPart.java
License:Open Source License
private void doRemovePackages() { IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (!selection.isEmpty()) { Iterator<?> elements = selection.iterator(); List<Object> removed = new LinkedList<Object>(); while (elements.hasNext()) { Object pkg = elements.next(); if (packages.remove(pkg)) removed.add(pkg);//from w w w .j a v a2 s. com } if (!removed.isEmpty()) { viewer.remove(removed.toArray()); markDirty(); } } }