0001: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts;
0002:
0003: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.ComponentFlowEditorDocument;
0004: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.MessageExchange;
0005: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.componentflowFactory;
0006: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.componentflowPackage;
0007:
0008: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.edit.parts.ExternalSystemEditPart.ESFigure;
0009: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
0010: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorPaletteFactory;
0011: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorVisualIDRegistry;
0012:
0013: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.view.factories.DomainElementInitializer;
0014: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.view.factories.MessageExchangeViewFactory;
0015:
0016: import java.util.HashMap;
0017: import java.util.Iterator;
0018: import java.util.List;
0019:
0020: import org.eclipse.draw2d.BorderLayout;
0021: import org.eclipse.draw2d.ChopboxAnchor;
0022: import org.eclipse.draw2d.ConnectionAnchor;
0023: import org.eclipse.draw2d.Figure;
0024: import org.eclipse.draw2d.IFigure;
0025: import org.eclipse.draw2d.ImageFigure;
0026: import org.eclipse.draw2d.PositionConstants;
0027: import org.eclipse.draw2d.StackLayout;
0028: import org.eclipse.draw2d.ToolbarLayout;
0029:
0030: import org.eclipse.draw2d.geometry.Point;
0031: import org.eclipse.draw2d.geometry.Rectangle;
0032:
0033: import org.eclipse.emf.common.command.AbstractCommand;
0034: import org.eclipse.emf.common.command.CompoundCommand;
0035:
0036: import org.eclipse.emf.common.notify.Notification;
0037:
0038: import org.eclipse.emf.common.notify.impl.AdapterImpl;
0039:
0040: import org.eclipse.emf.ecore.EAnnotation;
0041: import org.eclipse.emf.ecore.EClass;
0042: import org.eclipse.emf.ecore.EObject;
0043: import org.eclipse.emf.ecore.EStructuralFeature;
0044:
0045: import org.eclipse.emf.edit.command.AddCommand;
0046: import org.eclipse.emf.edit.command.RemoveCommand;
0047: import org.eclipse.emf.edit.command.SetCommand;
0048:
0049: import org.eclipse.emf.transaction.TransactionalEditingDomain;
0050:
0051: import org.eclipse.emf.transaction.util.TransactionUtil;
0052:
0053: import org.eclipse.gef.ConnectionEditPart;
0054: import org.eclipse.gef.EditPart;
0055: import org.eclipse.gef.EditPolicy;
0056: import org.eclipse.gef.GraphicalEditPart;
0057: import org.eclipse.gef.NodeEditPart;
0058: import org.eclipse.gef.Request;
0059: import org.eclipse.gef.RequestConstants;
0060:
0061: import org.eclipse.gef.commands.Command;
0062: import org.eclipse.gef.commands.UnexecutableCommand;
0063:
0064: import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
0065:
0066: import org.eclipse.gef.editpolicies.ComponentEditPolicy;
0067: import org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy;
0068: import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
0069: import org.eclipse.gef.editpolicies.ResizableEditPolicy;
0070:
0071: import org.eclipse.gef.requests.CreateConnectionRequest;
0072: import org.eclipse.gef.requests.CreateRequest;
0073: import org.eclipse.gef.requests.DirectEditRequest;
0074: import org.eclipse.gef.requests.GroupRequest;
0075: import org.eclipse.gef.requests.ReconnectRequest;
0076:
0077: import org.eclipse.gmf.runtime.notation.Bounds;
0078: import org.eclipse.gmf.runtime.notation.Edge;
0079: import org.eclipse.gmf.runtime.notation.FillStyle;
0080: import org.eclipse.gmf.runtime.notation.FontStyle;
0081: import org.eclipse.gmf.runtime.notation.LineStyle;
0082: import org.eclipse.gmf.runtime.notation.Node;
0083: import org.eclipse.gmf.runtime.notation.NotationFactory;
0084: import org.eclipse.gmf.runtime.notation.NotationPackage;
0085: import org.eclipse.gmf.runtime.notation.View;
0086:
0087: import org.eclipse.swt.SWT;
0088:
0089: import org.eclipse.swt.graphics.Color;
0090: import org.eclipse.swt.graphics.Font;
0091: import org.eclipse.swt.graphics.FontData;
0092:
0093: /**
0094: * @generated
0095: */
0096: public class ExternalSystemEditPart extends AbstractGraphicalEditPart
0097: implements NodeEditPart, IUpdatableEditPart {
0098:
0099: /**
0100: * @generated
0101: */
0102: public static final int VISUAL_ID = 2007;
0103:
0104: /**
0105: * @generated
0106: */
0107: protected IFigure contentPane;
0108:
0109: /**
0110: * @generated
0111: */
0112: protected IFigure primaryShape;
0113:
0114: /**
0115: * @generated
0116: */
0117: public ExternalSystemEditPart(View model) {
0118: assert model instanceof Node;
0119: setModel(model);
0120: }
0121:
0122: /**
0123: * @generated NOT
0124: */
0125: public void wizardOut(View view, boolean newCom) {
0126:
0127: }
0128:
0129: /**
0130: * @generated
0131: */
0132: protected void createEditPolicies() {
0133: installEditPolicy(EditPolicy.COMPONENT_ROLE,
0134: new ComponentEditPolicy() {
0135: protected Command createDeleteCommand(
0136: GroupRequest deleteRequest) {
0137: TransactionalEditingDomain editingDomain = TransactionUtil
0138: .getEditingDomain(getDiagramNode()
0139: .getDiagram().getElement());
0140: CompoundCommand cc = new CompoundCommand();
0141: cc
0142: .append(getDomainModelRemoveCommand(editingDomain));
0143: cc.append(RemoveCommand.create(editingDomain,
0144: getDiagramNode()));
0145: return new WrappingCommand(editingDomain, cc);
0146: }
0147:
0148: private org.eclipse.emf.common.command.Command getDomainModelRemoveCommand(
0149: TransactionalEditingDomain editingDomain) {
0150: return RemoveCommand
0151: .create(
0152: editingDomain,
0153: getDiagramNode().getElement()
0154: .eContainer(),
0155: componentflowPackage.eINSTANCE
0156: .getComponentFlowEditorDocument_DecorativeModelElements(),
0157: getDiagramNode().getElement());
0158: }
0159: });
0160: installEditPolicy(EditPolicy.LAYOUT_ROLE,
0161: new ConstrainedLayoutEditPolicy() {
0162: protected Command getCreateCommand(
0163: CreateRequest request) {
0164: return UnexecutableCommand.INSTANCE;
0165: }
0166:
0167: protected Object getConstraintFor(Rectangle rect) {
0168: return null;
0169: }
0170:
0171: protected Object getConstraintFor(Point point) {
0172: return null;
0173: }
0174:
0175: protected Command createChangeConstraintCommand(
0176: EditPart child, Object constraint) {
0177: return UnexecutableCommand.INSTANCE;
0178: }
0179:
0180: protected EditPolicy createChildEditPolicy(
0181: EditPart child) {
0182: return new ResizableEditPolicy() {
0183: public EditPart getTargetEditPart(
0184: Request request) {
0185: if (RequestConstants.REQ_SELECTION
0186: .equals(request.getType())) {
0187: return ExternalSystemEditPart.this ;
0188: }
0189: return super .getTargetEditPart(request);
0190: }
0191: };
0192: }
0193: });
0194: installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
0195: new GraphicalNodeEditPolicy() {
0196: protected Command getReconnectTargetCommand(
0197: ReconnectRequest request) {
0198: //XXX: reconnect command
0199: return UnexecutableCommand.INSTANCE;
0200: }
0201:
0202: protected Command getReconnectSourceCommand(
0203: ReconnectRequest request) {
0204: //XXX: reconnect command
0205: return UnexecutableCommand.INSTANCE;
0206: }
0207:
0208: protected Command getConnectionCreateCommand(
0209: CreateConnectionRequest request) {
0210: if (request instanceof ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx) {
0211: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx = (ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx) request;
0212: int[] visualIds = requestEx.getVisualIds();
0213: CompoundCommand result = new CompoundCommand();
0214: for (int i = 0; i < visualIds.length; i++) {
0215: int nextVisualId = visualIds[i];
0216: switch (nextVisualId) {
0217: case MessageExchangeEditPart.VISUAL_ID:
0218: result
0219: .append(new CreateMessageExchange4001StartCommand(
0220: requestEx));
0221: break;
0222: }
0223: }
0224: if (result.getCommandList().size() != 1
0225: || !result.canExecute()) {
0226: //Cannot create several connections at once.
0227: //returning an unexecutable command does not change cursor to "No".
0228: return null;
0229: }
0230: Command wrappedResult = new WrappingCommand(
0231: TransactionUtil
0232: .getEditingDomain(getDiagramNode()
0233: .getDiagram()
0234: .getElement()),
0235: result);
0236: request.setStartCommand(wrappedResult);
0237: return wrappedResult;
0238: }
0239: return null;
0240: }
0241:
0242: protected Command getConnectionCompleteCommand(
0243: CreateConnectionRequest request) {
0244: if (request.getStartCommand() == null
0245: || !request.getStartCommand()
0246: .canExecute()) {
0247: return UnexecutableCommand.INSTANCE;
0248: }
0249: if (request instanceof ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx) {
0250: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx = (ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx) request;
0251: int[] visualIds = requestEx.getVisualIds();
0252: CompoundCommand result = new CompoundCommand();
0253: for (int i = 0; i < visualIds.length; i++) {
0254: int nextVisualId = visualIds[i];
0255: switch (nextVisualId) {
0256: case MessageExchangeEditPart.VISUAL_ID:
0257: result
0258: .append(new CreateMessageExchange4001Command(
0259: requestEx));
0260: break;
0261: }
0262: }
0263: if (result.getCommandList().size() != 1) {
0264: //Cannot create several connections at once.
0265: return UnexecutableCommand.INSTANCE;
0266: }
0267: return new WrappingCommand(
0268: TransactionUtil
0269: .getEditingDomain(getDiagramNode()
0270: .getDiagram()
0271: .getElement()),
0272: result);
0273: }
0274: return UnexecutableCommand.INSTANCE;
0275: }
0276: });
0277: }
0278:
0279: /**
0280: * @generated NOT
0281: */
0282: protected IFigure createFigure() {
0283: IFigure invisibleRectangle = new Figure();
0284: invisibleRectangle.setLayoutManager(new BorderLayout());
0285: IFigure rec = new Figure();
0286: invisibleRectangle.add(rec, BorderLayout.CENTER);
0287: rec.setLayoutManager(new StackLayout());
0288: IFigure shape = createNodeShape();
0289: rec.add(shape);
0290: contentPane = setupContentPane(shape);
0291:
0292: IFigure decorationShape = createDecorationPane();
0293: if (decorationShape != null) {
0294: rec.add(decorationShape);
0295: }
0296:
0297: org.eclipse.draw2d.Label fig = new org.eclipse.draw2d.Label();
0298: fig.setText("");
0299:
0300: ((ESFigure) shape).setFigureESNameFigure(fig);
0301:
0302: invisibleRectangle.add(fig, BorderLayout.BOTTOM);
0303: return invisibleRectangle;
0304: }
0305:
0306: /**
0307: * @generated
0308: */
0309: protected IFigure createNodeShape() {
0310: ESFigure figure = new ESFigure();
0311: primaryShape = figure;
0312: return primaryShape;
0313: }
0314:
0315: /**
0316: * @generated
0317: */
0318: public ESFigure getPrimaryShape() {
0319: return (ESFigure) primaryShape;
0320: }
0321:
0322: /**
0323: * @generated NOT
0324: */
0325: private IFigure createDecorationPane() {
0326: View view = (View) getModel();
0327: Figure decorationPane = new Figure();
0328: decorationPane.setLayoutManager(new BorderLayout());
0329:
0330: ImageFigure imageFigure = new ImageFigure(
0331: ComponentFlowEditorDiagramEditorPlugin.getInstance()
0332: .getBundledImage("icons/External32.ico"),
0333: PositionConstants.CENTER);
0334: decorationPane.add(imageFigure, BorderLayout.TOP);
0335: return decorationPane;
0336: }
0337:
0338: /**
0339: * Default implementation treats passed figure as content pane.
0340: * Respects layout one may have set for generated figure.
0341: * @param nodeShape instance of generated figure class
0342: * @generated
0343: */
0344: protected IFigure setupContentPane(IFigure nodeShape) {
0345: if (nodeShape.getLayoutManager() == null) {
0346: ToolbarLayout layout = new ToolbarLayout();
0347: layout.setSpacing(5);
0348: nodeShape.setLayoutManager(layout);
0349: }
0350: return nodeShape; // use nodeShape itself as contentPane
0351: }
0352:
0353: /**
0354: * @generated
0355: */
0356: public IFigure getContentPane() {
0357: if (contentPane == null) {
0358: return super .getContentPane();
0359: }
0360: return contentPane;
0361: }
0362:
0363: /**
0364: * @generated
0365: */
0366: public Node getDiagramNode() {
0367: return (Node) getModel();
0368: }
0369:
0370: /**
0371: * @generated
0372: */
0373: protected boolean addFixedChild(EditPart childEditPart) {
0374: if (childEditPart instanceof ExternalSystemNameEditPart) {
0375: ((ExternalSystemNameEditPart) childEditPart)
0376: .setLabel(getPrimaryShape().getFigureESNameFigure());
0377: return true;
0378: }
0379: return false;
0380: }
0381:
0382: /**
0383: * @generated
0384: */
0385: protected boolean removeFixedChild(EditPart childEditPart) {
0386: return false;
0387: }
0388:
0389: /**
0390: * Returns the label which should be direct-edited by default.
0391: * @generated
0392: */
0393: private EditPart getPrimaryLabelEditPart() {
0394: for (Iterator it = getDiagramNode().getChildren().iterator(); it
0395: .hasNext();) {
0396: View nextChild = (View) it.next();
0397: if (ComponentFlowEditorVisualIDRegistry
0398: .getVisualID(nextChild) == ExternalSystemNameEditPart.VISUAL_ID) {
0399: return (EditPart) getViewer().getEditPartRegistry()
0400: .get(nextChild);
0401: }
0402: }
0403: return null;
0404: }
0405:
0406: /**
0407: * @generated
0408: */
0409: public void performRequest(Request req) {
0410: if (RequestConstants.REQ_DIRECT_EDIT == req.getType()) {
0411: EditPart labelToEdit;
0412: if (req instanceof DirectEditRequest) {
0413: labelToEdit = getLabelEditPart((DirectEditRequest) req);
0414: } else {
0415: labelToEdit = getPrimaryLabelEditPart();
0416: }
0417: if (labelToEdit != null) {
0418: labelToEdit.performRequest(req);
0419: }
0420: }
0421: }
0422:
0423: /**
0424: * @generated
0425: */
0426: private EditPart getLabelEditPart(DirectEditRequest req) {
0427: EditPart result = getViewer().findObjectAt(req.getLocation());
0428: if (result != null) {
0429: View view = (View) result.getModel();
0430: if (getDiagramNode().getChildren().contains(view)) {
0431: int visualId = ComponentFlowEditorVisualIDRegistry
0432: .getVisualID(view);
0433: switch (visualId) {
0434: case ExternalSystemNameEditPart.VISUAL_ID:
0435: return result;
0436: }
0437: }
0438: }
0439: return getPrimaryLabelEditPart();
0440: }
0441:
0442: /**
0443: * @generated
0444: */
0445: protected void addChildVisual(EditPart childEditPart, int index) {
0446: if (addFixedChild(childEditPart)) {
0447: return;
0448: }
0449: super .addChildVisual(childEditPart, -1);
0450: }
0451:
0452: /**
0453: * @generated
0454: */
0455: protected void removeChildVisual(EditPart childEditPart) {
0456: if (removeFixedChild(childEditPart)) {
0457: return;
0458: }
0459: super .removeChildVisual(childEditPart);
0460: }
0461:
0462: /**
0463: * @generated
0464: */
0465: protected void refreshVisuals() {
0466: super .refreshVisuals();
0467: refreshBounds();
0468: refreshBackgroundColor();
0469: refreshForegroundColor();
0470: refreshFont();
0471: refreshVisibility();
0472: }
0473:
0474: /**
0475: * @generated
0476: */
0477: protected void refreshVisibility() {
0478: boolean isVisible = getDiagramNode().isVisible();
0479: boolean wasVisible = getFigure().isVisible();
0480: if (isVisible == wasVisible) {
0481: return;
0482: }
0483: if (!isVisible && (getSelected() != SELECTED_NONE)) {
0484: getViewer().deselect(this );
0485: }
0486:
0487: getFigure().setVisible(isVisible);
0488: getFigure().revalidate();
0489: }
0490:
0491: /**
0492: * @generated
0493: */
0494: protected void refreshBounds() {
0495: Node node = getDiagramNode();
0496: assert node.getLayoutConstraint() instanceof Bounds;
0497: Bounds bounds = (Bounds) node.getLayoutConstraint();
0498: ((GraphicalEditPart) getParent()).setLayoutConstraint(this ,
0499: getFigure(), new Rectangle(bounds.getX(),
0500: bounds.getY(), bounds.getWidth(), bounds
0501: .getHeight()));
0502: }
0503:
0504: /**
0505: * @generated
0506: */
0507: protected List getModelChildren() {
0508: return getDiagramNode().getVisibleChildren();
0509: }
0510:
0511: /**
0512: * @generated
0513: */
0514: protected List getModelSourceConnections() {
0515: return getDiagramNode().getSourceEdges();
0516: }
0517:
0518: /**
0519: * @generated
0520: */
0521: protected List getModelTargetConnections() {
0522: return getDiagramNode().getTargetEdges();
0523: }
0524:
0525: /**
0526: * @generated
0527: */
0528: public ConnectionAnchor getSourceConnectionAnchor(
0529: ConnectionEditPart connection) {
0530: return new ChopboxAnchor(getFigure());
0531: }
0532:
0533: /**
0534: * @generated
0535: */
0536: public ConnectionAnchor getSourceConnectionAnchor(Request request) {
0537: return new ChopboxAnchor(getFigure());
0538: }
0539:
0540: /**
0541: * @generated
0542: */
0543: public ConnectionAnchor getTargetConnectionAnchor(
0544: ConnectionEditPart connection) {
0545: return new ChopboxAnchor(getFigure());
0546: }
0547:
0548: /**
0549: * @generated
0550: */
0551: public ConnectionAnchor getTargetConnectionAnchor(Request request) {
0552: return new ChopboxAnchor(getFigure());
0553: }
0554:
0555: /**
0556: * @generated
0557: */
0558: public Object getAdapter(Class key) {
0559: return super .getAdapter(key);
0560: }
0561:
0562: /**
0563: * @generated
0564: */
0565: public void activate() {
0566: super .activate();
0567: getDiagramNode().getElement().eAdapters().add(
0568: domainModelRefresher);
0569: }
0570:
0571: /**
0572: * @generated
0573: */
0574: public void deactivate() {
0575: getDiagramNode().getElement().eAdapters().remove(
0576: domainModelRefresher);
0577: super .deactivate();
0578: }
0579:
0580: /**
0581: * @generated
0582: */
0583: private DomainModelRefresher domainModelRefresher = new DomainModelRefresher();
0584:
0585: /**
0586: * @generated
0587: */
0588: private class DomainModelRefresher extends AdapterImpl {
0589: /**
0590: * @generated
0591: */
0592: public void notifyChanged(Notification msg) {
0593: super .notifyChanged(msg);
0594: if (msg.isTouch()) {
0595: return;
0596: }
0597: Refresher refresher = getRefresher((EStructuralFeature) msg
0598: .getFeature(), msg);
0599: if (refresher != null) {
0600: refresher.refresh();
0601: }
0602: }
0603: }
0604:
0605: /**
0606: * @generated
0607: */
0608: public void addRefresher(EStructuralFeature feature,
0609: Refresher refresher) {
0610: CompositeRefresher compositeRefresher = getCompositeRefresher(feature);
0611: compositeRefresher.addRefresher(refresher);
0612: }
0613:
0614: /**
0615: * @generated
0616: */
0617: public void removeRefresher(EStructuralFeature feature,
0618: Refresher refresher) {
0619: CompositeRefresher compositeRefresher = getCompositeRefresher(feature);
0620: compositeRefresher.removeRefresher(refresher);
0621: }
0622:
0623: /**
0624: * @generated
0625: */
0626: private CompositeRefresher getCompositeRefresher(
0627: EStructuralFeature feature) {
0628: if (structuralFeatures2Refresher == null) {
0629: createRefreshers();
0630: }
0631: Refresher refresher = (Refresher) structuralFeatures2Refresher
0632: .get(feature);
0633: if (refresher instanceof CompositeRefresher) {
0634: return (CompositeRefresher) refresher;
0635: }
0636: CompositeRefresher result = new CompositeRefresher();
0637: if (refresher != null) {
0638: result.addRefresher(refresher);
0639: }
0640: structuralFeatures2Refresher.put(feature, result);
0641: return result;
0642: }
0643:
0644: /**
0645: * @generated
0646: */
0647: protected void refreshFont() {
0648: FontStyle style = (FontStyle) getDiagramNode().getStyle(
0649: NotationPackage.eINSTANCE.getFontStyle());
0650: Font toDispose = createdFont;
0651: if (style != null) {
0652: String fontName = style.getFontName();
0653: int fontHeight = style.getFontHeight();
0654: int fontStyle = SWT.NORMAL;
0655: if (style.isBold()) {
0656: fontStyle |= SWT.BOLD;
0657: }
0658: if (style.isItalic()) {
0659: fontStyle |= SWT.ITALIC;
0660: }
0661: Font currentFont = getFigure().getFont();
0662: if (currentFont != null) {
0663: FontData currentFontData = currentFont.getFontData()[0];
0664: if (currentFontData.getName().equals(fontName)
0665: && currentFontData.getHeight() == fontHeight
0666: && currentFontData.getStyle() == fontStyle) {
0667: return;
0668: }
0669: }
0670: createdFont = new Font(null, fontName, fontHeight,
0671: fontStyle);
0672: getFigure().setFont(createdFont);
0673: } else {
0674: //revert to the default font
0675: getFigure().setFont(getViewer().getControl().getFont());
0676: createdFont = null;
0677: }
0678: if (toDispose != null) {
0679: toDispose.dispose();
0680: }
0681: }
0682:
0683: /**
0684: * The font (created by {@link #refreshFont()}) currently assigned to the label (unless the default font is assigned).
0685: * Whenever another non-default font is assigned to it, it is safe to dispose the previous one.
0686: * @generated
0687: */
0688: private Font createdFont;
0689:
0690: /**
0691: * @generated
0692: */
0693: protected void refreshForegroundColor() {
0694: LineStyle style = (LineStyle) getDiagramNode().getStyle(
0695: NotationPackage.eINSTANCE.getLineStyle());
0696: Color toDispose = createdForegroundColor;
0697: if (style != null) {
0698: int foregroundColor = style.getLineColor();
0699: int red = foregroundColor & 0x000000FF;
0700: int green = (foregroundColor & 0x0000FF00) >> 8;
0701: int blue = (foregroundColor & 0x00FF0000) >> 16;
0702: Color currentColor = getFigure().getForegroundColor();
0703: if (currentColor != null && currentColor.getRed() == red
0704: && currentColor.getGreen() == green
0705: && currentColor.getBlue() == blue) {
0706: return;
0707: }
0708: createdForegroundColor = new Color(null, red, green, blue);
0709: getFigure().setForegroundColor(createdForegroundColor);
0710: } else {
0711: getFigure().setForegroundColor(
0712: getViewer().getControl().getForeground());
0713: createdForegroundColor = null;
0714: }
0715: if (toDispose != null) {
0716: toDispose.dispose();
0717: }
0718: }
0719:
0720: /**
0721: * The color (created by {@link #refreshForegroundColor()}) currently assigned to the figure.
0722: * Whenever another color is assigned to it, it is safe to dispose the previous one.
0723: * @generated
0724: */
0725: private Color createdForegroundColor;
0726:
0727: /**
0728: * @generated
0729: */
0730: protected void refreshBackgroundColor() {
0731: FillStyle style = (FillStyle) getDiagramNode().getStyle(
0732: NotationPackage.eINSTANCE.getFillStyle());
0733: Color toDispose = createdBackgroundColor;
0734: if (style != null) {
0735: int backgroundColor = style.getFillColor();
0736: int red = backgroundColor & 0x000000FF;
0737: int green = (backgroundColor & 0x0000FF00) >> 8;
0738: int blue = (backgroundColor & 0x00FF0000) >> 16;
0739: Color currentColor = getFigure().getBackgroundColor();
0740: if (currentColor != null && currentColor.getRed() == red
0741: && currentColor.getGreen() == green
0742: && currentColor.getBlue() == blue) {
0743: return;
0744: }
0745: createdBackgroundColor = new Color(null, red, green, blue);
0746: getFigure().setBackgroundColor(createdBackgroundColor);
0747: } else {
0748: getFigure().setBackgroundColor(
0749: getViewer().getControl().getBackground());
0750: }
0751: if (toDispose != null) {
0752: toDispose.dispose();
0753: }
0754: }
0755:
0756: /**
0757: * The color (created by {@link #refreshBackgroundColor()}) currently assigned to the figure.
0758: * Whenever another color is assigned to it, it is safe to dispose the previous one.
0759: * @generated
0760: */
0761: private Color createdBackgroundColor;
0762:
0763: /**
0764: * @generated
0765: */
0766: private HashMap structuralFeatures2Refresher;
0767:
0768: /**
0769: * @generated
0770: */
0771: public Refresher getRefresher(EStructuralFeature feature,
0772: Notification msg) {
0773: if (structuralFeatures2Refresher == null) {
0774: createRefreshers();
0775: }
0776: return (Refresher) structuralFeatures2Refresher.get(feature);
0777: }
0778:
0779: /**
0780: * @generated
0781: */
0782: private void createRefreshers() {
0783: structuralFeatures2Refresher = new HashMap();
0784: Refresher childrenRefresher = new Refresher() {
0785: public void refresh() {
0786: refreshChildren();
0787: }
0788: };
0789: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0790: .getView_PersistedChildren(), childrenRefresher);
0791: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0792: .getView_TransientChildren(), childrenRefresher);
0793: Refresher boundsRefresher = new Refresher() {
0794: public void refresh() {
0795: refreshBounds();
0796: }
0797: };
0798: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0799: .getNode_LayoutConstraint(), boundsRefresher);
0800: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0801: .getSize_Width(), boundsRefresher);
0802: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0803: .getSize_Height(), boundsRefresher);
0804: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0805: .getLocation_X(), boundsRefresher);
0806: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0807: .getLocation_Y(), boundsRefresher);
0808: Refresher visibilityRefresher = new Refresher() {
0809: public void refresh() {
0810: refreshVisibility();
0811: }
0812: };
0813: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0814: .getView_Visible(), visibilityRefresher);
0815: Refresher sourceEdgesRefresher = new Refresher() {
0816: public void refresh() {
0817: refreshSourceConnections();
0818: }
0819: };
0820: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0821: .getView_SourceEdges(), sourceEdgesRefresher);
0822: Refresher targetEdgesRefresher = new Refresher() {
0823: public void refresh() {
0824: refreshTargetConnections();
0825: }
0826: };
0827: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0828: .getView_TargetEdges(), targetEdgesRefresher);
0829: Refresher fontRefresher = new Refresher() {
0830: public void refresh() {
0831: refreshFont();
0832: }
0833: };
0834: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0835: .getFontStyle_FontHeight(), fontRefresher);
0836: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0837: .getFontStyle_FontName(), fontRefresher);
0838: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0839: .getFontStyle_Bold(), fontRefresher);
0840: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0841: .getFontStyle_Italic(), fontRefresher);
0842:
0843: Refresher backgroundColorRefresher = new Refresher() {
0844: public void refresh() {
0845: refreshBackgroundColor();
0846: }
0847: };
0848: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0849: .getFillStyle_FillColor(), backgroundColorRefresher);
0850: Refresher foregroundColorRefresher = new Refresher() {
0851: public void refresh() {
0852: refreshForegroundColor();
0853: }
0854: };
0855: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0856: .getLineStyle_LineColor(), foregroundColorRefresher);
0857: }
0858:
0859: /**
0860: * @generated
0861: */
0862: private static class CreateMessageExchange4001StartCommand extends
0863: AbstractCommand {
0864: /**
0865: * @generated
0866: */
0867: private View source;
0868:
0869: /**
0870: * @generated
0871: */
0872: public CreateMessageExchange4001StartCommand(
0873: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx) {
0874: //Until the mouse button is pressed, the source of the connection is in request.getTargetEditPart(), not in request.getSourceEditPart().
0875: source = (View) requestEx.getTargetEditPart().getModel();
0876: }
0877:
0878: /**
0879: * @generated
0880: */
0881: public void execute() {
0882: //This command never gets executed
0883: }
0884:
0885: /**
0886: * @generated
0887: */
0888: public void undo() {
0889: //This command never gets executed
0890: }
0891:
0892: /**
0893: * @generated
0894: */
0895: public void redo() {
0896: //This command never gets executed
0897: }
0898:
0899: /**
0900: * @generated
0901: */
0902: public boolean canUndo() {
0903: return true;
0904: }
0905:
0906: /**
0907: * @generated
0908: */
0909: protected boolean prepare() {
0910: if (source == null) {
0911: return false;
0912: }
0913: ComponentFlowEditorDocument container = (ComponentFlowEditorDocument) getRelationshipContainer(
0914: source.getElement(), componentflowPackage.eINSTANCE
0915: .getComponentFlowEditorDocument());
0916: if (container == null) {
0917: return false;
0918: }
0919:
0920: return true;
0921: }
0922:
0923: /**
0924: * Finds container element for the new relationship of the specified type.
0925: * Default implementation goes up by containment hierarchy starting from
0926: * the specified element and returns the first element that is instance of
0927: * the specified container class.
0928: *
0929: * @generated
0930: */
0931: protected EObject getRelationshipContainer(EObject element,
0932: EClass containerClass) {
0933: for (; element != null; element = element.eContainer()) {
0934: if (containerClass.isSuperTypeOf(element.eClass())) {
0935: return element;
0936: }
0937: }
0938: return null;
0939: }
0940:
0941: }
0942:
0943: /**
0944: * @generated
0945: */
0946: private static class CreateMessageExchange4001Command extends
0947: AbstractCommand {
0948: /**
0949: * @generated
0950: */
0951: private final View source;
0952:
0953: /**
0954: * @generated
0955: */
0956: private final View target;
0957:
0958: /**
0959: * @generated
0960: */
0961: private final Edge createdEdge;
0962:
0963: /**
0964: * @generated
0965: */
0966: private final org.eclipse.emf.common.command.Command domainModelAddCommand;
0967:
0968: /**
0969: * @generated
0970: */
0971: public CreateMessageExchange4001Command(
0972: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx) {
0973: if (requestEx.getSourceEditPart().getModel() instanceof View) {
0974: source = (View) requestEx.getSourceEditPart()
0975: .getModel();
0976: } else {
0977: source = null;
0978: }
0979: if (requestEx.getTargetEditPart().getModel() instanceof View) {
0980: target = (View) requestEx.getTargetEditPart()
0981: .getModel();
0982: } else {
0983: target = null;
0984: }
0985: if (source == null || target == null) {
0986: createdEdge = null;
0987: domainModelAddCommand = org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
0988: return;
0989: }
0990: createdEdge = NotationFactory.eINSTANCE.createEdge();
0991: MessageExchange createdDomainElement = componentflowFactory.eINSTANCE
0992: .createMessageExchange();
0993: createdEdge.setElement(createdDomainElement);
0994:
0995: DomainElementInitializer.MessageExchange_4001
0996: .initializeElement(createdDomainElement);
0997: MessageExchangeViewFactory.decorateView(createdEdge);
0998: TransactionalEditingDomain domainModelEditDomain = TransactionUtil
0999: .getEditingDomain(source.getDiagram().getElement());
1000: org.eclipse.emf.common.command.CompoundCommand addLinkEndsCommand = new org.eclipse.emf.common.command.CompoundCommand();
1001: EObject container = getRelationshipContainer(source
1002: .getElement(), componentflowPackage.eINSTANCE
1003: .getComponentFlowEditorDocument());
1004: if (container == null) {
1005: domainModelAddCommand = null;
1006: return;
1007: }
1008: addLinkEndsCommand
1009: .append(AddCommand
1010: .create(
1011: domainModelEditDomain,
1012: container,
1013: componentflowPackage.eINSTANCE
1014: .getComponentFlowEditorDocument_MessageExchanges(),
1015: createdDomainElement));
1016:
1017: if (createdDomainElement.getSourceElement() != null) {
1018: domainModelAddCommand = null;
1019: return;
1020: }
1021: addLinkEndsCommand.append(SetCommand.create(
1022: domainModelEditDomain, createdDomainElement,
1023: componentflowPackage.eINSTANCE
1024: .getMessageExchange_SourceElement(), source
1025: .getElement()));
1026:
1027: if (createdDomainElement.getTargetElement() != null) {
1028: domainModelAddCommand = null;
1029: return;
1030: }
1031: addLinkEndsCommand.append(SetCommand.create(
1032: domainModelEditDomain, createdDomainElement,
1033: componentflowPackage.eINSTANCE
1034: .getMessageExchange_TargetElement(), target
1035: .getElement()));
1036: domainModelAddCommand = addLinkEndsCommand;
1037: }
1038:
1039: /**
1040: * Finds container element for the new relationship of the specified type.
1041: * Default implementation goes up by containment hierarchy starting from
1042: * the specified element and returns the first element that is instance of
1043: * the specified container class.
1044: *
1045: * @generated
1046: */
1047: protected EObject getRelationshipContainer(EObject element,
1048: EClass containerClass) {
1049: for (; element != null; element = element.eContainer()) {
1050: if (containerClass.isSuperTypeOf(element.eClass())) {
1051: return element;
1052: }
1053: }
1054: return null;
1055: }
1056:
1057: /**
1058: * @generated
1059: */
1060: public boolean canExecute() {
1061: if (source == null || target == null || createdEdge == null
1062: || domainModelAddCommand == null
1063: || !domainModelAddCommand.canExecute()) {
1064: return false;
1065: }
1066:
1067: return true;
1068: }
1069:
1070: /**
1071: * @generated
1072: */
1073: public boolean canUndo() {
1074: return source != null && target != null
1075: && createdEdge != null
1076: && domainModelAddCommand != null
1077: && domainModelAddCommand.canUndo();
1078: }
1079:
1080: /**
1081: * @generated
1082: */
1083: public void execute() {
1084: domainModelAddCommand.execute();
1085: source.getDiagram().insertEdge(createdEdge);
1086: createdEdge.setSource(source);
1087: createdEdge.setTarget(target);
1088: }
1089:
1090: /**
1091: * @generated
1092: */
1093: public void undo() {
1094: domainModelAddCommand.undo();
1095: source.getDiagram().removeEdge(createdEdge);
1096: createdEdge.setSource(null);
1097: createdEdge.setTarget(null);
1098: }
1099:
1100: /**
1101: * @generated
1102: */
1103: public void redo() {
1104: execute();
1105: }
1106: }
1107:
1108: /**
1109: * @generated
1110: */
1111: public class ESFigure extends org.eclipse.draw2d.RectangleFigure {
1112:
1113: /**
1114: * @generated
1115: */
1116: public ESFigure() {
1117:
1118: this
1119: .setBackgroundColor(org.eclipse.draw2d.ColorConstants.lightBlue
1120:
1121: );
1122: this .setPreferredSize(getMapMode().DPtoLP(80), getMapMode()
1123: .DPtoLP(50));
1124: createContents();
1125: }
1126:
1127: /**
1128: * @generated NOT
1129: */
1130: private void createContents() {/*
1131: org.eclipse.draw2d.Label fig_0 = new org.eclipse.draw2d.Label();
1132: fig_0.setText("<...>");
1133:
1134: setFigureESNameFigure(fig_0);
1135:
1136: Object layData0 = null;
1137:
1138: this.add(fig_0, layData0);
1139: */
1140: }
1141:
1142: /**
1143: * @generated
1144: */
1145: private org.eclipse.draw2d.Label fESNameFigure;
1146:
1147: /**
1148: * @generated
1149: */
1150: public org.eclipse.draw2d.Label getFigureESNameFigure() {
1151: return fESNameFigure;
1152: }
1153:
1154: /**
1155: * @generated
1156: */
1157: private void setFigureESNameFigure(org.eclipse.draw2d.Label fig) {
1158: fESNameFigure = fig;
1159: }
1160:
1161: /**
1162: * @generated
1163: */
1164: private boolean myUseLocalCoordinates = false;
1165:
1166: /**
1167: * @generated
1168: */
1169: protected boolean useLocalCoordinates() {
1170: return myUseLocalCoordinates;
1171: }
1172:
1173: /**
1174: * @generated
1175: */
1176: protected void setUseLocalCoordinates(
1177: boolean useLocalCoordinates) {
1178: myUseLocalCoordinates = useLocalCoordinates;
1179: }
1180:
1181: }
1182:
1183: /**
1184: * @generated
1185: */
1186: private static class MapModeWorkaround {
1187: /**
1188: * @generated
1189: */
1190: public int DPtoLP(int dp) {
1191: return dp;
1192: }
1193:
1194: /**
1195: * @generated
1196: */
1197: public static MapModeWorkaround INSTANCE = new MapModeWorkaround();
1198: }
1199:
1200: /**
1201: * @generated
1202: */
1203: private MapModeWorkaround getMapMode() {
1204: return MapModeWorkaround.INSTANCE;
1205: }
1206: }
|