List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:de.loskutov.eclipseskins.ui.ClosedPartListControl.java
License:Open Source License
/** * Delete all selected elements.//from w ww.jav a 2 s . co m * * @return <code>true</code> if there are no elements left after deletion. */ protected boolean deleteSelectedElements() { IStructuredSelection selection = getSelectedElements(); if (selection != null) { for (Iterator iterator = selection.iterator(); iterator.hasNext();) { ClosedPart closedPart = (ClosedPart) iterator.next(); closedPart.remove(); } if (tabArea.getClosedPartList().length == 0) { dispose(); } else { fTableViewer.refresh(); } return true; } return false; }
From source file:de.loskutov.eclipseskins.ui.PartListControl.java
License:Open Source License
/** * Delete all selected elements./* w ww. j a va 2 s.c o m*/ * * @return <code>true</code> if there are no elements left after deletion. */ protected boolean deleteSelectedElements() { IStructuredSelection selection = getSelectedElements(); if (selection != null) { ArrayList list = new ArrayList(selection.size()); for (Iterator iterator = selection.iterator(); iterator.hasNext();) { IPresentablePart presentablePart = (IPresentablePart) iterator.next(); list.add(presentablePart); } VSStackPresentation presentation = tabArea.getPresentation(); presentation.close((IPresentablePart[]) list.toArray(new IPresentablePart[list.size()])); IPresentablePart[] partList = presentation.getSite().getPartList(); if (partList == null || partList.length == 0) { dispose(); } return true; } return false; }
From source file:de.ovgu.cide.astview.ASTView.java
License:Open Source License
private List<IASTNode> getSelection() { List<IASTNode> result = new ArrayList<IASTNode>(); IStructuredSelection selection = (IStructuredSelection) fViewer.getSelection(); for (Iterator<Object> iter = selection.iterator(); iter.hasNext();) { Object element = iter.next(); if (element instanceof IASTNode) { result.add((IASTNode) element); }/* ww w . j av a2 s. c om*/ } return result; }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.actions.CalculateDependencyAction.java
License:Open Source License
/** * Checks if selection is valid, i.e. selection is not empty, not root and a feature from the feature model tree. * /* w w w .ja v a 2s .c o m*/ * @param selection the selected feature from the feature model tree * @return true if valid selection, else false */ private boolean isValidSelection(IStructuredSelection selection) { // check empty selection (i.e. ModelEditPart is selected) if (selection.size() == 1 && (selection.getFirstElement() instanceof ModelEditPart)) return false; selectedFeatures.clear(); Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object editPart = iter.next(); if (!(editPart instanceof FeatureEditPart) && !(editPart instanceof IFeature)) continue; IFeature feature; if (editPart instanceof FeatureEditPart) feature = ((FeatureEditPart) editPart).getFeature().getObject(); else feature = (IFeature) editPart; selectedFeatures.add(feature); } boolean res = !selectedFeatures.isEmpty(); // permit selection to be root of the origin feature model if (res) { String s = selectedFeatures.getFirst().toString(); if (s.equals(FeatureUtils.getRoot(featureModel).toString())) { return false; } } return res; }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.actions.CreateCompoundAction.java
License:Open Source License
private boolean isValidSelection(IStructuredSelection selection) { // check empty selection (i.e. ModelEditPart is selected) if (selection.size() == 1 && (selection.getFirstElement() instanceof ModelEditPart)) return false; // check that selected features have the same parent selectedFeatures.clear();/* w ww . ja v a 2 s. c o m*/ Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object editPart = iter.next(); if (!(editPart instanceof FeatureEditPart) && !(editPart instanceof Feature)) continue; Feature feature; if (editPart instanceof FeatureEditPart) feature = ((FeatureEditPart) editPart).getFeature(); else feature = (Feature) editPart; if (selectedFeatures.isEmpty()) parent = feature.getParent(); else if (parent != feature.getParent()) return false; selectedFeatures.add(feature); } return !selectedFeatures.isEmpty(); }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.actions.DeleteAction.java
License:Open Source License
private boolean isValidSelection(IStructuredSelection selection) { // check empty selection (i.e. ModelEditPart is selected) if (selection.size() == 1 && selection.getFirstElement() instanceof ModelEditPart) return false; // check that a possibly new root can be determined unique Feature root = featureModel.getRoot(); Feature newRoot = root;//w w w. jav a 2 s. c o m LinkedList<Feature> features = new LinkedList<Feature>(featureModel.getFeatures()); Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object editPart = iter.next(); if (!(editPart instanceof FeatureEditPart) && !(editPart instanceof Feature)) continue; Feature feature = editPart instanceof FeatureEditPart ? ((FeatureEditPart) editPart).getFeature() : (Feature) editPart; if (feature == root) { if (root.getChildrenCount() != 1) return false; newRoot = root.getFirstChild(); if (!newRoot.hasChildren()) return false; } features.remove(feature); } // check that the only child of a deleted root is not deleted too if (root != newRoot && !features.contains(newRoot)) return false; return true; }
From source file:de.ovgu.featureide.fm.ui.editors.featuremodel.actions.EditConstraintAction.java
License:Open Source License
@Override protected boolean isValidSelection(IStructuredSelection selection) { if (selection.size() == 1 && selection.getFirstElement() instanceof ModelEditPart) return false; Iterator<?> iter = selection.iterator(); while (iter.hasNext()) { Object editPart = iter.next(); if (editPart instanceof ConstraintEditPart) { constraint = ((ConstraintEditPart) editPart).getConstraintModel(); return true; }/*from w ww. j ava 2s . c om*/ if (editPart instanceof Constraint) { constraint = (Constraint) editPart; return true; } } return false; }
From source file:de.ovgu.featureide.fm.ui.handlers.base.ASelectionHandler.java
License:Open Source License
@Override public final Object execute(ExecutionEvent event) throws ExecutionException { final ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { IStructuredSelection strSelection = (IStructuredSelection) selection; if (startAction(strSelection)) { for (Iterator<?> it = strSelection.iterator(); it.hasNext();) { singleAction(it.next()); }/*from w w w . j a va 2 s. c om*/ endAction(); } } return null; }
From source file:de.plugins.eclipse.depclipse.actions.PackageTreeSelectionChangedAction.java
License:Open Source License
public void runWithEvent(SelectionChangedEvent event) { IStructuredSelection selectedStructure = (IStructuredSelection) event.getSelection(); ArrayList<IResource> al = new ArrayList<IResource>(); Iterator<?> iter = selectedStructure.iterator(); IResource[] resources;// w ww. j a v a 2 s . c om while (iter.hasNext()) { TreeObject o = (TreeObject) iter.next(); if (o.isLeaf()) { TreeLeaf tleaf = (TreeLeaf) o; if (tleaf.getIResource() != null) { al.add(tleaf.getIResource()); } } else { TreeFolder tfolder = (TreeFolder) o; try { resources = tfolder.getIResources(); for (int i = 0; i < resources.length; i++) { if (!al.contains(resources[i])) { al.add(resources[i]); } } } catch (JavaModelException e) { DepclipsePlugin.handle(e); } } } DepclipsePlugin.getJDependData().setSelection((IResource[]) al.toArray(new IResource[0])); }
From source file:de.quamoco.adaptation.wizard.util.modelattributes.ModelAttributesComposite.java
License:Apache License
/** * Creates the visual controls embedded in this composite, * depending on the {@link #style} attribute. *//*from www . j a v a 2s .c om*/ protected void createControls() { this.setLayout(new GridLayout(3, false)); /* Name row */ Label lblName = new Label(this, SWT.NONE); lblName.setText("Name:"); txtName = new Text(this, SWT.NONE); txtName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); btnFilterName = createFilterButton(); /* Description row */ Label lblDescription = new Label(this, SWT.NONE); lblDescription.setText("Description:"); txtDescription = new Text(this, SWT.MULTI | SWT.V_SCROLL); lblDescription.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); GridData layoutTxtDescription = new GridData(SWT.FILL, SWT.FILL, true, false); layoutTxtDescription.heightHint = 55; txtDescription.setLayoutData(layoutTxtDescription); btnFilterDescription = createFilterButton(); /* Object row */ Label lblObject = new Label(this, SWT.NONE); lblObject.setText("Object:"); cbObject = new ComboViewer(this, SWT.NONE); cbObject.setContentProvider(new ObjectContentProvider(wizard.getAttributesSettingPage())); cbObject.setLabelProvider(new NamedElementLabelProvider()); cbObject.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbObject.setSorter(new ViewerSorter()); // default sorter (by name) btnFilterObject = createFilterButton(); /* Viewpoint row */ Label lblViewpoint = new Label(this, SWT.NONE); lblViewpoint.setText("Viewpoint:"); cbViewpoint = new ComboViewer(this, SWT.NONE); cbViewpoint.setContentProvider(new ViewpointContentProvider(wizard.getAttributesSettingPage())); cbViewpoint.setLabelProvider(new NamedElementLabelProvider()); cbViewpoint.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbViewpoint.setSorter(new ViewerSorter()); btnFilterViewpoint = createFilterButton(); /* Quality Focus row */ Label lblQualityFocus = new Label(this, SWT.NONE); lblQualityFocus.setText("Quality Focus:"); cbQualityFocus = new ComboViewer(this, SWT.NONE); cbQualityFocus.setContentProvider( new QualityFocusContentProvider(wizard.getAttributesSettingPage(), cbViewpoint)); cbQualityFocus.setLabelProvider(new NamedElementLabelProvider()); cbQualityFocus.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbQualityFocus.setSorter(new ViewerSorter()); btnFilterQualityFocus = createFilterButton(); // Call update method when viewpoint has changed cbViewpoint.addPostSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { cbQualityFocus.refresh(); } }); /* Purpose row */ Label lblPurpose = new Label(this, SWT.NONE); lblPurpose.setText("Purpose:"); cbPurpose = new ComboViewer(this, SWT.READ_ONLY); cbPurpose.setContentProvider(new PurposeContentProvider(wizard)); cbPurpose.setLabelProvider(new NamedElementLabelProvider()); cbPurpose.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbPurpose.setSorter(new ViewerSorter()); btnFilterPurpose = createFilterButton(); /* Context row */ Label lblContext = new Label(this, SWT.NONE); lblContext.setText("Context:"); lblContext.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); Composite contextComposite = new Composite(this, SWT.NONE); contextComposite.setLayout(SWTUtil.createNoMarginGridLayout(1, false)); contextComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); lwContext = new ListViewer(contextComposite); lwContext.setContentProvider(new ContextListContentProvider()); lwContext.setLabelProvider(new NamedElementLabelProvider()); lwContext.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); lwContext.setSorter(new ViewerSorter()); lwContext.setInput(context); lwContext.getList().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL) { IStructuredSelection selection = (IStructuredSelection) lwContext.getSelection(); if (selection != null && !selection.isEmpty()) { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object next = iterator.next(); context.remove(next); cbContext.add(next); } lwContext.refresh(); notifyListener(); } } } }); Composite cbContextComposite = new Composite(contextComposite, SWT.NONE); cbContextComposite.setLayout(SWTUtil.createNoMarginGridLayout(2, false)); cbContextComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbContext = new ComboViewer(cbContextComposite, SWT.NONE); cbContext.setContentProvider(new ContextComboContentProvider(context)); cbContext.setLabelProvider(new NamedElementLabelProvider()); cbContext.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); cbContext.setSorter(new ViewerSorter()); Button btnContextAdd = new Button(cbContextComposite, SWT.PUSH); btnContextAdd.setText("Add"); btnContextAdd.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { addContext(); } }); cbContext.getCombo().addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.CR) { addContext(); } } }); btnFilterContext = createFilterButton(); }