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.AbstractBorderedShapeEditPart; |
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.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.SinkFigure; |
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.SinkRoleItemSemanticEditPolicy; |
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 sink role for an assembly context. |
47 | * |
48 | * @generated |
49 | */ |
50 | public class SinkRoleEditPart 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 = 3014; |
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 SinkRoleEditPart(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 SinkRoleItemSemanticEditPolicy()); |
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 SinkRoleEntityNameEditPart.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 | SinkRoleFigure figure = new SinkRoleFigure(); |
140 | return primaryShape = figure; |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | public SinkRoleFigure getPrimaryShape() { |
147 | return (SinkRoleFigure) primaryShape; |
148 | } |
149 | |
150 | /** |
151 | * @generated |
152 | */ |
153 | protected void addBorderItem(IFigure borderItemContainer, |
154 | IBorderItemEditPart borderItemEditPart) { |
155 | if (borderItemEditPart instanceof SinkRoleEntityNameEditPart) { |
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 | * Create the node shape. |
167 | * This is manually adopted to trigger |
168 | * @generated |
169 | */ |
170 | protected NodeFigure createNodePlate() { |
171 | DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(20, 20); |
172 | |
173 | //FIXME: workaround for #154536 |
174 | result.getBounds().setSize(result.getPreferredSize()); |
175 | return result; |
176 | } |
177 | |
178 | /** |
179 | * Creates figure for this edit part. |
180 | * |
181 | * Body of this method does not depend on settings in generation model |
182 | * so you may safely remove <i>generated</i> tag and modify it. |
183 | * |
184 | * Manually modified to generate a specific sink figure |
185 | * instead of the standard shape configured in the map model. |
186 | * |
187 | * @generated not |
188 | */ |
189 | protected NodeFigure createMainFigure() { |
190 | SinkFigure figure = new SinkFigure(getMapMode().DPtoLP( |
191 | FIGURE_LOGICAL_SIZE), POSITION_TYPE.POS_INTERNAL); |
192 | figure.getBounds().setSize(figure.getPreferredSize()); |
193 | return figure; |
194 | } |
195 | |
196 | /** |
197 | * Default implementation treats passed figure as content pane. |
198 | * Respects layout one may have set for generated figure. |
199 | * @param nodeShape instance of generated figure class |
200 | * @generated |
201 | */ |
202 | protected IFigure setupContentPane(IFigure nodeShape) { |
203 | return nodeShape; // use nodeShape itself as contentPane |
204 | } |
205 | |
206 | /** |
207 | * @generated |
208 | */ |
209 | public IFigure getContentPane() { |
210 | if (contentPane != null) { |
211 | return contentPane; |
212 | } |
213 | return super.getContentPane(); |
214 | } |
215 | |
216 | /** |
217 | * @generated |
218 | */ |
219 | protected void setForegroundColor(Color color) { |
220 | if (primaryShape != null) { |
221 | primaryShape.setForegroundColor(color); |
222 | } |
223 | } |
224 | |
225 | /** |
226 | * @generated |
227 | */ |
228 | protected void setBackgroundColor(Color color) { |
229 | if (primaryShape != null) { |
230 | primaryShape.setBackgroundColor(color); |
231 | } |
232 | } |
233 | |
234 | /** |
235 | * @generated |
236 | */ |
237 | protected void setLineWidth(int width) { |
238 | if (primaryShape instanceof Shape) { |
239 | ((Shape) primaryShape).setLineWidth(width); |
240 | } |
241 | } |
242 | |
243 | /** |
244 | * @generated |
245 | */ |
246 | protected void setLineType(int style) { |
247 | if (primaryShape instanceof Shape) { |
248 | ((Shape) primaryShape).setLineStyle(style); |
249 | } |
250 | } |
251 | |
252 | /** |
253 | * @generated |
254 | */ |
255 | public EditPart getPrimaryChildEditPart() { |
256 | return getChildBySemanticHint(PalladioComponentModelVisualIDRegistry |
257 | .getType(SinkRoleEntityNameEditPart.VISUAL_ID)); |
258 | } |
259 | |
260 | /** |
261 | * @generated |
262 | */ |
263 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMARelTypesOnTarget() { |
264 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
265 | types |
266 | .add(PalladioComponentModelElementTypes.AssemblyEventConnector_4007); |
267 | return types; |
268 | } |
269 | |
270 | /** |
271 | * @generated |
272 | */ |
273 | public List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/getMATypesForSource( |
274 | IElementType relationshipType) { |
275 | List/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/types = new ArrayList/*<org.eclipse.gmf.runtime.emf.type.core.IElementType>*/(); |
276 | if (relationshipType == PalladioComponentModelElementTypes.AssemblyEventConnector_4007) { |
277 | types.add(PalladioComponentModelElementTypes.SourceRole_3013); |
278 | } |
279 | return types; |
280 | } |
281 | |
282 | /** |
283 | * @generated |
284 | */ |
285 | public class SinkRoleFigure extends RectangleFigure { |
286 | |
287 | /** |
288 | * @generated |
289 | */ |
290 | public SinkRoleFigure() { |
291 | this.setLineWidth(1); |
292 | this.setPreferredSize(new Dimension(getMapMode().DPtoLP(20), |
293 | getMapMode().DPtoLP(20))); |
294 | this.setMinimumSize(new Dimension(getMapMode().DPtoLP(0), |
295 | getMapMode().DPtoLP(0))); |
296 | this.setLocation(new Point(getMapMode().DPtoLP(40), getMapMode() |
297 | .DPtoLP(40))); |
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 | |
321 | } |