001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.AsyncActivity2ItemSemanticEditPolicy;
004: import newprocess.diagram.part.New_processVisualIDRegistry;
005: import newprocess.diagram.providers.New_processElementTypes;
006:
007: import org.eclipse.draw2d.ColorConstants;
008: import org.eclipse.draw2d.Graphics;
009: import org.eclipse.draw2d.IFigure;
010: import org.eclipse.draw2d.LineBorder;
011: import org.eclipse.draw2d.RectangleFigure;
012: import org.eclipse.draw2d.StackLayout;
013: import org.eclipse.draw2d.ToolbarLayout;
014: import org.eclipse.draw2d.geometry.Dimension;
015: import org.eclipse.emf.common.notify.Notification;
016: import org.eclipse.gef.EditPart;
017: import org.eclipse.gef.EditPolicy;
018: import org.eclipse.gef.Request;
019: import org.eclipse.gef.commands.Command;
020: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
021: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
022: import org.eclipse.gef.requests.CreateRequest;
023: import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
024: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
025: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
026: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
027: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy;
028: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
029: import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
030: import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
031: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
032: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
033: import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
034: import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
035: import org.eclipse.gmf.runtime.notation.View;
036: import org.eclipse.swt.graphics.Color;
037:
038: /**
039: * @generated
040: */
041: public class AsyncActivity2EditPart extends ShapeNodeEditPart {
042:
043: /**
044: * @generated
045: */
046: public static final int VISUAL_ID = 2004;
047:
048: /**
049: * @generated
050: */
051: protected IFigure contentPane;
052:
053: /**
054: * @generated
055: */
056: protected IFigure primaryShape;
057:
058: /**
059: * @generated
060: */
061: public AsyncActivity2EditPart(View view) {
062: super (view);
063: }
064:
065: /**
066: * @generated
067: */
068: protected void createDefaultEditPolicies() {
069: installEditPolicy(EditPolicyRoles.CREATION_ROLE,
070: new CreationEditPolicy() {
071:
072: public Command getCommand(Request request) {
073: if (understandsRequest(request)) {
074: if (request instanceof CreateViewAndElementRequest) {
075: CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request)
076: .getViewAndElementDescriptor()
077: .getCreateElementRequestAdapter();
078: IElementType type = (IElementType) adapter
079: .getAdapter(IElementType.class);
080: if (type == New_processElementTypes.Expression_3008) {
081: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
082: .getType(AsyncActivityAsyncActivityPreconditionCompartment2EditPart.VISUAL_ID));
083: return compartmentEditPart == null ? null
084: : compartmentEditPart
085: .getCommand(request);
086: }
087: if (type == New_processElementTypes.Expression_3009) {
088: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
089: .getType(AsyncActivityAsyncActivityPostconditionCompartment2EditPart.VISUAL_ID));
090: return compartmentEditPart == null ? null
091: : compartmentEditPart
092: .getCommand(request);
093: }
094: }
095: return super .getCommand(request);
096: }
097: return null;
098: }
099: });
100: super .createDefaultEditPolicies();
101:
102: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
103: new AsyncActivity2ItemSemanticEditPolicy());
104: installEditPolicy(EditPolicy.LAYOUT_ROLE,
105: createLayoutEditPolicy());
106: }
107:
108: /**
109: * @generated
110: */
111: protected LayoutEditPolicy createLayoutEditPolicy() {
112: LayoutEditPolicy lep = new LayoutEditPolicy() {
113:
114: protected EditPolicy createChildEditPolicy(EditPart child) {
115: EditPolicy result = child
116: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
117: if (result == null) {
118: result = new NonResizableEditPolicy();
119: }
120: return result;
121: }
122:
123: protected Command getMoveChildrenCommand(Request request) {
124: return null;
125: }
126:
127: protected Command getCreateCommand(CreateRequest request) {
128: return null;
129: }
130: };
131: return lep;
132: }
133:
134: /**
135: * @generated
136: */
137: protected IFigure createNodeShape() {
138: AsyncActivityFigure figure = new AsyncActivityFigure();
139: return primaryShape = figure;
140: }
141:
142: /**
143: * @generated
144: */
145: public AsyncActivityFigure getPrimaryShape() {
146: return (AsyncActivityFigure) primaryShape;
147: }
148:
149: /**
150: * overwritten to update the ActivityDecorators
151: * @author sh
152: */
153: @Override
154: public void notifyChanged(Notification notification) {
155: super .notifyChanged(notification);
156:
157: // notify the decorator
158: Object editPolicy = this
159: .getEditPolicy(EditPolicyRoles.DECORATION_ROLE);
160: if (editPolicy instanceof DecorationEditPolicy) {
161: ((DecorationEditPolicy) editPolicy).refresh();
162: }
163: }
164:
165: /**
166: * @generated
167: */
168: protected boolean addFixedChild(EditPart childEditPart) {
169: if (childEditPart instanceof AsyncActivityName2EditPart) {
170: ((AsyncActivityName2EditPart) childEditPart)
171: .setLabel(getPrimaryShape()
172: .getFigureAsyncActivityNameFigure());
173: return true;
174: }
175: if (childEditPart instanceof AsyncActivityAsyncActivityPreconditionCompartment2EditPart) {
176: IFigure pane = getPrimaryShape()
177: .getFigureAsyncActivityPreconditionFigure();
178: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
179: pane
180: .add(((AsyncActivityAsyncActivityPreconditionCompartment2EditPart) childEditPart)
181: .getFigure());
182: return true;
183: }
184: if (childEditPart instanceof AsyncActivityAsyncActivityPostconditionCompartment2EditPart) {
185: IFigure pane = getPrimaryShape()
186: .getFigureAsyncActivityPostconditionFigure();
187: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
188: pane
189: .add(((AsyncActivityAsyncActivityPostconditionCompartment2EditPart) childEditPart)
190: .getFigure());
191: return true;
192: }
193: return false;
194: }
195:
196: /**
197: * @generated
198: */
199: protected boolean removeFixedChild(EditPart childEditPart) {
200:
201: if (childEditPart instanceof AsyncActivityAsyncActivityPreconditionCompartment2EditPart) {
202: IFigure pane = getPrimaryShape()
203: .getFigureAsyncActivityPreconditionFigure();
204: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
205: pane
206: .remove(((AsyncActivityAsyncActivityPreconditionCompartment2EditPart) childEditPart)
207: .getFigure());
208: return true;
209: }
210: if (childEditPart instanceof AsyncActivityAsyncActivityPostconditionCompartment2EditPart) {
211: IFigure pane = getPrimaryShape()
212: .getFigureAsyncActivityPostconditionFigure();
213: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
214: pane
215: .remove(((AsyncActivityAsyncActivityPostconditionCompartment2EditPart) childEditPart)
216: .getFigure());
217: return true;
218: }
219: return false;
220: }
221:
222: /**
223: * @generated
224: */
225: protected void addChildVisual(EditPart childEditPart, int index) {
226: if (addFixedChild(childEditPart)) {
227: return;
228: }
229: super .addChildVisual(childEditPart, -1);
230: }
231:
232: /**
233: * @generated
234: */
235: protected void removeChildVisual(EditPart childEditPart) {
236: if (removeFixedChild(childEditPart)) {
237: return;
238: }
239: super .removeChildVisual(childEditPart);
240: }
241:
242: /**
243: * @generated
244: */
245: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
246:
247: if (editPart instanceof AsyncActivityAsyncActivityPreconditionCompartment2EditPart) {
248: return getPrimaryShape()
249: .getFigureAsyncActivityPreconditionFigure();
250: }
251: if (editPart instanceof AsyncActivityAsyncActivityPostconditionCompartment2EditPart) {
252: return getPrimaryShape()
253: .getFigureAsyncActivityPostconditionFigure();
254: }
255: return super .getContentPaneFor(editPart);
256: }
257:
258: /**
259: * @generated
260: */
261: protected NodeFigure createNodePlate() {
262: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
263: getMapMode().DPtoLP(100), getMapMode().DPtoLP(160));
264:
265: return result;
266: }
267:
268: /**
269: * Creates figure for this edit part.
270: *
271: * Body of this method does not depend on settings in generation model
272: * so you may safely remove <i>generated</i> tag and modify it.
273: *
274: * @generated
275: */
276: protected NodeFigure createNodeFigure() {
277: NodeFigure figure = createNodePlate();
278: figure.setLayoutManager(new StackLayout());
279: IFigure shape = createNodeShape();
280: figure.add(shape);
281: contentPane = setupContentPane(shape);
282: return figure;
283: }
284:
285: /**
286: * Default implementation treats passed figure as content pane.
287: * Respects layout one may have set for generated figure.
288: * @param nodeShape instance of generated figure class
289: * @generated NOT
290: * @author sh
291: */
292: protected IFigure setupContentPane(IFigure nodeShape) {
293: if (nodeShape.getLayoutManager() == null) {
294: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
295: layout.setSpacing(getMapMode().DPtoLP(0));
296: layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
297: nodeShape.setLayoutManager(layout);
298: }
299: return nodeShape; // use nodeShape itself as contentPane
300: }
301:
302: /**
303: * @generated
304: */
305: public IFigure getContentPane() {
306: if (contentPane != null) {
307: return contentPane;
308: }
309: return super .getContentPane();
310: }
311:
312: /**
313: * @generated
314: */
315: public EditPart getPrimaryChildEditPart() {
316: return getChildBySemanticHint(New_processVisualIDRegistry
317: .getType(AsyncActivityName2EditPart.VISUAL_ID));
318: }
319:
320: /**
321: * @generated
322: */
323: public class AsyncActivityFigure extends RectangleFigure {
324: /**
325: * @generated NOT
326: * @author sh
327: */
328: public AsyncActivityFigure() {
329: this .setFill(true);
330: this .setFillXOR(false);
331: this .setOutline(true);
332: this .setOutlineXOR(false);
333: this .setLineWidth(0);
334: this .setLineStyle(Graphics.LINE_SOLID);
335: this .setPreferredSize(new Dimension(getMapMode()
336: .DPtoLP(100), getMapMode().DPtoLP(160)));
337: createContents();
338:
339: //******************* gradient *******************************
340: Color[] highlight = { ColorConstants.black,
341: ColorConstants.white };
342: Color[] shadow = { ColorConstants.white,
343: ColorConstants.black };
344: //this.setBorder(new SchemeBorder(new SchemeBorder.Scheme(highlight, shadow)));
345: this .setBorder(new LineBorder(ColorConstants.lightGray, 1));
346: //************************************************************
347: }
348:
349: /**
350: * @generated NOT
351: * @author sh
352: */
353: private void createContents() {
354: // The Precondition Compartment
355: RectangleFigure asyncActivityPreconditionFigure0 = new RectangleFigure();
356: asyncActivityPreconditionFigure0.setFill(true);
357: asyncActivityPreconditionFigure0.setFillXOR(false);
358: asyncActivityPreconditionFigure0.setOutline(true);
359: asyncActivityPreconditionFigure0.setOutlineXOR(false);
360: asyncActivityPreconditionFigure0.setLineWidth(1);
361: asyncActivityPreconditionFigure0
362: .setLineStyle(Graphics.LINE_SOLID);
363: this .add(asyncActivityPreconditionFigure0);
364: setFigureAsyncActivityPreconditionFigure(asyncActivityPreconditionFigure0);
365:
366: // The Activity Name Figuer
367: WrapLabel asyncActivityNameFigure0 = new WrapLabel();
368: asyncActivityNameFigure0.setText("<...>");
369: this .add(asyncActivityNameFigure0);
370: setFigureAsyncActivityNameFigure(asyncActivityNameFigure0);
371:
372: // The Postcondition Compartment
373: RectangleFigure asyncActivityPostconditionFigure0 = new RectangleFigure();
374: asyncActivityPostconditionFigure0.setFill(true);
375: asyncActivityPostconditionFigure0.setFillXOR(false);
376: asyncActivityPostconditionFigure0.setOutline(true);
377: asyncActivityPostconditionFigure0.setOutlineXOR(false);
378: asyncActivityPostconditionFigure0.setLineWidth(1);
379: asyncActivityPostconditionFigure0
380: .setLineStyle(Graphics.LINE_SOLID);
381: this .add(asyncActivityPostconditionFigure0);
382: setFigureAsyncActivityPostconditionFigure(asyncActivityPostconditionFigure0);
383: }
384:
385: /**
386: * @generated
387: */
388: private WrapLabel fAsyncActivityNameFigure;
389:
390: /**
391: * @generated
392: */
393: public WrapLabel getFigureAsyncActivityNameFigure() {
394: return fAsyncActivityNameFigure;
395: }
396:
397: /**
398: * @generated
399: */
400: private void setFigureAsyncActivityNameFigure(WrapLabel fig) {
401: fAsyncActivityNameFigure = fig;
402: }
403:
404: /**
405: * @generated
406: */
407: private RectangleFigure fAsyncActivityPreconditionFigure;
408:
409: /**
410: * @generated
411: */
412: public RectangleFigure getFigureAsyncActivityPreconditionFigure() {
413: return fAsyncActivityPreconditionFigure;
414: }
415:
416: /**
417: * @generated
418: */
419: private void setFigureAsyncActivityPreconditionFigure(
420: RectangleFigure fig) {
421: fAsyncActivityPreconditionFigure = fig;
422: }
423:
424: /**
425: * @generated
426: */
427: private RectangleFigure fAsyncActivityPostconditionFigure;
428:
429: /**
430: * @generated
431: */
432: public RectangleFigure getFigureAsyncActivityPostconditionFigure() {
433: return fAsyncActivityPostconditionFigure;
434: }
435:
436: /**
437: * @generated
438: */
439: private void setFigureAsyncActivityPostconditionFigure(
440: RectangleFigure fig) {
441: fAsyncActivityPostconditionFigure = fig;
442: }
443:
444: /**
445: * @generated
446: */
447: private boolean myUseLocalCoordinates = false;
448:
449: /**
450: * @generated
451: */
452: protected boolean useLocalCoordinates() {
453: return myUseLocalCoordinates;
454: }
455:
456: /**
457: * @generated
458: */
459: protected void setUseLocalCoordinates(
460: boolean useLocalCoordinates) {
461: myUseLocalCoordinates = useLocalCoordinates;
462: }
463:
464: }
465:
466: }
|