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.handles.MoveHandle; |
25 | import org.eclipse.gef.requests.CreateRequest; |
26 | import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart; |
27 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart; |
28 | import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
29 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy; |
30 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; |
31 | import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator; |
32 | import org.eclipse.gmf.runtime.emf.type.core.IElementType; |
33 | import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; |
34 | import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; |
35 | import org.eclipse.gmf.runtime.notation.View; |
36 | import org.eclipse.swt.graphics.Color; |
37 | |
38 | import de.uka.ipd.sdq.pcm.gmf.composite.SocketFigure; |
39 | import de.uka.ipd.sdq.pcm.gmf.composite.SourceFigure; |
40 | import de.uka.ipd.sdq.pcm.gmf.composite.AbstractBorderFigure.POSITION_TYPE; |
41 | import de.uka.ipd.sdq.pcm.gmf.composite.edit.policies.SourceRoleItemSemanticEditPolicy; |
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 | * The edit part to draw an internal source role for an assembly context. |
47 | * |
48 | * @generated |
49 | */ |
50 | public class SourceRoleEditPart extends BorderedBorderItemEditPart { |
51 | |
52 | /** |
53 | * size of the figure in LP |
54 | * |
55 | * @generated not |
56 | */ |
57 | private static final int FIGURE_LOGICAL_SIZE = 30; |
58 | |
59 | /** |
60 | * @generated |
61 | */ |
62 | public static final int VISUAL_ID = 3013; |
63 | |
64 | /** |
65 | * @generated |
66 | */ |
67 | protected IFigure contentPane; |
68 | |
69 | /** |
70 | * @generated |
71 | */ |
72 | protected IFigure primaryShape; |
73 | |
74 | /** |
75 | * @generated |
76 | */ |
77 | public SourceRoleEditPart(View view) { |
78 | super(view); |
79 | } |
80 | |
81 | /** |
82 | * @generated |
83 | */ |
84 | protected void createDefaultEditPolicies() { |
85 | super.createDefaultEditPolicies(); |
86 | installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, |
87 | getPrimaryDragEditPolicy()); |
88 | installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, |
89 | new SourceRoleItemSemanticEditPolicy()); |
90 | installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); |
91 | // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies |
92 | // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); |
93 | } |
94 | |
95 | /** |
96 | * @generated |
97 | */ |
98 | protected LayoutEditPolicy createLayoutEditPolicy() { |
99 | LayoutEditPolicy lep = new LayoutEditPolicy() { |
100 | |
101 | protected EditPolicy createChildEditPolicy(EditPart child) { |
102 | View childView = (View) child.getModel(); |
103 | switch (PalladioComponentModelVisualIDRegistry |
104 | .getVisualID(childView)) { |
105 | case SourceRoleEntityNameEditPart.VISUAL_ID: |
106 | return new BorderItemSelectionEditPolicy() { |
107 | |
108 | protected List createSelectionHandles() { |
109 | MoveHandle mh = new MoveHandle( |
110 | (GraphicalEditPart) getHost()); |
111 | mh.setBorder(null); |
112 | return Collections.singletonList(mh); |
113 | } |
114 | }; |
115 | } |
116 | EditPolicy result = child |
117 | .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); |
118 | if (result == null) { |
119 | result = new NonResizableEditPolicy(); |
120 | } |
121 | return result; |
122 | } |
123 | |
124 | protected Command getMoveChildrenCommand(Request request) { |
125 | return null; |
126 | } |
127 | |
128 | protected Command getCreateCommand(CreateRequest request) { |
129 | return null; |
130 | } |
131 | }; |
132 | return lep; |
133 | } |
134 | |
135 | /** |
136 | * @generated |
137 | */ |
138 | protected IFigure createNodeShape() { |
139 | SourceRoleFigure figure = new SourceRoleFigure(); |
140 | return primaryShape = figure; |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | public SourceRoleFigure getPrimaryShape() { |
147 | return (SourceRoleFigure) primaryShape; |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | protected void addBorderItem(IFigure borderItemContainer, |
154 | IBorderItemEditPart borderItemEditPart) { |
155 | if (borderItemEditPart instanceof SourceRoleEntityNameEditPart) { |
156 | BorderItemLocator locator = new BorderItemLocator(getMainFigure(), |
157 | PositionConstants.SOUTH); |
158 | locator.setBorderItemOffset(new Dimension(-20, -20)); |
159 | borderItemContainer.add(borderItemEditPart.getFigure(), locator); |
160 | } else { |
161 | super.addBorderItem(borderItemContainer, borderItemEditPart); |
162 | } |
163 | } |
164 | |
165 | /** |
166 | * @generated |
167 | */ |
168 | protected NodeFigure createNodePlate() { |
169 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); |
170 | |
171 | //FIXME: workaround for #154536 |
172 | result.getBounds().setSize(result.getPreferredSize()); |
173 | return result; |
174 | } |
175 | |
176 | /** |
177 | * Creates figure for this edit part. |
178 | * |
179 | * Body of this method does not depend on settings in generation model |
180 | * so you may safely remove <i>generated</i> tag and modify it. |
181 | * |
182 | * Manually modified to generate a specific source figure |
183 | * instead of the standard shape configured in the map model. |
184 | * |
185 | * @generated not |
186 | */ |
187 | protected NodeFigure createMainFigure() { |
188 | SourceFigure figure = new SourceFigure(getMapMode().DPtoLP( |
189 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_INTERNAL); |
190 | figure.getBounds().setSize(figure.getPreferredSize()); |
191 | return figure; |
192 | } |
193 | |
194 | /** |
195 | * Default implementation treats passed figure as content pane. |
196 | * Respects layout one may have set for generated figure. |
197 | * @param nodeShape instance of generated figure class |
198 | * @generated |
199 | */ |
200 | protected IFigure setupContentPane(IFigure nodeShape) { |
201 | return nodeShape; // use nodeShape itself as contentPane |
202 | } |
203 | |
204 | /** |
205 | * @generated |
206 | */ |
207 | public IFigure getContentPane() { |
208 | if (contentPane != null) { |
209 | return contentPane; |
210 | } |
211 | return super.getContentPane(); |
212 | } |
213 | |
214 | /** |
215 | * @generated |
216 | */ |
217 | protected void setForegroundColor(Color color) { |
218 | if (primaryShape != null) { |
219 | primaryShape.setForegroundColor(color); |
220 | } |
221 | } |
222 | |
223 | /** |
224 | * @generated |
225 | */ |
226 | protected void setBackgroundColor(Color color) { |
227 | if (primaryShape != null) { |
228 | primaryShape.setBackgroundColor(color); |
229 | } |
230 | } |
231 | |
232 | /** |
233 | * @generated |
234 | */ |
235 | protected void setLineWidth(int width) { |
236 | if (primaryShape instanceof Shape) { |
237 | ((Shape) primaryShape).setLineWidth(width); |
238 | } |
239 | } |
240 | |
241 | /** |
242 | * @generated |
243 | */ |
244 | protected void setLineType(int style) { |
245 | if (primaryShape instanceof Shape) { |
246 | ((Shape) primaryShape).setLineStyle(style); |
247 | } |
248 | } |
249 | |
250 | /** |
251 | * @generated |
252 | */ |
253 | public EditPart getPrimaryChildEditPart() { |
254 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
255 | .getType(SourceRoleEntityNameEditPart.VISUAL_ID)); |
256 | } |
257 | |
258 | /** |
259 | * @generated |
260 | */ |
261 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSource() { |
262 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
263 | types |
264 | .add(PalladioComponentModelElementTypes.AssemblyEventConnector_4007); |
265 | return types; |
266 | } |
267 | |
268 | /** |
269 | * @generated |
270 | */ |
271 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnSourceAndTarget( |
272 | IGraphicalEditPart targetEditPart) { |
273 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
274 | if (targetEditPart instanceof SinkRoleEditPart) { |
275 | types |
276 | .add(PalladioComponentModelElementTypes.AssemblyEventConnector_4007); |
277 | } |
278 | return types; |
279 | } |
280 | |
281 | /** |
282 | * @generated |
283 | */ |
284 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForTarget( |
285 | IElementType relationshipType) { |
286 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
287 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyEventConnector_4007) { |
288 | types.add(PalladioComponentModelElementTypes.SinkRole_3014); |
289 | } |
290 | return types; |
291 | } |
292 | |
293 | /** |
294 | * @generated |
295 | */ |
296 | public class SourceRoleFigure extends RectangleFigure { |
297 | |
298 | /** |
299 | * @generated |
300 | */ |
301 | public SourceRoleFigure() { |
302 | this.setLineWidth(1); |
303 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
304 | getMapMode().DPtoLP(20))); |
305 | this.setLocation(new Point(getMapMode().DPtoLP(40), getMapMode() |
306 | .DPtoLP(40))); |
307 | } |
308 | |
309 | /** |
310 | * @generated |
311 | */ |
312 | private boolean myUseLocalCoordinates = false; |
313 | |
314 | /** |
315 | * @generated |
316 | */ |
317 | protected boolean useLocalCoordinates() { |
318 | return myUseLocalCoordinates; |
319 | } |
320 | |
321 | /** |
322 | * @generated |
323 | */ |
324 | protected void setUseLocalCoordinates(boolean useLocalCoordinates) { |
325 | myUseLocalCoordinates = useLocalCoordinates; |
326 | } |
327 | |
328 | } |
329 | |
330 | } |