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