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());
}
}
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());
}
}
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);
}
}
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;
}
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;
}
Aggregations