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