001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.cust.policies.NodeComponentEditPolicy;
004: import newprocess.diagram.edit.policies.GlobalsItemSemanticEditPolicy;
005: import newprocess.diagram.part.New_processVisualIDRegistry;
006: import newprocess.diagram.providers.New_processElementTypes;
007:
008: import org.eclipse.draw2d.ColorConstants;
009: import org.eclipse.draw2d.Graphics;
010: import org.eclipse.draw2d.IFigure;
011: import org.eclipse.draw2d.RectangleFigure;
012: import org.eclipse.draw2d.SchemeBorder;
013: import org.eclipse.draw2d.StackLayout;
014: import org.eclipse.draw2d.geometry.Dimension;
015: import org.eclipse.gef.EditPart;
016: import org.eclipse.gef.EditPolicy;
017: import org.eclipse.gef.Request;
018: import org.eclipse.gef.commands.Command;
019: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
020: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
021: import org.eclipse.gef.requests.CreateRequest;
022: import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
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 GlobalsEditPart extends ShapeNodeEditPart {
039:
040: /**
041: * @generated
042: */
043: public static final int VISUAL_ID = 2011;
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 GlobalsEditPart(View view) {
059: super (view);
060: }
061:
062: /**
063: * @generated NOT
064: * @author sh
065: */
066: protected void createDefaultEditPolicies() {
067: installEditPolicy(EditPolicyRoles.CREATION_ROLE,
068: new CreationEditPolicy() {
069:
070: public Command getCommand(Request request) {
071: if (understandsRequest(request)) {
072: if (request instanceof CreateViewAndElementRequest) {
073: CreateElementRequestAdapter adapter = ((CreateViewAndElementRequest) request)
074: .getViewAndElementDescriptor()
075: .getCreateElementRequestAdapter();
076: IElementType type = (IElementType) adapter
077: .getAdapter(IElementType.class);
078: if (type == New_processElementTypes.Loader_3013) {
079: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
080: .getType(GlobalsGlobalsLoaderCompartmentEditPart.VISUAL_ID));
081: return compartmentEditPart == null ? null
082: : compartmentEditPart
083: .getCommand(request);
084: }
085: if (type == New_processElementTypes.Condition_3014) {
086: EditPart compartmentEditPart = getChildBySemanticHint(New_processVisualIDRegistry
087: .getType(GlobalsGlobalsConditionCompartmentEditPart.VISUAL_ID));
088: return compartmentEditPart == null ? null
089: : compartmentEditPart
090: .getCommand(request);
091: }
092: }
093: return super .getCommand(request);
094: }
095: return null;
096: }
097: });
098: super .createDefaultEditPolicies();
099:
100: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
101: new GlobalsItemSemanticEditPolicy());
102: installEditPolicy(EditPolicy.LAYOUT_ROLE,
103: createLayoutEditPolicy());
104: // install this policy to disable deleting of the Globals Figure
105: installEditPolicy(EditPolicy.COMPONENT_ROLE,
106: new NodeComponentEditPolicy());
107: }
108:
109: /**
110: * @generated
111: */
112: protected LayoutEditPolicy createLayoutEditPolicy() {
113: LayoutEditPolicy lep = new LayoutEditPolicy() {
114:
115: protected EditPolicy createChildEditPolicy(EditPart child) {
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: GlobalsFigure figure = new GlobalsFigure();
140: return primaryShape = figure;
141: }
142:
143: /**
144: * @generated
145: */
146: public GlobalsFigure getPrimaryShape() {
147: return (GlobalsFigure) primaryShape;
148: }
149:
150: /**
151: * @generated
152: */
153: protected NodeFigure createNodePlate() {
154: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
155: getMapMode().DPtoLP(120), getMapMode().DPtoLP(120));
156:
157: return result;
158: }
159:
160: /**
161: * Creates figure for this edit part.
162: *
163: * Body of this method does not depend on settings in generation model
164: * so you may safely remove <i>generated</i> tag and modify it.
165: *
166: * @generated
167: */
168: protected NodeFigure createNodeFigure() {
169: NodeFigure figure = createNodePlate();
170: figure.setLayoutManager(new StackLayout());
171: IFigure shape = createNodeShape();
172: figure.add(shape);
173: contentPane = setupContentPane(shape);
174: return figure;
175: }
176:
177: /**
178: * Default implementation treats passed figure as content pane.
179: * Respects layout one may have set for generated figure.
180: * @param nodeShape instance of generated figure class
181: * @generated
182: */
183: protected IFigure setupContentPane(IFigure nodeShape) {
184: if (nodeShape.getLayoutManager() == null) {
185: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
186: layout.setSpacing(getMapMode().DPtoLP(5));
187: nodeShape.setLayoutManager(layout);
188: }
189: return nodeShape; // use nodeShape itself as contentPane
190: }
191:
192: /**
193: * @generated
194: */
195: public IFigure getContentPane() {
196: if (contentPane != null) {
197: return contentPane;
198: }
199: return super .getContentPane();
200: }
201:
202: /**
203: * @generated
204: */
205: public class GlobalsFigure extends RectangleFigure {
206: /**
207: * @generated NOT
208: * @author sh
209: */
210: public GlobalsFigure() {
211: this .setFill(true);
212: this .setFillXOR(false);
213: this .setOutline(true);
214: this .setOutlineXOR(false);
215: this .setLineWidth(1);
216: this .setLineStyle(Graphics.LINE_SOLID);
217: this .setBackgroundColor(GLOBALSFIGURE_BACK);
218: this .setPreferredSize(new Dimension(getMapMode()
219: .DPtoLP(120), getMapMode().DPtoLP(120)));
220: createContents();
221:
222: //******************* gradient *******************************
223: Color[] highlight = { ColorConstants.black,
224: ColorConstants.white };
225: Color[] shadow = { ColorConstants.white,
226: ColorConstants.black };
227: this .setBorder(new SchemeBorder(new SchemeBorder.Scheme(
228: highlight, shadow)));
229: //this.setBorder(new SchemeBorder(SchemeBorder.SCHEMES.ETCHED));
230: //************************************************************
231: }
232:
233: /**
234: * @generated
235: */
236: private void createContents() {
237:
238: WrapLabel globalsNameFigure0 = new WrapLabel();
239: globalsNameFigure0.setText("Globals");
240:
241: this .add(globalsNameFigure0);
242: setFigureGlobalsNameFigure(globalsNameFigure0);
243:
244: }
245:
246: /**
247: * @generated
248: */
249: private WrapLabel fGlobalsNameFigure;
250:
251: /**
252: * @generated
253: */
254: public WrapLabel getFigureGlobalsNameFigure() {
255: return fGlobalsNameFigure;
256: }
257:
258: /**
259: * @generated
260: */
261: private void setFigureGlobalsNameFigure(WrapLabel fig) {
262: fGlobalsNameFigure = fig;
263: }
264:
265: /**
266: * @generated
267: */
268: private boolean myUseLocalCoordinates = false;
269:
270: /**
271: * @generated
272: */
273: protected boolean useLocalCoordinates() {
274: return myUseLocalCoordinates;
275: }
276:
277: /**
278: * @generated
279: */
280: protected void setUseLocalCoordinates(
281: boolean useLocalCoordinates) {
282: myUseLocalCoordinates = useLocalCoordinates;
283: }
284:
285: }
286:
287: /**
288: * @generated
289: */
290: static final Color GLOBALSFIGURE_BACK = new Color(null, 255, 255,
291: 170);
292:
293: }
|