001: package newprocess.diagram.edit.parts;
002:
003: import newprocess.ConditionProxy;
004: import newprocess.NewprocessPackage;
005: import newprocess.diagram.cust.listener.ProxyFigureListener;
006: import newprocess.diagram.cust.policies.HighlightEditPolicy;
007: import newprocess.diagram.edit.policies.ConditionProxyItemSemanticEditPolicy;
008: import newprocess.diagram.part.New_processVisualIDRegistry;
009:
010: import org.eclipse.draw2d.Graphics;
011: import org.eclipse.draw2d.IFigure;
012: import org.eclipse.draw2d.PositionConstants;
013: import org.eclipse.draw2d.RoundedRectangle;
014: import org.eclipse.draw2d.StackLayout;
015: import org.eclipse.draw2d.geometry.Dimension;
016: import org.eclipse.emf.common.notify.Notification;
017: import org.eclipse.gef.EditPart;
018: import org.eclipse.gef.EditPolicy;
019: import org.eclipse.gef.Request;
020: import org.eclipse.gef.commands.Command;
021: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
022: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
023: import org.eclipse.gef.editpolicies.ResizableEditPolicy;
024: import org.eclipse.gef.requests.CreateRequest;
025: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
026: import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
027: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
028: import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
029: import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel;
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.Node;
033: import org.eclipse.gmf.runtime.notation.View;
034: import org.eclipse.swt.graphics.Color;
035:
036: /**
037: * @generated
038: */
039: public class ConditionProxyEditPart extends ShapeNodeEditPart {
040:
041: /**
042: * @generated
043: */
044: public static final int VISUAL_ID = 2006;
045:
046: /**
047: * @generated
048: */
049: protected IFigure contentPane;
050:
051: /**
052: * @generated
053: */
054: protected IFigure primaryShape;
055:
056: /**
057: * @generated
058: */
059: public ConditionProxyEditPart(View view) {
060: super (view);
061: }
062:
063: /**
064: * @generated NOT
065: * @author sh
066: */
067: protected void createDefaultEditPolicies() {
068: super .createDefaultEditPolicies();
069:
070: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
071: new ConditionProxyItemSemanticEditPolicy());
072: installEditPolicy(EditPolicy.LAYOUT_ROLE,
073: createLayoutEditPolicy());
074: installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE,
075: new HighlightEditPolicy());
076: }
077:
078: /**
079: * @generated
080: */
081: protected LayoutEditPolicy createLayoutEditPolicy() {
082: LayoutEditPolicy lep = new LayoutEditPolicy() {
083:
084: protected EditPolicy createChildEditPolicy(EditPart child) {
085: EditPolicy result = child
086: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
087: if (result == null) {
088: result = new NonResizableEditPolicy();
089: }
090: return result;
091: }
092:
093: protected Command getMoveChildrenCommand(Request request) {
094: return null;
095: }
096:
097: protected Command getCreateCommand(CreateRequest request) {
098: return null;
099: }
100: };
101: return lep;
102: }
103:
104: /**
105: * @generated NOT
106: * @author sh
107: */
108: protected IFigure createNodeShape() {
109: ProxyFigure figure = new ProxyFigure();
110:
111: // tell the figure its host and register a FigureListner
112: figure.setHost(this );
113: figure.addFigureListener(ProxyFigureListener.INSTANCE);
114: primaryShape = figure;
115:
116: // change the border corresponding to the invalid flag
117: if (((ConditionProxy) ((Node) getModel()).getElement())
118: .isInverted())
119: this .getPrimaryShape().setLineWidth(2);
120: else
121: this .getPrimaryShape().setLineWidth(1);
122:
123: return primaryShape;
124: }
125:
126: /**
127: * @generated
128: */
129: public ProxyFigure getPrimaryShape() {
130: return (ProxyFigure) primaryShape;
131: }
132:
133: /**
134: * @generated
135: */
136: protected boolean addFixedChild(EditPart childEditPart) {
137: if (childEditPart instanceof ConditionProxyProxyNameEditPart) {
138: ((ConditionProxyProxyNameEditPart) childEditPart)
139: .setLabel(getPrimaryShape()
140: .getFigureProxyNameFigure());
141: return true;
142: }
143: return false;
144: }
145:
146: /**
147: * @generated
148: */
149: protected boolean removeFixedChild(EditPart childEditPart) {
150:
151: return false;
152: }
153:
154: /**
155: * @generated
156: */
157: protected void addChildVisual(EditPart childEditPart, int index) {
158: if (addFixedChild(childEditPart)) {
159: return;
160: }
161: super .addChildVisual(childEditPart, -1);
162: }
163:
164: /**
165: * @generated
166: */
167: protected void removeChildVisual(EditPart childEditPart) {
168: if (removeFixedChild(childEditPart)) {
169: return;
170: }
171: super .removeChildVisual(childEditPart);
172: }
173:
174: /**
175: * @generated
176: */
177: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
178:
179: return super .getContentPaneFor(editPart);
180: }
181:
182: /**
183: * reacts on changes of the inverted flag.
184: * If the inverted flag was set we set a fat border.
185: * @author sh
186: */
187: public void notifyChanged(Notification notification) {
188: super .notifyChanged(notification);
189:
190: // react to the inverted property
191: if (notification.getEventType() == Notification.SET
192: && notification.getFeatureID(NewprocessPackage.class) == NewprocessPackage.CONDITION_PROXY__INVERTED) {
193:
194: // return if we don't have a boolean value
195: if (notification.getNewValue() == null
196: || notification.getNewValue() instanceof Boolean == false)
197: return;
198:
199: // do our magic if the proxy has been edited
200: if (notification.getNotifier() instanceof ConditionProxy) {
201: if (notification.getNewBooleanValue() == true) {
202: this .getPrimaryShape().setLineWidth(2);
203: } else {
204: this .getPrimaryShape().setLineWidth(1);
205: }
206: }
207: }
208: }
209:
210: /**
211: * @generated
212: */
213: protected NodeFigure createNodePlate() {
214: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
215: getMapMode().DPtoLP(100), getMapMode().DPtoLP(20));
216:
217: return result;
218: }
219:
220: /**
221: * @generated
222: */
223: public EditPolicy getPrimaryDragEditPolicy() {
224: EditPolicy result = super .getPrimaryDragEditPolicy();
225: if (result instanceof ResizableEditPolicy) {
226: ResizableEditPolicy ep = (ResizableEditPolicy) result;
227: ep.setResizeDirections(PositionConstants.NONE);
228: }
229: return result;
230: }
231:
232: /**
233: * Creates figure for this edit part.
234: *
235: * Body of this method does not depend on settings in generation model
236: * so you may safely remove <i>generated</i> tag and modify it.
237: *
238: * @generated
239: */
240: protected NodeFigure createNodeFigure() {
241: NodeFigure figure = createNodePlate();
242: figure.setLayoutManager(new StackLayout());
243: IFigure shape = createNodeShape();
244: figure.add(shape);
245: contentPane = setupContentPane(shape);
246: return figure;
247: }
248:
249: /**
250: * Default implementation treats passed figure as content pane.
251: * Respects layout one may have set for generated figure.
252: * @param nodeShape instance of generated figure class
253: * @generated
254: */
255: protected IFigure setupContentPane(IFigure nodeShape) {
256: if (nodeShape.getLayoutManager() == null) {
257: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
258: layout.setSpacing(getMapMode().DPtoLP(5));
259: nodeShape.setLayoutManager(layout);
260: }
261: return nodeShape; // use nodeShape itself as contentPane
262: }
263:
264: /**
265: * @generated
266: */
267: public IFigure getContentPane() {
268: if (contentPane != null) {
269: return contentPane;
270: }
271: return super .getContentPane();
272: }
273:
274: /**
275: * @generated
276: */
277: public EditPart getPrimaryChildEditPart() {
278: return getChildBySemanticHint(New_processVisualIDRegistry
279: .getType(ConditionProxyProxyNameEditPart.VISUAL_ID));
280: }
281:
282: /**
283: * @generated NOT
284: * @author sh
285: */
286: public class ProxyFigure extends RoundedRectangle {
287: private ConditionProxyEditPart host;
288:
289: /**
290: * @generated
291: */
292: public ProxyFigure() {
293: this .setCornerDimensions(new Dimension(getMapMode().DPtoLP(
294: 20), getMapMode().DPtoLP(20)));
295: this .setFill(true);
296: this .setFillXOR(false);
297: this .setOutline(true);
298: this .setOutlineXOR(false);
299: this .setLineWidth(1);
300: this .setLineStyle(Graphics.LINE_SOLID);
301: this .setBackgroundColor(PROXYFIGURE_BACK);
302: this .setPreferredSize(new Dimension(getMapMode()
303: .DPtoLP(100), getMapMode().DPtoLP(20)));
304: createContents();
305: }
306:
307: /**
308: * @generated
309: */
310: private void createContents() {
311:
312: WrapLabel proxyNameFigure0 = new WrapLabel();
313: proxyNameFigure0.setText("<...>");
314:
315: this .add(proxyNameFigure0);
316: setFigureProxyNameFigure(proxyNameFigure0);
317:
318: }
319:
320: /**
321: * @generated
322: */
323: private WrapLabel fProxyNameFigure;
324:
325: /**
326: * @generated
327: */
328: public WrapLabel getFigureProxyNameFigure() {
329: return fProxyNameFigure;
330: }
331:
332: /**
333: * @generated
334: */
335: private void setFigureProxyNameFigure(WrapLabel fig) {
336: fProxyNameFigure = fig;
337: }
338:
339: /**
340: * @generated
341: */
342: private boolean myUseLocalCoordinates = false;
343:
344: /**
345: * @generated
346: */
347: protected boolean useLocalCoordinates() {
348: return myUseLocalCoordinates;
349: }
350:
351: /**
352: * @generated
353: */
354: protected void setUseLocalCoordinates(
355: boolean useLocalCoordinates) {
356: myUseLocalCoordinates = useLocalCoordinates;
357: }
358:
359: public ConditionProxyEditPart getHost() {
360: return host;
361: }
362:
363: public void setHost(ConditionProxyEditPart host) {
364: this .host = host;
365: }
366: }
367:
368: /**
369: * @generated
370: */
371: static final Color PROXYFIGURE_BACK = new Color(null, 255, 255, 102);
372:
373: }
|