001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.diagram.edit.policies.ConditionItemSemanticEditPolicy;
004: import newprocess.diagram.part.New_processVisualIDRegistry;
005:
006: import org.eclipse.draw2d.Graphics;
007: import org.eclipse.draw2d.IFigure;
008: import org.eclipse.draw2d.RectangleFigure;
009: import org.eclipse.draw2d.StackLayout;
010: import org.eclipse.draw2d.geometry.Dimension;
011: import org.eclipse.emf.common.notify.Notification;
012: import org.eclipse.gef.EditPart;
013: import org.eclipse.gef.EditPolicy;
014: import org.eclipse.gef.Request;
015: import org.eclipse.gef.commands.Command;
016: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
017: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
018: import org.eclipse.gef.requests.CreateRequest;
019: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
020: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
021: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy;
022: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
023: import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
024: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
025: import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
026: import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
027: import org.eclipse.gmf.runtime.notation.View;
028: import org.eclipse.swt.graphics.Color;
029:
030: /**
031: * @generated
032: */
033: public class ConditionEditPart extends ShapeNodeEditPart {
034:
035: /**
036: * @generated
037: */
038: public static final int VISUAL_ID = 3014;
039:
040: /**
041: * @generated
042: */
043: protected IFigure contentPane;
044:
045: /**
046: * @generated
047: */
048: protected IFigure primaryShape;
049:
050: /**
051: * @generated
052: */
053: public ConditionEditPart(View view) {
054: super (view);
055: }
056:
057: /**
058: * @generated
059: */
060: protected void createDefaultEditPolicies() {
061: super .createDefaultEditPolicies();
062:
063: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
064: new ConditionItemSemanticEditPolicy());
065: installEditPolicy(EditPolicy.LAYOUT_ROLE,
066: createLayoutEditPolicy());
067: }
068:
069: /**
070: * @generated
071: */
072: protected LayoutEditPolicy createLayoutEditPolicy() {
073: LayoutEditPolicy lep = new LayoutEditPolicy() {
074:
075: protected EditPolicy createChildEditPolicy(EditPart child) {
076: EditPolicy result = child
077: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
078: if (result == null) {
079: result = new NonResizableEditPolicy();
080: }
081: return result;
082: }
083:
084: protected Command getMoveChildrenCommand(Request request) {
085: return null;
086: }
087:
088: protected Command getCreateCommand(CreateRequest request) {
089: return null;
090: }
091: };
092: return lep;
093: }
094:
095: /**
096: * @generated
097: */
098: protected IFigure createNodeShape() {
099: ConditionFigure figure = new ConditionFigure();
100: return primaryShape = figure;
101: }
102:
103: /**
104: * @generated
105: */
106: public ConditionFigure getPrimaryShape() {
107: return (ConditionFigure) primaryShape;
108: }
109:
110: /**
111: * @generated
112: */
113: protected boolean addFixedChild(EditPart childEditPart) {
114: if (childEditPart instanceof ConditionNameEditPart) {
115: ((ConditionNameEditPart) childEditPart)
116: .setLabel(getPrimaryShape()
117: .getFigureConditionNameFigure());
118: return true;
119: }
120: return false;
121: }
122:
123: /**
124: * @generated
125: */
126: protected boolean removeFixedChild(EditPart childEditPart) {
127:
128: return false;
129: }
130:
131: /**
132: * @generated
133: */
134: protected void addChildVisual(EditPart childEditPart, int index) {
135: if (addFixedChild(childEditPart)) {
136: return;
137: }
138: super .addChildVisual(childEditPart, -1);
139: }
140:
141: /**
142: * @generated
143: */
144: protected void removeChildVisual(EditPart childEditPart) {
145: if (removeFixedChild(childEditPart)) {
146: return;
147: }
148: super .removeChildVisual(childEditPart);
149: }
150:
151: /**
152: * @generated
153: */
154: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
155:
156: return super .getContentPaneFor(editPart);
157: }
158:
159: /**
160: * overwritten to update the ActivityDecorators
161: * @author sh
162: */
163: @Override
164: public void notifyChanged(Notification notification) {
165: super .notifyChanged(notification);
166:
167: // notify the decorator
168: Object editPolicy = this
169: .getEditPolicy(EditPolicyRoles.DECORATION_ROLE);
170: if (editPolicy instanceof DecorationEditPolicy) {
171: ((DecorationEditPolicy) editPolicy).refresh();
172: }
173: }
174:
175: /**
176: * @generated
177: */
178: protected NodeFigure createNodePlate() {
179: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
180: getMapMode().DPtoLP(120), getMapMode().DPtoLP(20));
181:
182: return result;
183: }
184:
185: /**
186: * Creates figure for this edit part.
187: *
188: * Body of this method does not depend on settings in generation model
189: * so you may safely remove <i>generated</i> tag and modify it.
190: *
191: * @generated
192: */
193: protected NodeFigure createNodeFigure() {
194: NodeFigure figure = createNodePlate();
195: figure.setLayoutManager(new StackLayout());
196: IFigure shape = createNodeShape();
197: figure.add(shape);
198: contentPane = setupContentPane(shape);
199: return figure;
200: }
201:
202: /**
203: * Default implementation treats passed figure as content pane.
204: * Respects layout one may have set for generated figure.
205: * @param nodeShape instance of generated figure class
206: * @generated
207: */
208: protected IFigure setupContentPane(IFigure nodeShape) {
209: if (nodeShape.getLayoutManager() == null) {
210: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
211: layout.setSpacing(getMapMode().DPtoLP(5));
212: nodeShape.setLayoutManager(layout);
213: }
214: return nodeShape; // use nodeShape itself as contentPane
215: }
216:
217: /**
218: * @generated
219: */
220: public IFigure getContentPane() {
221: if (contentPane != null) {
222: return contentPane;
223: }
224: return super .getContentPane();
225: }
226:
227: /**
228: * @generated
229: */
230: public EditPart getPrimaryChildEditPart() {
231: return getChildBySemanticHint(New_processVisualIDRegistry
232: .getType(ConditionNameEditPart.VISUAL_ID));
233: }
234:
235: /**
236: * @generated
237: */
238: public class ConditionFigure extends RectangleFigure {
239: /**
240: * @generated
241: */
242: public ConditionFigure() {
243: this .setFill(true);
244: this .setFillXOR(false);
245: this .setOutline(true);
246: this .setOutlineXOR(false);
247: this .setLineWidth(1);
248: this .setLineStyle(Graphics.LINE_SOLID);
249: this .setBackgroundColor(CONDITIONFIGURE_BACK);
250: this .setPreferredSize(new Dimension(getMapMode()
251: .DPtoLP(120), getMapMode().DPtoLP(20)));
252: createContents();
253: }
254:
255: /**
256: * @generated
257: */
258: private void createContents() {
259:
260: WrapLabel conditionNameFigure0 = new WrapLabel();
261: conditionNameFigure0.setText("<...>");
262:
263: this .add(conditionNameFigure0);
264: setFigureConditionNameFigure(conditionNameFigure0);
265:
266: }
267:
268: @Override
269: public void paintFigure(Graphics graphics) {
270: super .paintFigure(graphics);
271: graphics.setForegroundColor(new Color(null, 255, 255, 160));
272: graphics.setBackgroundColor(new Color(null, 255, 255, 72));
273: int x = getLocation().x;
274: int y = getLocation().y;
275: int width = getBounds().width;
276: int height = getBounds().height;
277: graphics.setLineWidth(1);
278: graphics.setLineStyle(Graphics.LINE_SOLID);
279: graphics.fillGradient(x, y, width, height, true);
280: }
281:
282: /**
283: * @generated
284: */
285: private WrapLabel fConditionNameFigure;
286:
287: /**
288: * @generated
289: */
290: public WrapLabel getFigureConditionNameFigure() {
291: return fConditionNameFigure;
292: }
293:
294: /**
295: * @generated
296: */
297: private void setFigureConditionNameFigure(WrapLabel fig) {
298: fConditionNameFigure = fig;
299: }
300:
301: /**
302: * @generated
303: */
304: private boolean myUseLocalCoordinates = false;
305:
306: /**
307: * @generated
308: */
309: protected boolean useLocalCoordinates() {
310: return myUseLocalCoordinates;
311: }
312:
313: /**
314: * @generated
315: */
316: protected void setUseLocalCoordinates(
317: boolean useLocalCoordinates) {
318: myUseLocalCoordinates = useLocalCoordinates;
319: }
320:
321: }
322:
323: /**
324: * @generated
325: */
326: static final Color CONDITIONFIGURE_BACK = new Color(null, 255, 255,
327: 102);
328:
329: }
|