001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.ConclusionItemSemanticEditPolicy;
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.geometry.Dimension;
014: import org.eclipse.gef.EditPart;
015: import org.eclipse.gef.EditPolicy;
016: import org.eclipse.gef.Request;
017: import org.eclipse.gef.commands.Command;
018: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
019: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
020: import org.eclipse.gef.requests.CreateRequest;
021: import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
022: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
023: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
024: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
025: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
026: import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest;
027: import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
028: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
029: import org.eclipse.gmf.runtime.emf.type.core.IElementType;
030: import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
031: import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
032: import org.eclipse.gmf.runtime.notation.View;
033: import org.eclipse.swt.graphics.Color;
034:
035: /**
036: * @generated
037: */
038: public class ConclusionEditPart extends ShapeNodeEditPart {
039:
040: /**
041: * @generated
042: */
043: public static final int VISUAL_ID = 2010;
044:
045: /**
046: * @generated
047: */
048: protected IFigure contentPane;
049:
050: /**
051: * @generated
052: */
053: protected IFigure primaryShape;
054:
055: /**
056: * @generated
057: */
058: public ConclusionEditPart(View view) {
059: super (view);
060: }
061:
062: /**
063: * @generated
064: */
065: protected void createDefaultEditPolicies() {
066: installEditPolicy(EditPolicyRoles.CREATION_ROLE,
067: new CreationEditPolicy() {
068:
069: public Command getCommand(Request request) {
070: if (understandsRequest(request)) {
071: if (request instanceof CreateViewAndElementRequest) {
072: CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request)
073: .getViewAndElementDescriptor()
074: .getCreateElementRequestAdapter();
075: IElementType type = (IElementType) adapter
076: .getAdapter(IElementType.class);
077: if (type == New_processElementTypes.Expression_3012) {
078: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
079: .getType(ConclusionConclusionPostconditionCompartmentEditPart.VISUAL_ID));
080: return compartmentEditPart == null ? null
081: : compartmentEditPart
082: .getCommand(request);
083: }
084: }
085: return super .getCommand(request);
086: }
087: return null;
088: }
089: });
090: super .createDefaultEditPolicies();
091:
092: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
093: new ConclusionItemSemanticEditPolicy());
094: installEditPolicy(EditPolicy.LAYOUT_ROLE,
095: createLayoutEditPolicy());
096: }
097:
098: /**
099: * @generated
100: */
101: protected LayoutEditPolicy createLayoutEditPolicy() {
102: LayoutEditPolicy lep = new LayoutEditPolicy() {
103:
104: protected EditPolicy createChildEditPolicy(EditPart child) {
105: EditPolicy result = child
106: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
107: if (result == null) {
108: result = new NonResizableEditPolicy();
109: }
110: return result;
111: }
112:
113: protected Command getMoveChildrenCommand(Request request) {
114: return null;
115: }
116:
117: protected Command getCreateCommand(CreateRequest request) {
118: return null;
119: }
120: };
121: return lep;
122: }
123:
124: /**
125: * @generated
126: */
127: protected IFigure createNodeShape() {
128: ConclusionFigure figure = new ConclusionFigure();
129: return primaryShape = figure;
130: }
131:
132: /**
133: * @generated
134: */
135: public ConclusionFigure getPrimaryShape() {
136: return (ConclusionFigure) primaryShape;
137: }
138:
139: /**
140: * @generated
141: */
142: protected boolean addFixedChild(EditPart childEditPart) {
143: if (childEditPart instanceof ConclusionNameEditPart) {
144: ((ConclusionNameEditPart) childEditPart)
145: .setLabel(getPrimaryShape()
146: .getFigureConclusionNameFigure());
147: return true;
148: }
149: if (childEditPart instanceof ConclusionConclusionPostconditionCompartmentEditPart) {
150: IFigure pane = getPrimaryShape()
151: .getFigureConclusionPostconditionFigure();
152: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
153: pane
154: .add(((ConclusionConclusionPostconditionCompartmentEditPart) childEditPart)
155: .getFigure());
156: return true;
157: }
158: return false;
159: }
160:
161: /**
162: * @generated
163: */
164: protected boolean removeFixedChild(EditPart childEditPart) {
165:
166: if (childEditPart instanceof ConclusionConclusionPostconditionCompartmentEditPart) {
167: IFigure pane = getPrimaryShape()
168: .getFigureConclusionPostconditionFigure();
169: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
170: pane
171: .remove(((ConclusionConclusionPostconditionCompartmentEditPart) childEditPart)
172: .getFigure());
173: return true;
174: }
175: return false;
176: }
177:
178: /**
179: * @generated
180: */
181: protected void addChildVisual(EditPart childEditPart, int index) {
182: if (addFixedChild(childEditPart)) {
183: return;
184: }
185: super .addChildVisual(childEditPart, -1);
186: }
187:
188: /**
189: * @generated
190: */
191: protected void removeChildVisual(EditPart childEditPart) {
192: if (removeFixedChild(childEditPart)) {
193: return;
194: }
195: super .removeChildVisual(childEditPart);
196: }
197:
198: /**
199: * @generated
200: */
201: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
202:
203: if (editPart instanceof ConclusionConclusionPostconditionCompartmentEditPart) {
204: return getPrimaryShape()
205: .getFigureConclusionPostconditionFigure();
206: }
207: return super .getContentPaneFor(editPart);
208: }
209:
210: /**
211: * @generated
212: */
213: protected NodeFigure createNodePlate() {
214: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
215: getMapMode().DPtoLP(100), getMapMode().DPtoLP(88));
216:
217: return result;
218: }
219:
220: /**
221: * Creates figure for this edit part.
222: *
223: * Body of this method does not depend on settings in generation model
224: * so you may safely remove <i>generated</i> tag and modify it.
225: *
226: * @generated
227: */
228: protected NodeFigure createNodeFigure() {
229: NodeFigure figure = createNodePlate();
230: figure.setLayoutManager(new StackLayout());
231: IFigure shape = createNodeShape();
232: figure.add(shape);
233: contentPane = setupContentPane(shape);
234: return figure;
235: }
236:
237: /**
238: * Default implementation treats passed figure as content pane.
239: * Respects layout one may have set for generated figure.
240: * @param nodeShape instance of generated figure class
241: * @generated
242: */
243: protected IFigure setupContentPane(IFigure nodeShape) {
244: if (nodeShape.getLayoutManager() == null) {
245: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
246: layout.setSpacing(getMapMode().DPtoLP(5));
247: nodeShape.setLayoutManager(layout);
248: }
249: return nodeShape; // use nodeShape itself as contentPane
250: }
251:
252: /**
253: * @generated
254: */
255: public IFigure getContentPane() {
256: if (contentPane != null) {
257: return contentPane;
258: }
259: return super .getContentPane();
260: }
261:
262: /**
263: * @generated
264: */
265: public EditPart getPrimaryChildEditPart() {
266: return getChildBySemanticHint(New_processVisualIDRegistry
267: .getType(ConclusionNameEditPart.VISUAL_ID));
268: }
269:
270: /**
271: * @generated
272: */
273: public class ConclusionFigure extends RectangleFigure {
274: /**
275: * @generated NOT
276: * @author sh
277: */
278: public ConclusionFigure() {
279: this .setFill(true);
280: this .setFillXOR(false);
281: this .setOutline(true);
282: this .setOutlineXOR(false);
283: this .setLineWidth(0);
284: this .setLineStyle(Graphics.LINE_SOLID);
285: this .setPreferredSize(new Dimension(getMapMode()
286: .DPtoLP(100), getMapMode().DPtoLP(88)));
287: createContents();
288:
289: //******************* gradient *******************************
290: Color[] highlight = { ColorConstants.black,
291: ColorConstants.white };
292: Color[] shadow = { ColorConstants.white,
293: ColorConstants.black };
294: //this.setBorder(new SchemeBorder(new SchemeBorder.Scheme(highlight,shadow)));
295: this .setBorder(new LineBorder(ColorConstants.lightGray, 1));
296: //************************************************************
297: }
298:
299: /**
300: * @generated NOT
301: * @author sh
302: */
303: private void createContents() {
304: // The Precondition Compartment
305: RectangleFigure conclusionPostconditionFigure0 = new RectangleFigure();
306: conclusionPostconditionFigure0.setFill(true);
307: conclusionPostconditionFigure0.setFillXOR(false);
308: conclusionPostconditionFigure0.setOutline(true);
309: conclusionPostconditionFigure0.setOutlineXOR(false);
310: conclusionPostconditionFigure0.setLineWidth(1);
311: conclusionPostconditionFigure0
312: .setLineStyle(Graphics.LINE_SOLID);
313: this .add(conclusionPostconditionFigure0);
314: setFigureConclusionPostconditionFigure(conclusionPostconditionFigure0);
315:
316: // The Conclusion Name Figure
317: WrapLabel conclusionNameFigure0 = new WrapLabel();
318: conclusionNameFigure0.setText("<...>");
319: this .add(conclusionNameFigure0);
320: setFigureConclusionNameFigure(conclusionNameFigure0);
321: }
322:
323: /**
324: * @generated
325: */
326: private WrapLabel fConclusionNameFigure;
327:
328: /**
329: * @generated
330: */
331: public WrapLabel getFigureConclusionNameFigure() {
332: return fConclusionNameFigure;
333: }
334:
335: /**
336: * @generated
337: */
338: private void setFigureConclusionNameFigure(WrapLabel fig) {
339: fConclusionNameFigure = fig;
340: }
341:
342: /**
343: * @generated
344: */
345: private RectangleFigure fConclusionPostconditionFigure;
346:
347: /**
348: * @generated
349: */
350: public RectangleFigure getFigureConclusionPostconditionFigure() {
351: return fConclusionPostconditionFigure;
352: }
353:
354: /**
355: * @generated
356: */
357: private void setFigureConclusionPostconditionFigure(
358: RectangleFigure fig) {
359: fConclusionPostconditionFigure = fig;
360: }
361:
362: /**
363: * @generated
364: */
365: private boolean myUseLocalCoordinates = false;
366:
367: /**
368: * @generated
369: */
370: protected boolean useLocalCoordinates() {
371: return myUseLocalCoordinates;
372: }
373:
374: /**
375: * @generated
376: */
377: protected void setUseLocalCoordinates(
378: boolean useLocalCoordinates) {
379: myUseLocalCoordinates = useLocalCoordinates;
380: }
381:
382: }
383:
384: }
|