001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.ExpansionItemSemanticEditPolicy;
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 ExpansionEditPart extends ShapeNodeEditPart {
039:
040: /**
041: * @generated
042: */
043: public static final int VISUAL_ID = 2009;
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 ExpansionEditPart(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_3011) {
078: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
079: .getType(ExpansionExpansionPostconditionCompartmentEditPart.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 ExpansionItemSemanticEditPolicy());
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: ExpansionFigure figure = new ExpansionFigure();
129: return primaryShape = figure;
130: }
131:
132: /**
133: * @generated
134: */
135: public ExpansionFigure getPrimaryShape() {
136: return (ExpansionFigure) primaryShape;
137: }
138:
139: /**
140: * @generated
141: */
142: protected boolean addFixedChild(EditPart childEditPart) {
143: if (childEditPart instanceof ExpansionNameEditPart) {
144: ((ExpansionNameEditPart) childEditPart)
145: .setLabel(getPrimaryShape()
146: .getFigureExpansionNameFigure());
147: return true;
148: }
149: if (childEditPart instanceof ExpansionExpansionPostconditionCompartmentEditPart) {
150: IFigure pane = getPrimaryShape()
151: .getFigureExpansionPostconditionFigure();
152: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
153: pane
154: .add(((ExpansionExpansionPostconditionCompartmentEditPart) 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 ExpansionExpansionPostconditionCompartmentEditPart) {
167: IFigure pane = getPrimaryShape()
168: .getFigureExpansionPostconditionFigure();
169: setupContentPane(pane); // FIXME each comparment should handle his content pane in his own way
170: pane
171: .remove(((ExpansionExpansionPostconditionCompartmentEditPart) 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 ExpansionExpansionPostconditionCompartmentEditPart) {
204: return getPrimaryShape()
205: .getFigureExpansionPostconditionFigure();
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(ExpansionNameEditPart.VISUAL_ID));
268: }
269:
270: /**
271: * @generated
272: */
273: public class ExpansionFigure extends RectangleFigure {
274: /**
275: * @generated NOT
276: * @author sh
277: */
278: public ExpansionFigure() {
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 Expansion Name Figure
305: WrapLabel expansionNameFigure0 = new WrapLabel();
306: expansionNameFigure0.setText("<...>");
307: this .add(expansionNameFigure0);
308: setFigureExpansionNameFigure(expansionNameFigure0);
309:
310: // The Postcondition Compartment
311: RectangleFigure expansionPostconditionFigure0 = new RectangleFigure();
312: expansionPostconditionFigure0.setFill(true);
313: expansionPostconditionFigure0.setFillXOR(false);
314: expansionPostconditionFigure0.setOutline(true);
315: expansionPostconditionFigure0.setOutlineXOR(false);
316: expansionPostconditionFigure0.setLineWidth(1);
317: expansionPostconditionFigure0
318: .setLineStyle(Graphics.LINE_SOLID);
319: this .add(expansionPostconditionFigure0);
320: setFigureExpansionPostconditionFigure(expansionPostconditionFigure0);
321: }
322:
323: /**
324: * @generated
325: */
326: private WrapLabel fExpansionNameFigure;
327:
328: /**
329: * @generated
330: */
331: public WrapLabel getFigureExpansionNameFigure() {
332: return fExpansionNameFigure;
333: }
334:
335: /**
336: * @generated
337: */
338: private void setFigureExpansionNameFigure(WrapLabel fig) {
339: fExpansionNameFigure = fig;
340: }
341:
342: /**
343: * @generated
344: */
345: private RectangleFigure fExpansionPostconditionFigure;
346:
347: /**
348: * @generated
349: */
350: public RectangleFigure getFigureExpansionPostconditionFigure() {
351: return fExpansionPostconditionFigure;
352: }
353:
354: /**
355: * @generated
356: */
357: private void setFigureExpansionPostconditionFigure(
358: RectangleFigure fig) {
359: fExpansionPostconditionFigure = 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: }
|