001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.EventItemSemanticEditPolicy;
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 EventEditPart extends ShapeNodeEditPart {
042:
043: /**
044: * @generated
045: */
046: public static final int VISUAL_ID = 2005;
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 EventEditPart(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_3010) {
081: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
082: .getType(EventEventPostconditionCompartmentEditPart.VISUAL_ID));
083: return compartmentEditPart == null ? null
084: : compartmentEditPart
085: .getCommand(request);
086: }
087: }
088: return super .getCommand(request);
089: }
090: return null;
091: }
092: });
093: super .createDefaultEditPolicies();
094:
095: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
096: new EventItemSemanticEditPolicy());
097: installEditPolicy(EditPolicy.LAYOUT_ROLE,
098: createLayoutEditPolicy());
099: }
100:
101: /**
102: * @generated
103: */
104: protected LayoutEditPolicy createLayoutEditPolicy() {
105: LayoutEditPolicy lep = new LayoutEditPolicy() {
106:
107: protected EditPolicy createChildEditPolicy(EditPart child) {
108: EditPolicy result = child
109: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
110: if (result == null) {
111: result = new NonResizableEditPolicy();
112: }
113: return result;
114: }
115:
116: protected Command getMoveChildrenCommand(Request request) {
117: return null;
118: }
119:
120: protected Command getCreateCommand(CreateRequest request) {
121: return null;
122: }
123: };
124: return lep;
125: }
126:
127: /**
128: * @generated
129: */
130: protected IFigure createNodeShape() {
131: EventFigure figure = new EventFigure();
132: return primaryShape = figure;
133: }
134:
135: /**
136: * @generated
137: */
138: public EventFigure getPrimaryShape() {
139: return (EventFigure) primaryShape;
140: }
141:
142: /**
143: * @generated
144: */
145: protected boolean addFixedChild(EditPart childEditPart) {
146: if (childEditPart instanceof EventNameEditPart) {
147: ((EventNameEditPart) childEditPart)
148: .setLabel(getPrimaryShape()
149: .getFigureEventNameFigure());
150: return true;
151: }
152: if (childEditPart instanceof EventEventPostconditionCompartmentEditPart) {
153: IFigure pane = getPrimaryShape()
154: .getFigureEventPostconditionFigure();
155: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
156: pane
157: .add(((EventEventPostconditionCompartmentEditPart) childEditPart)
158: .getFigure());
159: return true;
160: }
161: return false;
162: }
163:
164: /**
165: * @generated
166: */
167: protected boolean removeFixedChild(EditPart childEditPart) {
168:
169: if (childEditPart instanceof EventEventPostconditionCompartmentEditPart) {
170: IFigure pane = getPrimaryShape()
171: .getFigureEventPostconditionFigure();
172: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
173: pane
174: .remove(((EventEventPostconditionCompartmentEditPart) childEditPart)
175: .getFigure());
176: return true;
177: }
178: return false;
179: }
180:
181: /**
182: * @generated
183: */
184: protected void addChildVisual(EditPart childEditPart, int index) {
185: if (addFixedChild(childEditPart)) {
186: return;
187: }
188: super .addChildVisual(childEditPart, -1);
189: }
190:
191: /**
192: * @generated
193: */
194: protected void removeChildVisual(EditPart childEditPart) {
195: if (removeFixedChild(childEditPart)) {
196: return;
197: }
198: super .removeChildVisual(childEditPart);
199: }
200:
201: /**
202: * @generated
203: */
204: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
205:
206: if (editPart instanceof EventEventPostconditionCompartmentEditPart) {
207: return getPrimaryShape()
208: .getFigureEventPostconditionFigure();
209: }
210: return super .getContentPaneFor(editPart);
211: }
212:
213: /**
214: * overwritten to update the ActivityDecorators
215: * @author sh
216: */
217: @Override
218: public void notifyChanged(Notification notification) {
219: super .notifyChanged(notification);
220:
221: // notify the decorator
222: Object editPolicy = this
223: .getEditPolicy(EditPolicyRoles.DECORATION_ROLE);
224: if (editPolicy instanceof DecorationEditPolicy) {
225: ((DecorationEditPolicy) editPolicy).refresh();
226: }
227: }
228:
229: /**
230: * @generated
231: */
232: protected NodeFigure createNodePlate() {
233: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
234: getMapMode().DPtoLP(100), getMapMode().DPtoLP(88));
235:
236: return result;
237: }
238:
239: /**
240: * Creates figure for this edit part.
241: *
242: * Body of this method does not depend on settings in generation model
243: * so you may safely remove <i>generated</i> tag and modify it.
244: *
245: * @generated
246: */
247: protected NodeFigure createNodeFigure() {
248: NodeFigure figure = createNodePlate();
249: figure.setLayoutManager(new StackLayout());
250: IFigure shape = createNodeShape();
251: figure.add(shape);
252: contentPane = setupContentPane(shape);
253: return figure;
254: }
255:
256: /**
257: * Default implementation treats passed figure as content pane.
258: * Respects layout one may have set for generated figure.
259: * @param nodeShape instance of generated figure class
260: * @generated NOT
261: * @author sh
262: */
263: protected IFigure setupContentPane(IFigure nodeShape) {
264: if (nodeShape.getLayoutManager() == null) {
265: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
266: layout.setSpacing(getMapMode().DPtoLP(0));
267: layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
268: nodeShape.setLayoutManager(layout);
269: }
270: return nodeShape; // use nodeShape itself as contentPane
271: }
272:
273: /**
274: * @generated
275: */
276: public IFigure getContentPane() {
277: if (contentPane != null) {
278: return contentPane;
279: }
280: return super .getContentPane();
281: }
282:
283: /**
284: * @generated
285: */
286: public EditPart getPrimaryChildEditPart() {
287: return getChildBySemanticHint(New_processVisualIDRegistry
288: .getType(EventNameEditPart.VISUAL_ID));
289: }
290:
291: /**
292: * @generated
293: */
294: public class EventFigure extends RectangleFigure {
295: /**
296: * @generated NOT
297: * @author sh
298: */
299: public EventFigure() {
300: this .setFill(true);
301: this .setFillXOR(false);
302: this .setOutline(true);
303: this .setOutlineXOR(false);
304: this .setLineWidth(0);
305: this .setLineStyle(Graphics.LINE_SOLID);
306: this .setPreferredSize(new Dimension(getMapMode()
307: .DPtoLP(100), getMapMode().DPtoLP(88)));
308: createContents();
309:
310: //******************* gradient *******************************
311: Color[] highlight = { ColorConstants.black,
312: ColorConstants.white };
313: Color[] shadow = { ColorConstants.white,
314: ColorConstants.black };
315: //this.setBorder(new SchemeBorder(new SchemeBorder.Scheme(highlight,shadow)));
316: this .setBorder(new LineBorder(ColorConstants.lightGray, 1));
317: //************************************************************
318: }
319:
320: /**
321: * @generated NOT
322: * @author sh
323: */
324: private void createContents() {
325: // The Event Name Figure
326: WrapLabel eventNameFigure0 = new WrapLabel();
327: eventNameFigure0.setText("<...>");
328: this .add(eventNameFigure0);
329: setFigureEventNameFigure(eventNameFigure0);
330:
331: // The Postcondition Compartment
332: RectangleFigure eventPostconditionFigure0 = new RectangleFigure();
333: eventPostconditionFigure0.setFill(true);
334: eventPostconditionFigure0.setFillXOR(false);
335: eventPostconditionFigure0.setOutline(true);
336: eventPostconditionFigure0.setOutlineXOR(false);
337: eventPostconditionFigure0.setLineWidth(1);
338: eventPostconditionFigure0.setLineStyle(Graphics.LINE_SOLID);
339: this .add(eventPostconditionFigure0);
340: setFigureEventPostconditionFigure(eventPostconditionFigure0);
341: }
342:
343: /**
344: * @generated
345: */
346: private WrapLabel fEventNameFigure;
347:
348: /**
349: * @generated
350: */
351: public WrapLabel getFigureEventNameFigure() {
352: return fEventNameFigure;
353: }
354:
355: /**
356: * @generated
357: */
358: private void setFigureEventNameFigure(WrapLabel fig) {
359: fEventNameFigure = fig;
360: }
361:
362: /**
363: * @generated
364: */
365: private RectangleFigure fEventPostconditionFigure;
366:
367: /**
368: * @generated
369: */
370: public RectangleFigure getFigureEventPostconditionFigure() {
371: return fEventPostconditionFigure;
372: }
373:
374: /**
375: * @generated
376: */
377: private void setFigureEventPostconditionFigure(
378: RectangleFigure fig) {
379: fEventPostconditionFigure = fig;
380: }
381:
382: /**
383: * @generated
384: */
385: private boolean myUseLocalCoordinates = false;
386:
387: /**
388: * @generated
389: */
390: protected boolean useLocalCoordinates() {
391: return myUseLocalCoordinates;
392: }
393:
394: /**
395: * @generated
396: */
397: protected void setUseLocalCoordinates(
398: boolean useLocalCoordinates) {
399: myUseLocalCoordinates = useLocalCoordinates;
400: }
401:
402: }
403:
404: }
|