blob: a903f80ff007635de0a5291d60d4d1e24b3adc63 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/*****************************************************************************
* Copyright (c) 2014 CEA LIST.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Saadia Dhouib (CEA LIST) saadia.dhouib@cea.fr - Initial API and implementation
*****************************************************************************/
package org.eclipse.papyrus.robotml.diagram.common.editpolicy.provider;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
import org.eclipse.gmf.runtime.notation.LayoutConstraint;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.robotml.diagram.common.editpolicies.PortNodeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart;
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart;
import org.eclipse.uml2.uml.Element;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
public class RobotMLDiagramsEditPolicyProvider extends AbstractProvider
implements IEditPolicyProvider {
public static String ROBOTML_ID = "RobotML";
public boolean provides(IOperation operation) {
CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
if (!(epOperation.getEditPart() instanceof GraphicalEditPart)) {
return false;
}
GraphicalEditPart gep = (GraphicalEditPart) epOperation.getEditPart();
String diagramType = gep.getNotationView().getDiagram().getType();
if (!CompositeStructureDiagramEditPart.MODEL_ID.equals(diagramType)) {
return false;
}
if (gep instanceof org.eclipse.papyrus.uml.diagram.composite.edit.parts.PortEditPart) {
return true;
}
return false;
}
public void createEditPolicies(EditPart editPart) {
if (editPart.getModel() instanceof View) {
EObject element = ((View) editPart.getModel()).getElement();
if (element instanceof Element) {
if (((Element) element).getNearestPackage().getAppliedProfile(
ROBOTML_ID) != null) {
// System.err.println(list.get(i).getProfile().getName());
if (editPart instanceof PortEditPart) {
NotificationListener editPolicy = new PortNodeLabelDisplayEditPolicy();
editPart.installEditPolicy(
AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY,
(EditPolicy) editPolicy);
Object model = editPart.getModel();
LayoutConstraint notifier = ((Shape) model)
.getLayoutConstraint();
if (model instanceof Shape) {
// to force refreshing the port icon when the
// diagram is opening
Notification notification = new ENotificationImpl(
(InternalEObject) notifier,
Notification.SET,
NotationPackage.eINSTANCE.getLocation_X(),
0, 0);
editPolicy.notifyChanged(notification);
}
}
}
}
}
}
}
|