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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
/*****************************************************************************
* Copyright (c) 2013 CEA
*
*
* 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:
* Soyatec - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.edit.policies;
import org.eclipse.draw2d.IFigure;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper;
import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusUMLElementFigure;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
/**
* Display both stereotype and stereotype properties in one figure.
*
* @author Jin Liu (jin.liu@soyatec.com)
*/
public class AppliedStereotypeExternalNodeLabelEditPolicy extends AppliedStereotypeLabelDisplayEditPolicy {
protected View hostView = null;
/**
* Constructor.
*
*/
public AppliedStereotypeExternalNodeLabelEditPolicy() {
this(null);
}
/**
* Constructor.
*
*/
public AppliedStereotypeExternalNodeLabelEditPolicy(View hostView) {
this.hostView = hostView;
}
public void activate() {
// retrieve the view and the element managed by the edit part
View view = getView();
if(view == null) {
return;
}
super.activate();
if(hostView == null) {
// add a listener for TimeObservationEditPart
// eContainer = getParent() , but here it's the ECore model
EObject parent = view.eContainer();
if(parent instanceof View) {
hostView = (View)parent;
}
}
getDiagramEventBroker().addNotificationListener(hostView, this);
refreshDisplay();
}
@Override
public void deactivate() {
if(hostView != null) {
getDiagramEventBroker().removeNotificationListener(hostView, this);
}
super.deactivate();
}
@Override
public void refreshDisplay() {
super.refreshDisplay();
if(getHost() instanceof IPapyrusEditPart) {
IFigure figure = ((IPapyrusEditPart)getHost()).getPrimaryShape();
if(figure instanceof IPapyrusNodeUMLElementFigure) {
refreshAppliedStereotypesProperties((IPapyrusNodeUMLElementFigure)figure);
}
}
}
public String stereotypesToDisplay() {
if(hostView == null) {
return "";
}
// list of stereotypes to display
String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(hostView);
// Kind of the representation
String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind(hostView);
// check the presentation kind. if only icon => do not display
// stereotypes
if(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION.equals(stereotypespresentationKind)) {
return ""; // empty string, so stereotype label should not be
// displayed
}
// stereotypes with qualified name to display
String stereotypesToDisplayWithQN = AppliedStereotypeHelper.getStereotypesQNToDisplay(hostView);
// the set is empty
if(stereotypesToDisplayWithQN.length() == 0 && stereotypesToDisplay.length() == 0) {
return "";
}
// vertical representation
if(UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(stereotypespresentationKind)) {
return Activator.ST_LEFT + stereotypesToDisplay(Activator.ST_RIGHT + "\n" + Activator.ST_LEFT, stereotypesToDisplay, stereotypesToDisplayWithQN) + Activator.ST_RIGHT;
} else {// horizontal representation
return Activator.ST_LEFT + stereotypesToDisplay(", ", stereotypesToDisplay, stereotypesToDisplayWithQN) + Activator.ST_RIGHT;
}
}
protected void refreshAppliedStereotypesProperties(IPapyrusNodeUMLElementFigure figure) {
if(hostView == null) {
return;
}
final String stereotypesPropertiesToDisplay = AppliedStereotypeHelper.getAppliedStereotypesPropertiesToDisplay(hostView);
refreshAppliedStereotypesPropertiesInCompartment(stereotypesPropertiesToDisplay, figure);
refreshAppliedStereotypesPropertiesInBrace(stereotypesPropertiesToDisplay, figure);
}
/**
* Refreshes the stereotypes properties displayed in a compartment of this
* edit part.
*
* @param stereotypesPropertiesToDisplay
* list of properties to display
* @param figure
* the figure in which stereotype will be displayed
*/
protected void refreshAppliedStereotypesPropertiesInCompartment(String stereotypesPropertiesToDisplay, IPapyrusNodeUMLElementFigure figure) {
if(hostView == null) {
return;
}
// retrieve the stereotype properties to be displayed
final boolean displayInCompartment = AppliedStereotypeHelper.hasAppliedStereotypesPropertiesToDisplay(hostView, UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
// if the string is not empty, then, the figure has to display it. Else,
// it displays nothing
if(displayInCompartment) {
String todisplay = StereotypeUtil.getPropertiesValues(stereotypesPropertiesToDisplay, getUMLElement());
figure.setStereotypePropertiesInCompartment(todisplay);
} else {
figure.setStereotypePropertiesInCompartment(null);
}
}
/**
* Refreshes the stereotypes properties displayed above name of the element
* in this edit part.
*/
protected void refreshAppliedStereotypesPropertiesInBrace(String stereotypesPropertiesToDisplay, IPapyrusNodeUMLElementFigure figure) {
if(hostView == null) {
return;
}
// check if properties have to be displayed in braces.
final boolean displayInBrace = AppliedStereotypeHelper.hasAppliedStereotypesPropertiesToDisplay(hostView, UMLVisualInformationPapyrusConstant.STEREOTYPE_BRACE_LOCATION);
// if the string is not empty, then, the figure has to display it. Else,
// it displays nothing
if(displayInBrace) {
// it has to be displayed in braces, so compute the string to
// display
String todisplay = StereotypeUtil.getPropertiesValuesInBrace(stereotypesPropertiesToDisplay, getUMLElement());
figure.setStereotypePropertiesInBrace(todisplay);
} else {
figure.setStereotypePropertiesInBrace(null);
}
}
/**
* @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#refreshStereotypeDisplay()
*
*/
@Override
protected void refreshStereotypeDisplay() {
if(getHost() instanceof IPapyrusEditPart) {
IFigure figure = ((IPapyrusEditPart)getHost()).getPrimaryShape();
if(figure instanceof IPapyrusUMLElementFigure) {// calculate text
// and icon to
// display
final String stereotypesToDisplay = stereotypesToDisplay();
((IPapyrusUMLElementFigure)figure).setStereotypeDisplay(tag + (stereotypesToDisplay), null);
}
}
}
}
|