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