Example usage for org.eclipse.jface.viewers IStructuredSelection toList

List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection toList.

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:es.cv.gvcase.ide.navigator.actions.DeleteDiagramOrEObjectAction.java

License:Open Source License

@Override
public void run() {
    super.run();/*from   w ww .j a v a 2  s.c om*/
    // //
    IStructuredSelection ss = getStructuredSelection();
    CompoundCommand cc = new CompoundCommand("Delete elements");
    TransactionalEditingDomain domain = null;
    for (Object selected : ss.toList()) {
        if (selected instanceof EObject) {
            domain = domain != null ? domain : TransactionUtil.getEditingDomain((EObject) selected);
            if (selected instanceof Diagram) {
                Diagram diagram = (Diagram) selected;
                cc.append(new DeleteDiagramCommand(diagram));
            } else {
                cc.append(new DeleteCommand(domain, Collections.singleton(selected)));
            }
        }
    }
    if (cc.canExecute() && domain != null) {
        domain.getCommandStack().execute(cc);
    }
}

From source file:es.cv.gvcase.mdt.common.sections.composites.ChooseDialog.java

License:Open Source License

protected void changeItemHandle(SelectionChangedEvent event) {
    if (event.getSelection() instanceof IStructuredSelection) {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        for (Object o : selection.toList()) {
            if (!((o instanceof EObject) || (o instanceof CSingleObjectChooser.NullObject))) {
                getOkButton().setEnabled(false);
                return;
            }/*w  w  w .jav  a2  s  .co m*/
        }
        getOkButton().setEnabled(true);
        return;
    }
    getOkButton().setEnabled(false);
    return;
}

From source file:es.cv.gvcase.mdt.common.sections.composites.ChooseDialog.java

License:Open Source License

/**
 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
 *//*from w w w.  j  a  v a  2  s  .  c  o  m*/
protected void okPressed() {
    IStructuredSelection selection = (IStructuredSelection) tree.getTreeViewer().getSelection();
    List<Object> filteredSelection = new ArrayList<Object>();
    for (Object o : selection.toList()) {
        if ((o instanceof EObject) || (o instanceof CSingleObjectChooser.NullObject)) {
            filteredSelection.add(o);
        }
    }
    setResult(filteredSelection);
    super.okPressed();
}

From source file:es.cv.gvcase.mdt.common.util.MDTUtil.java

License:Open Source License

/**
 * Gets the edits the parts from selection.
 * /*w ww  . j a va 2  s  .c  o  m*/
 * @param selection
 *            the selection
 * 
 * @return the edits the parts from selection
 */
public static List<EditPart> getEditPartsFromSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        List<EditPart> editParts = new ArrayList<EditPart>();
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Object object : structuredSelection.toList()) {
            if (object instanceof EditPart) {
                editParts.add((EditPart) object);
            }
        }
        return editParts;
    }
    return Collections.emptyList();
}

From source file:es.cv.gvcase.mdt.common.util.MDTUtil.java

License:Open Source License

public static List<IGraphicalEditPart> getGraphicalEditPartsFromSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        List<IGraphicalEditPart> editParts = new ArrayList<IGraphicalEditPart>();
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Object object : structuredSelection.toList()) {
            if (object instanceof IGraphicalEditPart) {
                editParts.add((IGraphicalEditPart) object);
            }/*  w  w w  .  j a v a2  s.  c  o m*/
        }
        return editParts;
    }
    return Collections.emptyList();
}

From source file:es.cv.gvcase.mdt.common.util.MDTUtil.java

License:Open Source License

/**
 * Gets the {@link EObject}s from selection.
 * //from ww  w  .  j  a va 2  s.c  om
 * @param selection
 *            the selection
 * 
 * @return the e objects from selection
 */
public static List<EObject> getEObjectsFromSelection(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        List<EObject> eObjects = new ArrayList<EObject>();
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        for (Object object : structuredSelection.toList()) {
            EObject eObject = resolveSemantic(object);
            if (eObject != null) {
                eObjects.add(eObject);
            }
        }
        return eObjects;
    }
    return Collections.EMPTY_LIST;
}

From source file:eu.celar.ui.views.AuthTokenView.java

License:Open Source License

/**
 * Get a list of all currently selected tokens.
 * /* w w  w  .j a  v  a  2 s .c  o  m*/
 * @return A list containing all currently selected tokens.
 */
public List<IAuthenticationToken> getSelectedTokens() {
    IStructuredSelection selection = (IStructuredSelection) this.tokenList.getSelection();
    List<?> selectionList = selection.toList();
    List<IAuthenticationToken> result = new ArrayList<IAuthenticationToken>();
    for (Object element : selectionList) {
        if (element instanceof IAuthenticationToken) {
            IAuthenticationToken token = (IAuthenticationToken) element;
            result.add(token);
        }
    }
    return result;
}

From source file:eu.compassresearch.ide.ui.editor.core.CmlEditor.java

License:Open Source License

@Override
protected ISelectionChangedListener createOutlineSelectionChangedListener() {
    return new ISelectionChangedListener() {

        @SuppressWarnings("rawtypes")
        public void selectionChanged(SelectionChangedEvent event) {

            ISelection s = event.getSelection();
            if (s instanceof IStructuredSelection) {
                IStructuredSelection ss = (IStructuredSelection) s;
                List elements = ss.toList();
                if (!elements.isEmpty()) {
                    Object firstSelection = elements.get(0);

                    if (firstSelection instanceof INode) {
                        INode node = (INode) firstSelection;
                        selectAndReveal(node);
                    }//from  w  ww.ja v  a 2s.c  o m
                }
            }
        }
    };
}

From source file:eu.esdihumboldt.hale.ui.function.contribution.ReplaceFunctionWizardContribution.java

License:Open Source License

/**
 * Get the cell/*from   w ww. j  a  v  a2 s  .  com*/
 * 
 * @return the cell
 */
public Cell getOriginalCell() {
    if (this.originalCell != null) {
        return originalCell;
    }

    // retrieve first selected cell
    IStructuredSelection sel = SelectionTrackerUtil.getTracker().getSelection(IStructuredSelection.class);
    for (Object object : sel.toList()) {
        if (object instanceof Cell) {
            return (Cell) object;
        }
    }
    return null;
}

From source file:eu.esdihumboldt.hale.ui.function.contribution.SetTransformationModeContribution.java

License:Open Source License

/**
 * Get the cell//from w  w w  .  j a va2  s . co  m
 * 
 * @return the cell
 */
public Cell getOriginalCell() {
    // retrieve first selected cell
    IStructuredSelection sel = SelectionTrackerUtil.getTracker().getSelection(IStructuredSelection.class);
    for (Object object : sel.toList()) {
        if (object instanceof Cell) {
            return (Cell) object;
        }
    }
    return null;
}