001: package newprocess.diagram.edit.parts;
002:
003: import java.util.Iterator;
004: import java.util.List;
005:
006: import newprocess.diagram.cust.figures.TermDefaultSizeNodeFigure;
007: import newprocess.diagram.cust.locator.RootTermBorderItemLocator;
008: import newprocess.diagram.cust.locator.TermtBorderItemLocator;
009: import newprocess.diagram.cust.policies.NodeComponentEditPolicy;
010: import newprocess.diagram.edit.policies.Expression6CanonicalEditPolicy;
011: import newprocess.diagram.edit.policies.Expression6ItemSemanticEditPolicy;
012:
013: import org.eclipse.draw2d.Graphics;
014: import org.eclipse.draw2d.IFigure;
015: import org.eclipse.draw2d.PositionConstants;
016: import org.eclipse.draw2d.RectangleFigure;
017: import org.eclipse.draw2d.StackLayout;
018: import org.eclipse.draw2d.geometry.Dimension;
019: import org.eclipse.gef.EditPart;
020: import org.eclipse.gef.EditPolicy;
021: import org.eclipse.gef.Request;
022: import org.eclipse.gef.commands.Command;
023: import org.eclipse.gef.editpolicies.LayoutEditPolicy;
024: import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
025: import org.eclipse.gef.requests.CreateRequest;
026: import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
027: import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
028: import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
029: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy;
030: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
031: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
032: import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
033: import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
034: import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
035: import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
036: import org.eclipse.gmf.runtime.notation.View;
037: import org.eclipse.swt.graphics.Color;
038:
039: /**
040: * @generated
041: */
042: public class Expression6EditPart extends AbstractBorderedShapeEditPart {
043:
044: /**
045: * the BorderItemLocators which calculates the layout of BorderItems
046: */
047: private TermtBorderItemLocator termLoc = null;
048: private RootTermBorderItemLocator rootLoc = null;
049:
050: /**
051: * @generated NOT
052: * @author sh
053: * The Expression of the Event Postcondition
054: */
055: public static final int VISUAL_ID = 3010;
056:
057: /**
058: * @generated
059: */
060: protected IFigure contentPane;
061:
062: /**
063: * @generated
064: */
065: protected IFigure primaryShape;
066:
067: /**
068: * @generated
069: */
070: public Expression6EditPart(View view) {
071: super (view);
072: }
073:
074: /**
075: * @generated NOT
076: * @author sh
077: */
078: protected void createDefaultEditPolicies() {
079: installEditPolicy(EditPolicyRoles.CREATION_ROLE,
080: new CreationEditPolicy());
081: super .createDefaultEditPolicies();
082:
083: installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
084: new Expression6ItemSemanticEditPolicy());
085: installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
086: new DragDropEditPolicy());
087: installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
088: new Expression6CanonicalEditPolicy());
089: installEditPolicy(EditPolicy.LAYOUT_ROLE,
090: createLayoutEditPolicy());
091: // install this policy to disable deleting of the Expression Compartment
092: installEditPolicy(EditPolicy.COMPONENT_ROLE,
093: new NodeComponentEditPolicy());
094:
095: }
096:
097: /**
098: * @generated
099: */
100: protected LayoutEditPolicy createLayoutEditPolicy() {
101: LayoutEditPolicy lep = new LayoutEditPolicy() {
102:
103: protected EditPolicy createChildEditPolicy(EditPart child) {
104: if (child instanceof IBorderItemEditPart) {
105: return new BorderItemSelectionEditPolicy();
106: }
107: EditPolicy result = child
108: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
109: if (result == null) {
110: result = new NonResizableEditPolicy();
111: }
112: return result;
113: }
114:
115: protected Command getMoveChildrenCommand(Request request) {
116: return null;
117: }
118:
119: protected Command getCreateCommand(CreateRequest request) {
120: return null;
121: }
122: };
123: return lep;
124: }
125:
126: /**
127: * @generated
128: */
129: protected IFigure createNodeShape() {
130: ExpressionFigure figure = new ExpressionFigure();
131: return primaryShape = figure;
132: }
133:
134: /**
135: * @generated
136: */
137: public ExpressionFigure getPrimaryShape() {
138: return (ExpressionFigure) primaryShape;
139: }
140:
141: @Override
142: protected void addChildVisual(EditPart childEditPart, int index) {
143: if (addFixedChild(childEditPart)) {
144: return;
145: }
146: super .addChildVisual(childEditPart, -1);
147: }
148:
149: @Override
150: protected void removeChildVisual(EditPart child) {
151: if (removeFixedChild(child)) {
152: return;
153: }
154: super .removeChildVisual(child);
155: }
156:
157: /**
158: *
159: */
160: protected boolean removeFixedChild(EditPart childEditPart) {
161: if (childEditPart instanceof RootEditPart) {
162: getBorderedFigure().getBorderItemContainer().remove(
163: ((RootEditPart) childEditPart).getFigure());
164: return true;
165: }
166: if (childEditPart instanceof ConditionTermEditPart) {
167: getBorderedFigure().getBorderItemContainer()
168: .remove(
169: ((ConditionTermEditPart) childEditPart)
170: .getFigure());
171: return true;
172: }
173: return false;
174: }
175:
176: @Override
177: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
178: if (editPart instanceof RootEditPart) {
179: return getBorderedFigure().getBorderItemContainer();
180: }
181: if (editPart instanceof ConditionTermEditPart) {
182: return getBorderedFigure().getBorderItemContainer();
183: }
184: return getContentPane();
185: }
186:
187: /**
188: * @author sh
189: */
190: protected boolean addFixedChild(EditPart childEditPart) {
191: if (childEditPart instanceof RootEditPart) {
192: if (rootLoc == null) {
193: rootLoc = new RootTermBorderItemLocator(
194: getMainFigure(), PositionConstants.NORTH);
195: }
196: getBorderedFigure().getBorderItemContainer()
197: .add(((RootEditPart) childEditPart).getFigure(),
198: rootLoc);
199: return true;
200: }
201:
202: if (childEditPart instanceof ConditionTermEditPart) {
203: TermtBorderItemLocator locator = new TermtBorderItemLocator(
204: getMainFigure(), PositionConstants.SOUTH);
205: if (termLoc == null)
206: termLoc = locator;
207: getBorderedFigure().getBorderItemContainer()
208: .add(
209: ((ConditionTermEditPart) childEditPart)
210: .getFigure(), locator);
211: return true;
212: }
213: return false;
214: }
215:
216: /**
217: * @generated
218: */
219: protected NodeFigure createNodePlate() {
220: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
221: getMapMode().DPtoLP(160), getMapMode().DPtoLP(100));
222:
223: return result;
224: }
225:
226: /**
227: * Creates figure for this edit part.
228: *
229: * Body of this method does not depend on settings in generation model
230: * so you may safely remove <i>generated</i> tag and modify it.
231: *
232: * @generated
233: */
234: protected NodeFigure createMainFigure() {
235: NodeFigure figure = createNodePlate();
236: figure.setLayoutManager(new StackLayout());
237: IFigure shape = createNodeShape();
238: figure.add(shape);
239: contentPane = setupContentPane(shape);
240: return figure;
241: }
242:
243: /**
244: * Default implementation treats passed figure as content pane.
245: * Respects layout one may have set for generated figure.
246: * @param nodeShape instance of generated figure class
247: * @generated
248: */
249: protected IFigure setupContentPane(IFigure nodeShape) {
250: if (nodeShape.getLayoutManager() == null) {
251: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
252: layout.setSpacing(getMapMode().DPtoLP(5));
253: nodeShape.setLayoutManager(layout);
254: }
255: return nodeShape; // use nodeShape itself as contentPane
256: }
257:
258: /**
259: * Relocates the bordered items on the expression.
260: * If the links to proxies are crossed over the relocate
261: * moves the bordered items and resolves the crossings.
262: */
263: public void refreshBounds() {
264: super .refreshBounds();
265:
266: // get the item container where bordered items are added
267: IFigure itemContainer = this .getBorderedFigure()
268: .getBorderItemContainer();
269:
270: // iterate over all bordered items the expressio has and consider the root
271: List<IFigure> childs = itemContainer.getChildren();
272: for (Iterator<IFigure> iterator = childs.iterator(); iterator
273: .hasNext();) {
274: IFigure figure = iterator.next();
275: if (figure instanceof TermDefaultSizeNodeFigure) {
276: // relocate the default term
277: this .getTermBorderItemLocator().relocate(
278: (IFigure) figure);
279: continue;
280: }
281: if (figure instanceof DefaultSizeNodeFigure) {
282: // relocate the root
283: this .getRootTermBorderItemLocator().relocate(
284: (IFigure) figure);
285: }
286: }
287: }
288:
289: /**
290: * get the TermBorderItemLocator
291: */
292: public TermtBorderItemLocator getTermBorderItemLocator() {
293: return termLoc;
294: }
295:
296: /**
297: * get the RootTermBorderItemLocator
298: * @return
299: */
300: public RootTermBorderItemLocator getRootTermBorderItemLocator() {
301: return rootLoc;
302: }
303:
304: /**
305: * @generated
306: */
307: public IFigure getContentPane() {
308: if (contentPane != null) {
309: return contentPane;
310: }
311: return super .getContentPane();
312: }
313:
314: /**
315: * @generated
316: */
317: public class ExpressionFigure extends RectangleFigure {
318: /**
319: * @generated
320: */
321: public ExpressionFigure() {
322: this .setFill(true);
323: this .setFillXOR(false);
324: this .setOutline(true);
325: this .setOutlineXOR(false);
326: this .setLineWidth(1);
327: this .setLineStyle(Graphics.LINE_SOLID);
328: this .setBackgroundColor(EXPRESSIONFIGURE_BACK);
329: this .setPreferredSize(new Dimension(getMapMode()
330: .DPtoLP(160), getMapMode().DPtoLP(100)));
331: }
332:
333: /**
334: * @generated
335: */
336: private boolean myUseLocalCoordinates = false;
337:
338: /**
339: * @generated
340: */
341: protected boolean useLocalCoordinates() {
342: return myUseLocalCoordinates;
343: }
344:
345: /**
346: * @generated
347: */
348: protected void setUseLocalCoordinates(
349: boolean useLocalCoordinates) {
350: myUseLocalCoordinates = useLocalCoordinates;
351: }
352:
353: @Override
354: public void paintFigure(Graphics graphics) {
355: super .paintFigure(graphics);
356: graphics.setForegroundColor(new Color(null, 255, 172, 172));
357: graphics.setBackgroundColor(new Color(null, 216, 161, 161));
358: int x = getLocation().x;
359: int y = getLocation().y;
360: int width = getBounds().width;
361: int height = getBounds().height;
362: graphics.setLineWidth(1);
363: graphics.setLineStyle(Graphics.LINE_SOLID);
364: graphics.fillGradient(x, y, width, height, true);
365: }
366: }
367:
368: /**
369: * @generated NOT
370: * @author sh
371: */
372: static final Color EXPRESSIONFIGURE_BACK = new Color(null, 255, 99,
373: 60);
374:
375: }
|