Search in sources :

Example 1 with DSemanticDecorator

use of org.eclipse.sirius.viewpoint.DSemanticDecorator in project Palladio-Editors-Sirius by PalladioSimulator.

the class ApplyUnapplyProfileAction method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final EObject target = ((DSemanticDecorator) selections.iterator().next()).getTarget();
    final Resource targetResource = target.eResource();
    final FeatureEditorDialog profileSelectionDialog = new FeatureEditorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), LABEL_PROVIDER, target, target.eClass().getEAllStructuralFeatures().get(0).getEType(), ProfileAPI.getAppliedProfiles(targetResource), SELECT_APPLIED_PROFILES_MESSAGE, ProfileAPI.getApplicableProfiles(), false, true, true);
    if (profileSelectionDialog.open() == Dialog.OK) {
        ProfileAPI.updateProfileApplications(targetResource, (EList<Profile>) profileSelectionDialog.getResult());
    }
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) FeatureEditorDialog(org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Profile(org.modelversioning.emfprofile.Profile)

Example 2 with DSemanticDecorator

use of org.eclipse.sirius.viewpoint.DSemanticDecorator in project Palladio-Editors-Sirius by PalladioSimulator.

the class ApplyUnapplyStereotypeAction method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final EObject target = ((DSemanticDecorator) selections.iterator().next()).getTarget();
    final boolean targetHasProfileApplication = ProfileAPI.hasProfileApplication(target.eResource());
    final FeatureEditorDialog stereotypeSelectionDialog = new FeatureEditorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), LABEL_PROVIDER, target, target.eClass().getEAllStructuralFeatures().get(0).getEType(), targetHasProfileApplication ? StereotypeAPI.getAppliedStereotypes(target) : Collections.EMPTY_LIST, SELECT_APPLIED_STEREOTYPES_MESSAGE, targetHasProfileApplication ? StereotypeAPI.getApplicableStereotypes(target) : Collections.EMPTY_LIST, true, false, false);
    if (stereotypeSelectionDialog.open() == Dialog.OK) {
        StereotypeAPI.updateStereotypeApplications(target, (EList<Stereotype>) stereotypeSelectionDialog.getResult());
    }
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) FeatureEditorDialog(org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog) EObject(org.eclipse.emf.ecore.EObject) Stereotype(org.modelversioning.emfprofile.Stereotype)

Example 3 with DSemanticDecorator

use of org.eclipse.sirius.viewpoint.DSemanticDecorator in project InformationSystem by ObeoNetwork.

the class ViewpointSelectionListener method selectionChanged.

/**
 * {@inheritDoc}
 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
 */
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    EObject selectedEObject = null;
    if (!selection.isEmpty() && selection instanceof StructuredSelection) {
        StructuredSelection sSelection = (StructuredSelection) selection;
        if (sSelection.size() == 1) {
            Object selectedObject = sSelection.getFirstElement();
            if (selectedObject instanceof GraphicalEditPart) {
                // Sirius diagrams
                GraphicalEditPart graphicalEditPart = (GraphicalEditPart) selectedObject;
                if (graphicalEditPart.getModel() instanceof View) {
                    View node = (View) graphicalEditPart.getModel();
                    if (node.getElement() instanceof DSemanticDecorator) {
                        DSemanticDecorator semanticDecorator = (DSemanticDecorator) node.getElement();
                        selectedEObject = semanticDecorator.getTarget();
                    }
                }
            } else if (selectedObject instanceof DSemanticDecorator) {
                // Sirius trees and tables
                selectedEObject = ((DSemanticDecorator) selectedObject).getTarget();
            } else if (selectedObject instanceof EObject) {
                if (!ViewpointPackage.eINSTANCE.getDRepresentation().isInstance(selectedObject)) {
                    selectedEObject = (EObject) selectedObject;
                }
            }
        }
    } else {
        selectedEObject = null;
    }
    // Add this test to prevent a NullPointerException when selecting CDO resource
    if (!(selectedEObject instanceof Resource)) {
        eObjectSelected(selectedEObject);
    }
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) EObject(org.eclipse.emf.ecore.EObject) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) View(org.eclipse.gmf.runtime.notation.View)

Example 4 with DSemanticDecorator

use of org.eclipse.sirius.viewpoint.DSemanticDecorator in project InformationSystem by ObeoNetwork.

the class AbstractUserStoryDecorator method getAnalysis.

/**
 * Retrieves the DAnalysis instance from a diagram edit part
 * @param diagramEditPart Diagram edit part corresponding to an element on a viewpoint diagram
 * @return the DAnalysis instance
 */
private static DAnalysis getAnalysis(IDiagramElementEditPart diagramEditPart) {
    EObject viewpointNode = diagramEditPart.resolveSemanticElement();
    // if there is no GMF semantic element, we won't be able to retrieve a DAnalysis
    if (viewpointNode != null) {
        Session session = null;
        // First, try to retrieve the session using the sirius semantic element
        if (viewpointNode instanceof DSemanticDecorator) {
            EObject semanticElement = ((DSemanticDecorator) viewpointNode).getTarget();
            if (semanticElement != null) {
                session = new EObjectQuery(semanticElement).getSession();
            }
        }
        // If it didn't work, let's try using the sirius graphical element
        if (session == null) {
            session = new EObjectQuery(viewpointNode).getSession();
        }
        // If we were able to retrieve a session, let's get the root DAnalysis
        if (session != null) {
            EObject analysisEObject = session.getSessionResource().getContents().get(0);
            if (analysisEObject instanceof DAnalysis) {
                return (DAnalysis) analysisEObject;
            }
        }
        // Nothing worked, let's check if the EMF root element is a DAnalysis
        EObject container = EcoreUtil.getRootContainer(viewpointNode);
        if (container != null && container instanceof DAnalysis) {
            return (DAnalysis) container;
        }
    }
    return null;
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) EObject(org.eclipse.emf.ecore.EObject) DAnalysis(org.eclipse.sirius.viewpoint.DAnalysis) Session(org.eclipse.sirius.business.api.session.Session)

Example 5 with DSemanticDecorator

use of org.eclipse.sirius.viewpoint.DSemanticDecorator in project InformationSystem by ObeoNetwork.

the class DesignServices method getDisplayedElementsByType.

/**
 * Returns all elements of the specified class displayed on a diagram
 * @param diagram
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
private static <T extends EObject> Set<T> getDisplayedElementsByType(DSemanticDiagram diagram, Class<T> clazz) {
    Set<T> result = Sets.newLinkedHashSet();
    Iterator<DSemanticDecorator> it = Iterators.filter(diagram.eAllContents(), DSemanticDecorator.class);
    while (it.hasNext()) {
        DSemanticDecorator dec = it.next();
        EObject target = dec.getTarget();
        if (target != null && clazz.isAssignableFrom(target.getClass())) {
            result.add((T) target);
        }
    }
    return result;
}
Also used : DSemanticDecorator(org.eclipse.sirius.viewpoint.DSemanticDecorator) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)6 DSemanticDecorator (org.eclipse.sirius.viewpoint.DSemanticDecorator)6 Resource (org.eclipse.emf.ecore.resource.Resource)2 FeatureEditorDialog (org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 View (org.eclipse.gmf.runtime.notation.View)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 EObjectQuery (org.eclipse.sirius.business.api.query.EObjectQuery)2 Session (org.eclipse.sirius.business.api.session.Session)2 ArrayList (java.util.ArrayList)1 DAnalysis (org.eclipse.sirius.viewpoint.DAnalysis)1 Profile (org.modelversioning.emfprofile.Profile)1 Stereotype (org.modelversioning.emfprofile.Stereotype)1