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

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

Introduction

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

Prototype

@Override
    public List toList() 

Source Link

Usage

From source file:era.foss.objecteditor.specobject.SpecObjectHandler.java

License:Open Source License

/**
 * Remove specObject and associated hierarchy element in {@link SpecHierarchy}
 * //from   w w w.  ja v  a  2  s.  co  m
 * @param specObject specObject to be deleted
 * */
public static void deleteSpecObject(EditingDomain editingDomain, SpecObject specObject) {
    CompoundCommand compoundCommand = new CompoundCommand();
    compoundCommand.setLabel(ErfObjectsEditorPlugin.INSTANCE.getString("_UI_DeleteSpecObject_label"));
    compoundCommand
            .setDescription(ErfObjectsEditorPlugin.INSTANCE.getString("_UI_DeleteSpecObject_description"));

    // delete SpecHierarachy
    StructuredSelection specHierarchySelection = new StructuredSelection(specObject.getSpecHierarchy());
    if (!specHierarchySelection.isEmpty()) {
        Command deleteSpecHierarachyCommand = new DeleteCommand(editingDomain, specHierarchySelection.toList());
        compoundCommand.append(deleteSpecHierarachyCommand);
    }

    // delete SpecObject
    Command deleteSpecObjectCommand = new DeleteCommand(editingDomain,
            new StructuredSelection(specObject).toList());
    compoundCommand.append(deleteSpecObjectCommand);

    editingDomain.getCommandStack().execute(compoundCommand);
}

From source file:es.cv.gvcase.fefem.common.composites.EMFContainedCollectionEditionComposite.java

License:Open Source License

/**
 * Creates the a SelectionListener which will invoke the code to remove/delete
 * a selected element from the tree viewer.
 *     /*from w ww . j a v  a  2 s.c  o m*/
 * @return SelectionListener the {@link SelectionListener} which will
 * remove/delete a selected element from the viewer.
 */
protected SelectionListener getRemoveButtonSelectionListener() {
    SelectionAdapter adapter = new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            TableViewer viewer = getViewer();
            if (viewer.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) getViewer().getSelection();
                List<?> elementsToDelete = selection.toList();
                if (elementsToDelete.size() > 0) {
                    // We prepare the next selection, based on the element to delete
                    EObject eObject = (EObject) elementsToDelete.get(0);
                    StructuredSelection nextSelection = StructuredSelection.EMPTY;
                    if (modelObservable.size() > 1) { // If we have more than one element
                        int pos = modelObservable.indexOf(eObject);
                        nextSelection = (pos == modelObservable.size() - 1) // If it's the last first level element, we will select the previous sibling
                                ? new StructuredSelection(modelObservable.get(pos - 1))
                                : new StructuredSelection(modelObservable.get(pos + 1)); // otherwise, we will select the next one
                    }

                    EStructuralFeature feature = getFeature();
                    if (feature instanceof EReference // If it's a containment reference we delete the elements from the model
                            && ((EReference) feature).isContainment()) {
                        getEditingDomain().getCommandStack()
                                .execute(DeleteCommand.create(getEditingDomain(), elementsToDelete));
                    } else { // otherwise, we just remove the elements from the obsevableList
                        modelObservable.removeAll(elementsToDelete);
                    }

                    getPage().setDirty(true);
                    getViewer().setSelection(nextSelection);
                }
            }
        }
    };
    return adapter;
}

From source file:es.cv.gvcase.ide.navigator.util.NavigatorUtil.java

License:Open Source License

/**
 * Finds the {@link EditPart}s for the {@link EObject}s in the selection.
 * //from   w ww.ja  v a 2s  .c  om
 * @param selection
 *            the selection
 * @param viewer
 *            the viewer
 * 
 * @return the edits the parts from selection
 */
public static List<EditPart> getEditPartsFromSelection(ISelection selection, IDiagramGraphicalViewer viewer) {
    if (selection instanceof StructuredSelection && !selection.isEmpty()) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        // look for Views of the EObjects in the selection
        List<View> views = new ArrayList<View>();
        for (Object o : structuredSelection.toList()) {
            if (o instanceof EObject) {
                List referencerViews = getEObjectViews((EObject) o);
                for (Object ro : referencerViews) {
                    if (ro instanceof View) {
                        views.add((View) ro);
                    }
                }
            }
        }
        if (!views.isEmpty()) {
            List<EditPart> editParts = new ArrayList<EditPart>();
            for (View view : views) {
                Object ep = viewer.getEditPartRegistry().get(view);
                if (ep instanceof EditPart) {
                    editParts.add((EditPart) ep);
                }
            }
            if (!editParts.isEmpty()) {
                return editParts;
            }
        }
    }
    return Collections.emptyList();
}

From source file:es.cv.gvcase.mdt.common.composites.extended.ExtendedMembersComposite.java

License:Open Source License

/**
 * Handle add button selected./*from   w w w .j a va 2s  . com*/
 */
public void handleAddButtonSelected() {

    if (getCandidateElementsViewer().getSelection() instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) getCandidateElementsViewer().getSelection();

        executeAddCommand(selection.toList());

        refresh();
    }
}

From source file:es.cv.gvcase.mdt.common.composites.extended.ExtendedMembersComposite.java

License:Open Source License

/**
 * Handle remove button selected./* w w  w  .  j a  va2 s .c o  m*/
 */
public void handleRemoveButtonSelected() {

    if (getMemberElementsViewer().getSelection() instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) getMemberElementsViewer().getSelection();

        executeRemoveCommand(selection.toList());

        refresh();
    }
}

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

License:Open Source License

/**
 * Execute movement./*w w  w  . j  a v  a 2  s.  co m*/
 * 
 * @param up
 *            the up
 */
private void executeMovement(boolean up) {

    if (memberElementsViewer.getSelection() instanceof StructuredSelection) {
        StructuredSelection selection = (StructuredSelection) memberElementsViewer.getSelection();

        if (!selection.isEmpty()) {

            List membersToMove = selection.toList();

            List movedMembers = moveMembers(getMemberElements(), membersToMove, up);

            CompoundCommand c = new CompoundCommand();

            for (Object o : selection.toList()) {
                c.append(MoveCommand.create(getEMFEditDomain(), getElement(), getFeatureUnderEdition(), o,
                        movedMembers.indexOf(o)));
            }
            getEMFEditDomain().getCommandStack().execute(c);
            memberElementsViewer.setSelection(selection);
        }

    }

    return;
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add button selected.//from  w  w  w . j a v  a  2  s.  com
 */
protected void handleAddButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                addToMemberElements((EObject) element);
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add referenced elements button selected.
 */// w  w  w .  j a  va  2  s .c  o m
protected void handleAddReferencedElementsButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        if (!(selection.getFirstElement() instanceof EObject)) {
            return;
        }
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
            // Add related elements that have to be drawn on diagram
            addToMemberElements(getReferencedElements((EObject) element));
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                addToMemberElements((EObject) element);
                // Add related elements that have to be drawn on diagram
                addToMemberElements(getReferencedElements((EObject) element));
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add referencing elements button selected.
 *///from  w w w  .ja v a2 s .c o m
protected void handleAddReferencingElementsButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        if (!(selection.getFirstElement() instanceof EObject)) {
            return;
        }
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
            // Add related elements that have to be drawn on diagram
            addToMemberElements(getReferencingElements((EObject) element));
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                addToMemberElements((EObject) element);
                // Add related elements that have to be drawn on diagram
                addToMemberElements(getReferencingElements((EObject) element));
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}

From source file:es.cv.gvcase.mdt.common.part.DiagramElementsSelectionPage.java

License:Open Source License

/**
 * Handle add all related elements button selected.
 *//*w w w.ja v a  2s  .c  o  m*/
protected void handleAddAllRelatedElementsButtonSelected() {
    StructuredSelection selection = getCandidateElementsSelection();
    if (selection == null) {
        return;
    }

    if (selection.size() == 1) {
        if (!(selection.getFirstElement() instanceof EObject)) {
            return;
        }
        Object element = selection.getFirstElement();
        if (element instanceof EObject) {
            addToMemberElements((EObject) element);
            // Add related elements that have to be drawn on diagram
            addToMemberElements(getAllRelatedElements((EObject) element));
        }
    } else {
        for (Object element : selection.toList()) {
            if (element instanceof EObject) {
                // Add related elements that have to be drawn on diagram
                addToMemberElements(getAllRelatedElements((EObject) element));
            }
        }
    }

    refreshMembersViewer();
    refreshCandidatesViewer();
    // enable add buttons depending on candidate elements selected
    selection = getCandidateElementsSelection();
    enableAddButtons(selection != null && selection.size() > 0);
}