1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.parts; |
5 | |
6 | import java.util.ArrayList; |
7 | import java.util.Collections; |
8 | import java.util.List; |
9 | |
10 | import org.eclipse.draw2d.IFigure; |
11 | import org.eclipse.draw2d.PositionConstants; |
12 | import org.eclipse.draw2d.RectangleFigure; |
13 | import org.eclipse.draw2d.Shape; |
14 | import org.eclipse.draw2d.StackLayout; |
15 | import org.eclipse.draw2d.geometry.Dimension; |
16 | import org.eclipse.draw2d.geometry.Point; |
17 | import org.eclipse.gef.EditPart; |
18 | import org.eclipse.gef.EditPolicy; |
19 | import org.eclipse.gef.GraphicalEditPart; |
20 | import org.eclipse.gef.Request; |
21 | import org.eclipse.gef.commands.Command; |
22 | import org.eclipse.gef.editpolicies.LayoutEditPolicy; |
23 | import org.eclipse.gef.editpolicies.NonResizableEditPolicy; |
24 | import org.eclipse.gef.editpolicies.ResizableEditPolicy; |
25 | import org.eclipse.gef.handles.MoveHandle; |
26 | import org.eclipse.gef.requests.CreateRequest; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart; |
28 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
29 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
30 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
31 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
32 | import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
33 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
34 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
35 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
36 | import org.eclipse.gmf.runtime.notation.View; |
37 | import org.eclipse.swt.graphics.Color; |
38 | |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.BallFigure; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.AbstractBorderFigure.POSITION_TYPE; |
41 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.OperationProvidedRoleItemSemanticEditPolicy; |
42 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
43 | import de.uka.ipd.sdq.pcm.gmf.composite.providers.PalladioComponentModelElementTypes; |
44 | |
45 | /** |
46 | * Operation Provided Role Edit part for inner AssemblyContext provided roles. |
47 | * |
48 | * For system operation provided roles: |
49 | * @see OperationProvidedRole2EditPart |
50 | * |
51 | * @generated |
52 | */ |
53 | public class OperationProvidedRoleEditPart extends BorderedBorderItemEditPart { |
54 | |
55 | /** |
56 | * size of the figure in LP |
57 | * @generated not |
58 | */ |
59 | private static final int FIGURE_LOGICAL_SIZE = 30; |
60 | |
61 | /** |
62 | * @generated |
63 | */ |
64 | public static final int VISUAL_ID = 3007; |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected IFigure contentPane; |
70 | |
71 | /** |
72 | * @generated |
73 | */ |
74 | protected IFigure primaryShape; |
75 | |
76 | /** |
77 | * @generated |
78 | */ |
79 | public OperationProvidedRoleEditPart(View view) { |
80 | super(view); |
81 | } |
82 | |
83 | /** |
84 | * @generated |
85 | */ |
86 | protected void createDefaultEditPolicies() { |
87 | super.createDefaultEditPolicies(); |
88 | installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, |
89 | getPrimaryDragEditPolicy()); |
90 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
91 | new OperationProvidedRoleItemSemanticEditPolicy()); |
92 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
93 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
94 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
95 | } |
96 | |
97 | /** |
98 | * @generated |
99 | */ |
100 | protected LayoutEditPolicy createLayoutEditPolicy() { |
101 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
102 | |
103 | protected EditPolicy createChildEditPolicy(EditPart child) { |
104 | View childView = (View) child.getModel(); |
105 | switch (PalladioComponentModelVisualIDRegistry |
106 | .getVisualID(childView)) { |
107 | case OperationProvidedRoleEntityNameEditPart.VISUAL_ID: |
108 | return new BorderItemSelectionEditPolicy() { |
109 | |
110 | protected List createSelectionHandles() { |
111 | MoveHandle mh = new MoveHandle( |
112 | (GraphicalEditPart) getHost()); |
113 | mh.setBorder(null); |
114 | return Collections.singletonList(mh); |
115 | } |
116 | }; |
117 | } |
118 | EditPolicy result = child |
119 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
120 | if (result == null) { |
121 | result = new NonResizableEditPolicy(); |
122 | } |
123 | return result; |
124 | } |
125 | |
126 | protected Command getMoveChildrenCommand(Request request) { |
127 | return null; |
128 | } |
129 | |
130 | protected Command getCreateCommand(CreateRequest request) { |
131 | return null; |
132 | } |
133 | }; |
134 | return lep; |
135 | } |
136 | |
137 | /** |
138 | * @generated |
139 | */ |
140 | protected IFigure createNodeShape() { |
141 | OperationProvidedRoleFigure figure = new OperationProvidedRoleFigure(); |
142 | return primaryShape = figure; |
143 | } |
144 | |
145 | /** |
146 | * @generated |
147 | */ |
148 | public OperationProvidedRoleFigure getPrimaryShape() { |
149 | return (OperationProvidedRoleFigure) primaryShape; |
150 | } |
151 | |
152 | /** |
153 | * @generated |
154 | */ |
155 | protected void addBorderItem(IFigure borderItemContainer, |
156 | IBorderItemEditPart borderItemEditPart) { |
157 | if (borderItemEditPart instanceof OperationProvidedRoleEntityNameEditPart) { |
158 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
159 | PositionConstants.SOUTH); |
160 | locator.setBorderItemOffset(new Dimension(-20, -20)); |
161 | borderItemContainer.add(borderItemEditPart.getFigure(), locator); |
162 | } else { |
163 | super.addBorderItem(borderItemContainer, borderItemEditPart); |
164 | } |
165 | } |
166 | |
167 | /** |
168 | * Create the Node Plate. |
169 | * This triggers the drawing of the ball figure |
170 | * |
171 | * @generated not |
172 | */ |
173 | protected NodeFigure createNodePlate() { |
174 | //DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(getMapMode() |
175 | // .DPtoLP(20), getMapMode().DPtoLP(20)); |
176 | |
177 | BallFigure result = new BallFigure(getMapMode().DPtoLP( |
178 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_INTERNAL); |
179 | |
180 | //FIXME: workaround for #154536 |
181 | result.getBounds().setSize(result.getPreferredSize()); |
182 | return result; |
183 | } |
184 | |
185 | /** |
186 | * @generated |
187 | */ |
188 | public EditPolicy getPrimaryDragEditPolicy() { |
189 | EditPolicy result = super.getPrimaryDragEditPolicy(); |
190 | if (result instanceof ResizableEditPolicy) { |
191 | ResizableEditPolicy ep = (ResizableEditPolicy) result; |
192 | ep.setResizeDirections(PositionConstants.NONE); |
193 | } |
194 | return result; |
195 | } |
196 | |
197 | /** |
198 | * Creates figure for this edit part. |
199 | * |
200 | * Call the createNodePlate() method |
201 | * |
202 | * Original generated Comment: |
203 | * Body of this method does not depend on settings in generation model |
204 | * so you may safely remove <i>generated</i> tag and modify it. |
205 | * |
206 | * @generated not |
207 | */ |
208 | protected NodeFigure createMainFigure() { |
209 | NodeFigure figure = createNodePlate(); |
210 | //figure.setLayoutManager(new StackLayout()); |
211 | //IFigure shape = createNodeShape(); |
212 | //figure.add(shape); |
213 | //contentPane = setupContentPane(shape); |
214 | |
215 | return figure; |
216 | } |
217 | |
218 | /** |
219 | * Default implementation treats passed figure as content pane. |
220 | * Respects layout one may have set for generated figure. |
221 | * @param nodeShape instance of generated figure class |
222 | * @generated |
223 | */ |
224 | protected IFigure setupContentPane(IFigure nodeShape) { |
225 | return nodeShape; // use nodeShape itself as contentPane |
226 | } |
227 | |
228 | /** |
229 | * @generated |
230 | */ |
231 | public IFigure getContentPane() { |
232 | if (contentPane != null) { |
233 | return contentPane; |
234 | } |
235 | return super.getContentPane(); |
236 | } |
237 | |
238 | /** |
239 | * @generated |
240 | */ |
241 | protected void setForegroundColor(Color color) { |
242 | if (primaryShape != null) { |
243 | primaryShape.setForegroundColor(color); |
244 | } |
245 | } |
246 | |
247 | /** |
248 | * @generated |
249 | */ |
250 | protected void setBackgroundColor(Color color) { |
251 | if (primaryShape != null) { |
252 | primaryShape.setBackgroundColor(color); |
253 | } |
254 | } |
255 | |
256 | /** |
257 | * @generated |
258 | */ |
259 | protected void setLineWidth(int width) { |
260 | if (primaryShape instanceof Shape) { |
261 | ((Shape) primaryShape).setLineWidth(width); |
262 | } |
263 | } |
264 | |
265 | /** |
266 | * @generated |
267 | */ |
268 | protected void setLineType(int style) { |
269 | if (primaryShape instanceof Shape) { |
270 | ((Shape) primaryShape).setLineStyle(style); |
271 | } |
272 | } |
273 | |
274 | /** |
275 | * @generated |
276 | */ |
277 | public EditPart getPrimaryChildEditPart() { |
278 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
279 | .getType(OperationProvidedRoleEntityNameEditPart.VISUAL_ID)); |
280 | } |
281 | |
282 | /** |
283 | * @generated |
284 | */ |
285 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
286 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
287 | types |
288 | .add(PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006); |
289 | return types; |
290 | } |
291 | |
292 | /** |
293 | * @generated |
294 | */ |
295 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
296 | IGraphicalEditPart targetEditPart) { |
297 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
298 | if (targetEditPart instanceof de.uka.ipd.sdq.pcm.gmf.composite.edit.parts.OperationProvidedRoleEditPart) { |
299 | types |
300 | .add(PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006); |
301 | } |
302 | if (targetEditPart instanceof OperationProvidedRole2EditPart) { |
303 | types |
304 | .add(PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006); |
305 | } |
306 | return types; |
307 | } |
308 | |
309 | /** |
310 | * @generated |
311 | */ |
312 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
313 | IElementType relationshipType) { |
314 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
315 | if (relationshipType == PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006) { |
316 | types |
317 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3007); |
318 | } |
319 | if (relationshipType == PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006) { |
320 | types |
321 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
322 | } |
323 | return types; |
324 | } |
325 | |
326 | /** |
327 | * @generated |
328 | */ |
329 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
330 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
331 | types.add(PalladioComponentModelElementTypes.AssemblyConnector_4004); |
332 | types |
333 | .add(PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006); |
334 | return types; |
335 | } |
336 | |
337 | /** |
338 | * @generated |
339 | */ |
340 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
341 | IElementType relationshipType) { |
342 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
343 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyConnector_4004) { |
344 | types |
345 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3008); |
346 | } |
347 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyConnector_4004) { |
348 | types |
349 | .add(PalladioComponentModelElementTypes.OperationRequiredRole_3012); |
350 | } |
351 | if (relationshipType == PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006) { |
352 | types |
353 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3007); |
354 | } |
355 | if (relationshipType == PalladioComponentModelElementTypes.ProvidedDelegationConnector_4006) { |
356 | types |
357 | .add(PalladioComponentModelElementTypes.OperationProvidedRole_3011); |
358 | } |
359 | return types; |
360 | } |
361 | |
362 | /** |
363 | * @generated |
364 | */ |
365 | public class OperationProvidedRoleFigure extends RectangleFigure { |
366 | |
367 | /** |
368 | * @generated |
369 | */ |
370 | public OperationProvidedRoleFigure() { |
371 | this.setLineWidth(1); |
372 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
373 | getMapMode().DPtoLP(20))); |
374 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
375 | getMapMode().DPtoLP(0))); |
376 | this.setLocation(new Point(getMapMode().DPtoLP(40), getMapMode() |
377 | .DPtoLP(40))); |
378 | } |
379 | |
380 | /** |
381 | * @generated |
382 | */ |
383 | private boolean myUseLocalCoordinates = false; |
384 | |
385 | /** |
386 | * @generated |
387 | */ |
388 | protected boolean useLocalCoordinates() { |
389 | return myUseLocalCoordinates; |
390 | } |
391 | |
392 | /** |
393 | * @generated |
394 | */ |
395 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
396 | myUseLocalCoordinates = useLocalCoordinates; |
397 | } |
398 | |
399 | } |
400 | |
401 | } |