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