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.Expression3CanonicalEditPolicy;
011: import newprocess.diagram.edit.policies.Expression3ItemSemanticEditPolicy;
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 Expression3EditPart 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 Listener Postcondition
054: */
055: public static final int VISUAL_ID = 3007;
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 Expression3EditPart(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 Expression3ItemSemanticEditPolicy());
085: installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE,
086: new DragDropEditPolicy());
087: installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,
088: new Expression3CanonicalEditPolicy());
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: * @generated
098: */
099: protected LayoutEditPolicy createLayoutEditPolicy() {
100: LayoutEditPolicy lep = new LayoutEditPolicy() {
101:
102: protected EditPolicy createChildEditPolicy(EditPart child) {
103: if (child instanceof IBorderItemEditPart) {
104: return new BorderItemSelectionEditPolicy();
105: }
106: EditPolicy result = child
107: .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
108: if (result == null) {
109: result = new NonResizableEditPolicy();
110: }
111: return result;
112: }
113:
114: protected Command getMoveChildrenCommand(Request request) {
115: return null;
116: }
117:
118: protected Command getCreateCommand(CreateRequest request) {
119: return null;
120: }
121: };
122: return lep;
123: }
124:
125: /**
126: * @generated
127: */
128: protected IFigure createNodeShape() {
129: ExpressionFigure figure = new ExpressionFigure();
130: return primaryShape = figure;
131: }
132:
133: /**
134: * @generated
135: */
136: public ExpressionFigure getPrimaryShape() {
137: return (ExpressionFigure) primaryShape;
138: }
139:
140: @Override
141: protected void addChildVisual(EditPart childEditPart, int index) {
142: if (addFixedChild(childEditPart)) {
143: return;
144: }
145: super .addChildVisual(childEditPart, -1);
146: }
147:
148: @Override
149: protected void removeChildVisual(EditPart child) {
150: if (removeFixedChild(child)) {
151: return;
152: }
153: super .removeChildVisual(child);
154: }
155:
156: /**
157: *
158: */
159: protected boolean removeFixedChild(EditPart childEditPart) {
160: if (childEditPart instanceof RootEditPart) {
161: getBorderedFigure().getBorderItemContainer().remove(
162: ((RootEditPart) childEditPart).getFigure());
163: return true;
164: }
165: if (childEditPart instanceof ConditionTermEditPart) {
166: getBorderedFigure().getBorderItemContainer()
167: .remove(
168: ((ConditionTermEditPart) childEditPart)
169: .getFigure());
170: return true;
171: }
172: return false;
173: }
174:
175: @Override
176: protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
177: if (editPart instanceof RootEditPart) {
178: return getBorderedFigure().getBorderItemContainer();
179: }
180: if (editPart instanceof ConditionTermEditPart) {
181: return getBorderedFigure().getBorderItemContainer();
182: }
183: return getContentPane();
184: }
185:
186: /**
187: * @author sh
188: */
189: protected boolean addFixedChild(EditPart childEditPart) {
190: if (childEditPart instanceof RootEditPart) {
191: if (rootLoc == null) {
192: rootLoc = new RootTermBorderItemLocator(
193: getMainFigure(), PositionConstants.SOUTH);
194: }
195: getBorderedFigure().getBorderItemContainer()
196: .add(((RootEditPart) childEditPart).getFigure(),
197: rootLoc);
198: return true;
199: }
200:
201: if (childEditPart instanceof ConditionTermEditPart) {
202: TermtBorderItemLocator locator = new TermtBorderItemLocator(
203: getMainFigure(), PositionConstants.NORTH);
204: if (termLoc == null)
205: termLoc = locator;
206: getBorderedFigure().getBorderItemContainer()
207: .add(
208: ((ConditionTermEditPart) childEditPart)
209: .getFigure(), locator);
210: return true;
211: }
212: return false;
213: }
214:
215: /**
216: * @generated
217: */
218: protected NodeFigure createNodePlate() {
219: DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(
220: getMapMode().DPtoLP(160), getMapMode().DPtoLP(100));
221:
222: return result;
223: }
224:
225: /**
226: * Creates figure for this edit part.
227: *
228: * Body of this method does not depend on settings in generation model
229: * so you may safely remove <i>generated</i> tag and modify it.
230: *
231: * @generated
232: */
233: protected NodeFigure createMainFigure() {
234: NodeFigure figure = createNodePlate();
235: figure.setLayoutManager(new StackLayout());
236: IFigure shape = createNodeShape();
237: figure.add(shape);
238: contentPane = setupContentPane(shape);
239: return figure;
240: }
241:
242: /**
243: * Default implementation treats passed figure as content pane.
244: * Respects layout one may have set for generated figure.
245: * @param nodeShape instance of generated figure class
246: * @generated
247: */
248: protected IFigure setupContentPane(IFigure nodeShape) {
249: if (nodeShape.getLayoutManager() == null) {
250: ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
251: layout.setSpacing(getMapMode().DPtoLP(5));
252: nodeShape.setLayoutManager(layout);
253: }
254: return nodeShape; // use nodeShape itself as contentPane
255: }
256:
257: /**
258: * Relocates the bordered items on the expression.
259: * If the links to proxies are crossed over the relocate
260: * moves the bordered items and resolves the crossings.
261: */
262: public void refreshBounds() {
263: super .refreshBounds();
264:
265: // get the item container where bordered items are added
266: IFigure itemContainer = this .getBorderedFigure()
267: .getBorderItemContainer();
268:
269: // iterate over all bordered items the expressio has and consider the root
270: List<IFigure> childs = itemContainer.getChildren();
271: for (Iterator<IFigure> iterator = childs.iterator(); iterator
272: .hasNext();) {
273: IFigure figure = iterator.next();
274: if (figure instanceof TermDefaultSizeNodeFigure) {
275: // relocate the default term
276: this .getTermBorderItemLocator().relocate(
277: (IFigure) figure);
278: continue;
279: }
280: if (figure instanceof DefaultSizeNodeFigure) {
281: // relocate the root
282: this .getRootTermBorderItemLocator().relocate(
283: (IFigure) figure);
284: }
285: }
286: }
287:
288: /**
289: * get the TermBorderItemLocator
290: */
291: public TermtBorderItemLocator getTermBorderItemLocator() {
292: return termLoc;
293: }
294:
295: /**
296: * get the RootTermBorderItemLocator
297: * @return
298: */
299: public RootTermBorderItemLocator getRootTermBorderItemLocator() {
300: return rootLoc;
301: }
302:
303: /**
304: * @generated
305: */
306: public IFigure getContentPane() {
307: if (contentPane != null) {
308: return contentPane;
309: }
310: return super .getContentPane();
311: }
312:
313: /**
314: * @generated
315: */
316: public class ExpressionFigure extends RectangleFigure {
317: /**
318: * @generated
319: */
320: public ExpressionFigure() {
321: this .setFill(true);
322: this .setFillXOR(false);
323: this .setOutline(true);
324: this .setOutlineXOR(false);
325: this .setLineWidth(1);
326: this .setLineStyle(Graphics.LINE_SOLID);
327: this .setBackgroundColor(EXPRESSIONFIGURE_BACK);
328: this .setPreferredSize(new Dimension(getMapMode()
329: .DPtoLP(160), getMapMode().DPtoLP(100)));
330: }
331:
332: /**
333: * @generated
334: */
335: private boolean myUseLocalCoordinates = false;
336:
337: /**
338: * @generated
339: */
340: protected boolean useLocalCoordinates() {
341: return myUseLocalCoordinates;
342: }
343:
344: /**
345: * @generated
346: */
347: protected void setUseLocalCoordinates(
348: boolean useLocalCoordinates) {
349: myUseLocalCoordinates = useLocalCoordinates;
350: }
351:
352: @Override
353: public void paintFigure(Graphics graphics) {
354: super .paintFigure(graphics);
355: graphics.setForegroundColor(new Color(null, 148, 255, 172));
356: graphics.setBackgroundColor(new Color(null, 186, 255, 172));
357: int x = getLocation().x;
358: int y = getLocation().y;
359: int width = getBounds().width;
360: int height = getBounds().height;
361: graphics.setLineWidth(1);
362: graphics.setLineStyle(Graphics.LINE_SOLID);
363: graphics.fillGradient(x, y, width, height, true);
364: }
365: }
366:
367: /**
368: * @generated NOT
369: * @author sh
370: */
371: static final Color EXPRESSIONFIGURE_BACK = new Color(null, 0, 255,
372: 0);
373:
374: }
|