1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.ColorConstants; |
7 | import org.eclipse.draw2d.CompoundBorder; |
8 | import org.eclipse.draw2d.IFigure; |
9 | import org.eclipse.draw2d.LineBorder; |
10 | import org.eclipse.draw2d.MarginBorder; |
11 | import org.eclipse.draw2d.RectangleFigure; |
12 | import org.eclipse.draw2d.Shape; |
13 | import org.eclipse.draw2d.StackLayout; |
14 | import org.eclipse.draw2d.geometry.Dimension; |
15 | import org.eclipse.gef.EditPart; |
16 | import org.eclipse.gef.EditPolicy; |
17 | import org.eclipse.gef.Request; |
18 | import org.eclipse.gef.commands.Command; |
19 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
20 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
21 | import org.eclipse.gef.requests.CreateRequest; |
22 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
23 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; |
24 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
25 | import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; |
26 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
27 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
28 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
29 | import org.eclipse.gmf.runtime.notation.View; |
30 | import org.eclipse.swt.graphics.Color; |
31 | |
32 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.policies.UsageScenario2ItemSemanticEditPolicy; |
33 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
34 | |
35 | /** |
36 | * @generated |
37 | */ |
38 | public class UsageScenario2EditPart extends ShapeNodeEditPart { |
39 | |
40 | /** |
41 | * @generated |
42 | */ |
43 | public static final int VISUAL_ID = 2004; |
44 | |
45 | /** |
46 | * @generated |
47 | */ |
48 | protected IFigure contentPane; |
49 | |
50 | /** |
51 | * @generated |
52 | */ |
53 | protected IFigure primaryShape; |
54 | |
55 | /** |
56 | * @generated |
57 | */ |
58 | public UsageScenario2EditPart(View view) { |
59 | super(view); |
60 | } |
61 | |
62 | /** |
63 | * @generated |
64 | */ |
65 | protected void createDefaultEditPolicies() { |
66 | super.createDefaultEditPolicies(); |
67 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
68 | new UsageScenario2ItemSemanticEditPolicy()); |
69 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
70 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
71 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
72 | } |
73 | |
74 | /** |
75 | * @generated |
76 | */ |
77 | protected LayoutEditPolicy createLayoutEditPolicy() { |
78 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
79 | |
80 | protected EditPolicy createChildEditPolicy(EditPart child) { |
81 | EditPolicy result = child |
82 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
83 | if (result == null) { |
84 | result = new NonResizableEditPolicy(); |
85 | } |
86 | return result; |
87 | } |
88 | |
89 | protected Command getMoveChildrenCommand(Request request) { |
90 | return null; |
91 | } |
92 | |
93 | protected Command getCreateCommand(CreateRequest request) { |
94 | return null; |
95 | } |
96 | }; |
97 | return lep; |
98 | } |
99 | |
100 | /** |
101 | * @generated |
102 | */ |
103 | protected IFigure createNodeShape() { |
104 | UsageScenarioFigure figure = new UsageScenarioFigure(); |
105 | return primaryShape = figure; |
106 | } |
107 | |
108 | /** |
109 | * @generated |
110 | */ |
111 | public UsageScenarioFigure getPrimaryShape() { |
112 | return (UsageScenarioFigure) primaryShape; |
113 | } |
114 | |
115 | /** |
116 | * @generated |
117 | */ |
118 | protected boolean addFixedChild(EditPart childEditPart) { |
119 | if (childEditPart instanceof UsageScenarioLabelEditPart) { |
120 | ((UsageScenarioLabelEditPart) childEditPart) |
121 | .setLabel(getPrimaryShape() |
122 | .getFigureUsageScenarioLabelName()); |
123 | return true; |
124 | } |
125 | return false; |
126 | } |
127 | |
128 | /** |
129 | * @generated |
130 | */ |
131 | protected boolean removeFixedChild(EditPart childEditPart) { |
132 | if (childEditPart instanceof UsageScenarioLabelEditPart) { |
133 | return true; |
134 | } |
135 | return false; |
136 | } |
137 | |
138 | /** |
139 | * @generated |
140 | */ |
141 | protected void addChildVisual(EditPart childEditPart, int index) { |
142 | if (addFixedChild(childEditPart)) { |
143 | return; |
144 | } |
145 | super.addChildVisual(childEditPart, -1); |
146 | } |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | protected void removeChildVisual(EditPart childEditPart) { |
152 | if (removeFixedChild(childEditPart)) { |
153 | return; |
154 | } |
155 | super.removeChildVisual(childEditPart); |
156 | } |
157 | |
158 | /** |
159 | * @generated |
160 | */ |
161 | protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { |
162 | return getContentPane(); |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | protected NodeFigure createNodePlate() { |
169 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40); |
170 | return result; |
171 | } |
172 | |
173 | /** |
174 | * Creates figure for this edit part. |
175 | * |
176 | * Body of this method does not depend on settings in generation model |
177 | * so you may safely remove <i>generated</i> tag and modify it. |
178 | * |
179 | * @generated |
180 | */ |
181 | protected NodeFigure createNodeFigure() { |
182 | NodeFigure figure = createNodePlate(); |
183 | figure.setLayoutManager(new StackLayout()); |
184 | IFigure shape = createNodeShape(); |
185 | figure.add(shape); |
186 | contentPane = setupContentPane(shape); |
187 | return figure; |
188 | } |
189 | |
190 | /** |
191 | * Default implementation treats passed figure as content pane. |
192 | * Respects layout one may have set for generated figure. |
193 | * @param nodeShape instance of generated figure class |
194 | * @generated |
195 | */ |
196 | protected IFigure setupContentPane(IFigure nodeShape) { |
197 | if (nodeShape.getLayoutManager() == null) { |
198 | ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); |
199 | layout.setSpacing(5); |
200 | nodeShape.setLayoutManager(layout); |
201 | } |
202 | return nodeShape; // use nodeShape itself as contentPane |
203 | } |
204 | |
205 | /** |
206 | * @generated |
207 | */ |
208 | public IFigure getContentPane() { |
209 | if (contentPane != null) { |
210 | return contentPane; |
211 | } |
212 | return super.getContentPane(); |
213 | } |
214 | |
215 | /** |
216 | * @generated |
217 | */ |
218 | protected void setForegroundColor(Color color) { |
219 | if (primaryShape != null) { |
220 | primaryShape.setForegroundColor(color); |
221 | } |
222 | } |
223 | |
224 | /** |
225 | * @generated |
226 | */ |
227 | protected void setBackgroundColor(Color color) { |
228 | if (primaryShape != null) { |
229 | primaryShape.setBackgroundColor(color); |
230 | } |
231 | } |
232 | |
233 | /** |
234 | * @generated |
235 | */ |
236 | protected void setLineWidth(int width) { |
237 | if (primaryShape instanceof Shape) { |
238 | ((Shape) primaryShape).setLineWidth(width); |
239 | } |
240 | } |
241 | |
242 | /** |
243 | * @generated |
244 | */ |
245 | protected void setLineType(int style) { |
246 | if (primaryShape instanceof Shape) { |
247 | ((Shape) primaryShape).setLineStyle(style); |
248 | } |
249 | } |
250 | |
251 | /** |
252 | * @generated |
253 | */ |
254 | public EditPart getPrimaryChildEditPart() { |
255 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
256 | .getType(UsageScenarioLabelEditPart.VISUAL_ID)); |
257 | } |
258 | |
259 | /** |
260 | * @generated |
261 | */ |
262 | public class UsageScenarioFigure extends RectangleFigure { |
263 | |
264 | /** |
265 | * @generated |
266 | */ |
267 | private WrappingLabel fFigureUsageScenarioLabelName; |
268 | |
269 | /** |
270 | * @generated |
271 | */ |
272 | public UsageScenarioFigure() { |
273 | this.setLineWidth(1); |
274 | this.setForegroundColor(ColorConstants.lightGray); |
275 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
276 | getMapMode().DPtoLP(0))); |
277 | this.setBorder(new CompoundBorder(new LineBorder(null, getMapMode() |
278 | .DPtoLP(3)), new MarginBorder(getMapMode().DPtoLP(4), |
279 | getMapMode().DPtoLP(4), getMapMode().DPtoLP(4), |
280 | getMapMode().DPtoLP(4)))); |
281 | createContents(); |
282 | } |
283 | |
284 | /** |
285 | * @generated |
286 | */ |
287 | private void createContents() { |
288 | |
289 | fFigureUsageScenarioLabelName = new WrappingLabel(); |
290 | fFigureUsageScenarioLabelName.setText(""); |
291 | fFigureUsageScenarioLabelName.setMaximumSize(new Dimension( |
292 | getMapMode().DPtoLP(300), getMapMode().DPtoLP(40))); |
293 | fFigureUsageScenarioLabelName.setMinimumSize(new Dimension( |
294 | getMapMode().DPtoLP(30), getMapMode().DPtoLP(40))); |
295 | |
296 | this.add(fFigureUsageScenarioLabelName); |
297 | |
298 | } |
299 | |
300 | /** |
301 | * @generated |
302 | */ |
303 | private boolean myUseLocalCoordinates = false; |
304 | |
305 | /** |
306 | * @generated |
307 | */ |
308 | protected boolean useLocalCoordinates() { |
309 | return myUseLocalCoordinates; |
310 | } |
311 | |
312 | /** |
313 | * @generated |
314 | */ |
315 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
316 | myUseLocalCoordinates = useLocalCoordinates; |
317 | } |
318 | |
319 | /** |
320 | * @generated |
321 | */ |
322 | public WrappingLabel getFigureUsageScenarioLabelName() { |
323 | return fFigureUsageScenarioLabelName; |
324 | } |
325 | |
326 | } |
327 | |
328 | } |