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: CBREditPart.java 8280 2007-07-16 01:48:00Z jzhang $
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.MessageExchange;
0093: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.componentflowFactory;
0094: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.componentflowPackage;
0095: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditorPlugin;
0096: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorPaletteFactory;
0097: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorVisualIDRegistry;
0098: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.rules.RulesUtil;
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.CBRPropertyWizard;
0102: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.WizardUtil;
0103:
0104: /**
0105: * @generated
0106: */
0107: public class CBREditPart extends AbstractGraphicalEditPart implements
0108: NodeEditPart, IUpdatableEditPart {
0109:
0110: /**
0111: * @generated
0112: */
0113: public static final int VISUAL_ID = 2010;
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 CBREditPart(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 CBREditPart.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: // add----------------------------
0301: org.eclipse.draw2d.Label fig = new org.eclipse.draw2d.Label();
0302: fig.setText("");
0303:
0304: ((SEFigure) shape).setFigureSENameFigure(fig);
0305:
0306: invisibleRectangle.add(fig, BorderLayout.BOTTOM);
0307: //---------------------------------------------------
0308:
0309: View view = (View) getModel();
0310: wizardOut(view, true);
0311:
0312: return invisibleRectangle;
0313: }
0314:
0315: /**
0316: * @generated
0317: */
0318: protected IFigure createNodeShape() {
0319: SEFigure figure = new SEFigure();
0320: primaryShape = figure;
0321: return primaryShape;
0322: }
0323:
0324: /**
0325: * @generated
0326: */
0327: public SEFigure getPrimaryShape() {
0328: return (SEFigure) primaryShape;
0329: }
0330:
0331: /**
0332: * @generated NOT
0333: */
0334: private IFigure createDecorationPane() {
0335: View view = (View) getModel();
0336: EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
0337: /*if (annotation == null) {
0338: return null;
0339: }*/
0340:
0341: Figure decorationPane = new Figure();
0342: decorationPane.setLayoutManager(new BorderLayout());
0343:
0344: ImageFigure imageFigure = new ImageFigure(
0345: ComponentFlowEditorDiagramEditorPlugin.getInstance()
0346: .getBundledImage("icons/CBR32.ico"),
0347: PositionConstants.CENTER);
0348: decorationPane.add(imageFigure, BorderLayout.TOP);
0349: return decorationPane;
0350: }
0351:
0352: /**
0353: * Default implementation treats passed figure as content pane.
0354: * Respects layout one may have set for generated figure.
0355: * @param nodeShape instance of generated figure class
0356: * @generated
0357: */
0358: protected IFigure setupContentPane(IFigure nodeShape) {
0359: if (nodeShape.getLayoutManager() == null) {
0360: ToolbarLayout layout = new ToolbarLayout();
0361: layout.setSpacing(5);
0362: nodeShape.setLayoutManager(layout);
0363: }
0364: return nodeShape; // use nodeShape itself as contentPane
0365: }
0366:
0367: /**
0368: * @generated
0369: */
0370: public IFigure getContentPane() {
0371: if (contentPane == null) {
0372: return super .getContentPane();
0373: }
0374: return contentPane;
0375: }
0376:
0377: /**
0378: * @generated
0379: */
0380: public Node getDiagramNode() {
0381: return (Node) getModel();
0382: }
0383:
0384: /**
0385: * @generated
0386: */
0387: protected boolean addFixedChild(EditPart childEditPart) {
0388: if (childEditPart instanceof CBRNameEditPart) {
0389: ((CBRNameEditPart) childEditPart)
0390: .setLabel(getPrimaryShape().getFigureSENameFigure());
0391: return true;
0392: }
0393: return false;
0394: }
0395:
0396: /**
0397: * @generated
0398: */
0399: protected boolean removeFixedChild(EditPart childEditPart) {
0400: return false;
0401: }
0402:
0403: /**
0404: * Returns the label which should be direct-edited by default.
0405: * @generated
0406: */
0407: private EditPart getPrimaryLabelEditPart() {
0408: for (Iterator it = getDiagramNode().getChildren().iterator(); it
0409: .hasNext();) {
0410: View nextChild = (View) it.next();
0411: if (ComponentFlowEditorVisualIDRegistry
0412: .getVisualID(nextChild) == CBRNameEditPart.VISUAL_ID) {
0413: return (EditPart) getViewer().getEditPartRegistry()
0414: .get(nextChild);
0415: }
0416: }
0417: return null;
0418: }
0419:
0420: /**
0421: * @generated NOT
0422: */
0423: public void performRequest(Request req) {
0424: if (RequestConstants.REQ_DIRECT_EDIT == req.getType()) {
0425: EditPart labelToEdit;
0426: if (req instanceof DirectEditRequest) {
0427: labelToEdit = getLabelEditPart((DirectEditRequest) req);
0428: } else {
0429: labelToEdit = getPrimaryLabelEditPart();
0430: }
0431: if (labelToEdit != null) {
0432: labelToEdit.performRequest(req);
0433: }
0434: }
0435:
0436: // Figure double clicked
0437: if (REQ_OPEN.equals(req.getType())) {
0438: /*if(WizardUtil.whetherUseWizard)
0439: {
0440: View view = (View) getModel();
0441: wizardOut(view, false);
0442: super.performRequest(req);
0443: }*/
0444: return;
0445: }
0446: }
0447:
0448: /**
0449: * @generated
0450: */
0451: private EditPart getLabelEditPart(DirectEditRequest req) {
0452: EditPart result = getViewer().findObjectAt(req.getLocation());
0453: if (result != null) {
0454: View view = (View) result.getModel();
0455: if (getDiagramNode().getChildren().contains(view)) {
0456: int visualId = ComponentFlowEditorVisualIDRegistry
0457: .getVisualID(view);
0458: switch (visualId) {
0459: case CBRNameEditPart.VISUAL_ID:
0460: return result;
0461: }
0462: }
0463: }
0464: return getPrimaryLabelEditPart();
0465: }
0466:
0467: /**
0468: * @generated
0469: */
0470: protected void addChildVisual(EditPart childEditPart, int index) {
0471: if (addFixedChild(childEditPart)) {
0472: return;
0473: }
0474: super .addChildVisual(childEditPart, -1);
0475: }
0476:
0477: /**
0478: * @generated
0479: */
0480: protected void removeChildVisual(EditPart childEditPart) {
0481: if (removeFixedChild(childEditPart)) {
0482: return;
0483: }
0484: super .removeChildVisual(childEditPart);
0485: }
0486:
0487: /**
0488: * @generated NOT
0489: */
0490: protected void refreshVisuals() {
0491: super .refreshVisuals();
0492: refreshBounds();
0493: refreshBackgroundColor();
0494: refreshForegroundColor();
0495: refreshFont();
0496: refreshVisibility();
0497:
0498: }
0499:
0500: /**
0501: * @generated
0502: */
0503: protected void refreshVisibility() {
0504: boolean isVisible = getDiagramNode().isVisible();
0505: boolean wasVisible = getFigure().isVisible();
0506: if (isVisible == wasVisible) {
0507: return;
0508: }
0509: if (!isVisible && (getSelected() != SELECTED_NONE)) {
0510: getViewer().deselect(this );
0511: }
0512:
0513: getFigure().setVisible(isVisible);
0514: getFigure().revalidate();
0515: }
0516:
0517: /**
0518: * @generated
0519: */
0520: protected void refreshBounds() {
0521: Node node = getDiagramNode();
0522: assert node.getLayoutConstraint() instanceof Bounds;
0523: Bounds bounds = (Bounds) node.getLayoutConstraint();
0524: ((GraphicalEditPart) getParent()).setLayoutConstraint(this ,
0525: getFigure(), new Rectangle(bounds.getX(),
0526: bounds.getY(), bounds.getWidth(), bounds
0527: .getHeight()));
0528: }
0529:
0530: /**
0531: * @generated
0532: */
0533: protected List getModelChildren() {
0534: return getDiagramNode().getVisibleChildren();
0535: }
0536:
0537: /**
0538: * @generated
0539: */
0540: protected List getModelSourceConnections() {
0541: return getDiagramNode().getSourceEdges();
0542: }
0543:
0544: /**
0545: * @generated NOT
0546: */
0547: protected List getModelTargetConnections() {
0548:
0549: return getDiagramNode().getTargetEdges();
0550: }
0551:
0552: /**
0553: * @generated NOT
0554: */
0555: public void adjustName() {
0556: ComponentFlowEditorEditPartFactory.setModelName(this , "CBR");
0557: }
0558:
0559: /**
0560: * @generated NOT
0561: */
0562: public void wizardOut(View view, boolean newCom) {
0563:
0564: if (newCom && !WizardUtil.canWizardOut(view))
0565: return;
0566:
0567: final CBRPropertyWizard CBRWizard = new CBRPropertyWizard();
0568: if (newCom) {
0569: CBRWizard
0570: .setAddedOperation((ComponentFlowEditorElement) view
0571: .getElement());
0572: WizardDialog wizard = new WizardDialog(PlatformUI
0573: .getWorkbench().getActiveWorkbenchWindow()
0574: .getShell(), CBRWizard);
0575: wizard.open();
0576: } else {
0577: CBRWizard
0578: .setUpdateOperation((ComponentFlowEditorElement) view
0579: .getElement());
0580:
0581: TransactionalEditingDomain domain = TransactionUtil
0582: .getEditingDomain(view.getElement());
0583: domain.getCommandStack().execute(
0584: new RecordingCommand(domain) {
0585:
0586: public void doExecute() {
0587: WizardDialog wizard = new WizardDialog(
0588: PlatformUI.getWorkbench()
0589: .getActiveWorkbenchWindow()
0590: .getShell(), CBRWizard);
0591: wizard.open();
0592: }
0593: });
0594: }
0595:
0596: }
0597:
0598: /**
0599: * @generated
0600: */
0601: public ConnectionAnchor getSourceConnectionAnchor(
0602: ConnectionEditPart connection) {
0603: return new ChopboxAnchor(getFigure());
0604: }
0605:
0606: /**
0607: * @generated
0608: */
0609: public ConnectionAnchor getSourceConnectionAnchor(Request request) {
0610: return new ChopboxAnchor(getFigure());
0611: }
0612:
0613: /**
0614: * @generated
0615: */
0616: public ConnectionAnchor getTargetConnectionAnchor(
0617: ConnectionEditPart connection) {
0618: return new ChopboxAnchor(getFigure());
0619: }
0620:
0621: /**
0622: * @generated
0623: */
0624: public ConnectionAnchor getTargetConnectionAnchor(Request request) {
0625: return new ChopboxAnchor(getFigure());
0626: }
0627:
0628: /**
0629: * @generated
0630: */
0631: public Object getAdapter(Class key) {
0632: return super .getAdapter(key);
0633: }
0634:
0635: /**
0636: * @generated NOT
0637: */
0638: public void activate() {
0639: super .activate();
0640: RulesUtil.addModel(this );
0641:
0642: getDiagramNode().getElement().eAdapters().add(
0643: domainModelRefresher);
0644: }
0645:
0646: /**
0647: * @generated NOT
0648: */
0649: public void deactivate() {
0650: RulesUtil.removeModel(this );
0651: getDiagramNode().getElement().eAdapters().remove(
0652: domainModelRefresher);
0653: super .deactivate();
0654: }
0655:
0656: /**
0657: * @generated
0658: */
0659: private DomainModelRefresher domainModelRefresher = new DomainModelRefresher();
0660:
0661: /**
0662: * @generated
0663: */
0664: private class DomainModelRefresher extends AdapterImpl {
0665: /**
0666: * @generated NOT
0667: */
0668: public void notifyChanged(Notification msg) {
0669: super .notifyChanged(msg);
0670: if (msg.isTouch()) {
0671: return;
0672: }
0673: Refresher refresher = getRefresher((EStructuralFeature) msg
0674: .getFeature(), msg);
0675: if (refresher != null) {
0676: refresher.refresh();
0677: }
0678: adjustName();
0679: }
0680: }
0681:
0682: /**
0683: * @generated
0684: */
0685: public void addRefresher(EStructuralFeature feature,
0686: Refresher refresher) {
0687: CompositeRefresher compositeRefresher = getCompositeRefresher(feature);
0688: compositeRefresher.addRefresher(refresher);
0689: }
0690:
0691: /**
0692: * @generated
0693: */
0694: public void removeRefresher(EStructuralFeature feature,
0695: Refresher refresher) {
0696: CompositeRefresher compositeRefresher = getCompositeRefresher(feature);
0697: compositeRefresher.removeRefresher(refresher);
0698: }
0699:
0700: /**
0701: * @generated
0702: */
0703: private CompositeRefresher getCompositeRefresher(
0704: EStructuralFeature feature) {
0705: if (structuralFeatures2Refresher == null) {
0706: createRefreshers();
0707: }
0708: Refresher refresher = (Refresher) structuralFeatures2Refresher
0709: .get(feature);
0710: if (refresher instanceof CompositeRefresher) {
0711: return (CompositeRefresher) refresher;
0712: }
0713: CompositeRefresher result = new CompositeRefresher();
0714: if (refresher != null) {
0715: result.addRefresher(refresher);
0716: }
0717: structuralFeatures2Refresher.put(feature, result);
0718: return result;
0719: }
0720:
0721: /**
0722: * @generated
0723: */
0724: protected void refreshFont() {
0725: FontStyle style = (FontStyle) getDiagramNode().getStyle(
0726: NotationPackage.eINSTANCE.getFontStyle());
0727: Font toDispose = createdFont;
0728: if (style != null) {
0729: String fontName = style.getFontName();
0730: int fontHeight = style.getFontHeight();
0731: int fontStyle = SWT.NORMAL;
0732: if (style.isBold()) {
0733: fontStyle |= SWT.BOLD;
0734: }
0735: if (style.isItalic()) {
0736: fontStyle |= SWT.ITALIC;
0737: }
0738: Font currentFont = getFigure().getFont();
0739: if (currentFont != null) {
0740: FontData currentFontData = currentFont.getFontData()[0];
0741: if (currentFontData.getName().equals(fontName)
0742: && currentFontData.getHeight() == fontHeight
0743: && currentFontData.getStyle() == fontStyle) {
0744: return;
0745: }
0746: }
0747: createdFont = new Font(null, fontName, fontHeight,
0748: fontStyle);
0749: getFigure().setFont(createdFont);
0750: } else {
0751: //revert to the default font
0752: getFigure().setFont(getViewer().getControl().getFont());
0753: createdFont = null;
0754: }
0755: if (toDispose != null) {
0756: toDispose.dispose();
0757: }
0758: }
0759:
0760: /**
0761: * The font (created by {@link #refreshFont()}) currently assigned to the label (unless the default font is assigned).
0762: * Whenever another non-default font is assigned to it, it is safe to dispose the previous one.
0763: * @generated
0764: */
0765: private Font createdFont;
0766:
0767: /**
0768: * @generated
0769: */
0770: protected void refreshForegroundColor() {
0771: LineStyle style = (LineStyle) getDiagramNode().getStyle(
0772: NotationPackage.eINSTANCE.getLineStyle());
0773: Color toDispose = createdForegroundColor;
0774: if (style != null) {
0775: int foregroundColor = style.getLineColor();
0776: int red = foregroundColor & 0x000000FF;
0777: int green = (foregroundColor & 0x0000FF00) >> 8;
0778: int blue = (foregroundColor & 0x00FF0000) >> 16;
0779: Color currentColor = getFigure().getForegroundColor();
0780: if (currentColor != null && currentColor.getRed() == red
0781: && currentColor.getGreen() == green
0782: && currentColor.getBlue() == blue) {
0783: return;
0784: }
0785: createdForegroundColor = new Color(null, red, green, blue);
0786: getFigure().setForegroundColor(createdForegroundColor);
0787: } else {
0788: getFigure().setForegroundColor(
0789: getViewer().getControl().getForeground());
0790: createdForegroundColor = null;
0791: }
0792: if (toDispose != null) {
0793: toDispose.dispose();
0794: }
0795: }
0796:
0797: /**
0798: * The color (created by {@link #refreshForegroundColor()}) currently assigned to the figure.
0799: * Whenever another color is assigned to it, it is safe to dispose the previous one.
0800: * @generated
0801: */
0802: private Color createdForegroundColor;
0803:
0804: /**
0805: * @generated
0806: */
0807: protected void refreshBackgroundColor() {
0808: FillStyle style = (FillStyle) getDiagramNode().getStyle(
0809: NotationPackage.eINSTANCE.getFillStyle());
0810: Color toDispose = createdBackgroundColor;
0811: if (style != null) {
0812: int backgroundColor = style.getFillColor();
0813: int red = backgroundColor & 0x000000FF;
0814: int green = (backgroundColor & 0x0000FF00) >> 8;
0815: int blue = (backgroundColor & 0x00FF0000) >> 16;
0816: Color currentColor = getFigure().getBackgroundColor();
0817: if (currentColor != null && currentColor.getRed() == red
0818: && currentColor.getGreen() == green
0819: && currentColor.getBlue() == blue) {
0820: return;
0821: }
0822: createdBackgroundColor = new Color(null, red, green, blue);
0823: getFigure().setBackgroundColor(createdBackgroundColor);
0824: } else {
0825: getFigure().setBackgroundColor(
0826: getViewer().getControl().getBackground());
0827: }
0828: if (toDispose != null) {
0829: toDispose.dispose();
0830: }
0831: }
0832:
0833: /**
0834: * The color (created by {@link #refreshBackgroundColor()}) currently assigned to the figure.
0835: * Whenever another color is assigned to it, it is safe to dispose the previous one.
0836: * @generated
0837: */
0838: private Color createdBackgroundColor;
0839:
0840: /**
0841: * @generated
0842: */
0843: private HashMap structuralFeatures2Refresher;
0844:
0845: /**
0846: * @generated
0847: */
0848: public Refresher getRefresher(EStructuralFeature feature,
0849: Notification msg) {
0850: if (structuralFeatures2Refresher == null) {
0851: createRefreshers();
0852: }
0853: return (Refresher) structuralFeatures2Refresher.get(feature);
0854: }
0855:
0856: /**
0857: * @generated NOT
0858: */
0859: private void createRefreshers() {
0860: structuralFeatures2Refresher = new HashMap();
0861: Refresher childrenRefresher = new Refresher() {
0862: public void refresh() {
0863: refreshChildren();
0864: }
0865: };
0866: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0867: .getView_PersistedChildren(), childrenRefresher);
0868: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0869: .getView_TransientChildren(), childrenRefresher);
0870: Refresher boundsRefresher = new Refresher() {
0871: public void refresh() {
0872: refreshBounds();
0873: }
0874: };
0875: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0876: .getNode_LayoutConstraint(), boundsRefresher);
0877: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0878: .getSize_Width(), boundsRefresher);
0879: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0880: .getSize_Height(), boundsRefresher);
0881: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0882: .getLocation_X(), boundsRefresher);
0883: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0884: .getLocation_Y(), boundsRefresher);
0885: Refresher visibilityRefresher = new Refresher() {
0886: public void refresh() {
0887: refreshVisibility();
0888: }
0889: };
0890: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0891: .getView_Visible(), visibilityRefresher);
0892: Refresher sourceEdgesRefresher = new Refresher() {
0893: public void refresh() {
0894: refreshSourceConnections();
0895: }
0896: };
0897: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0898: .getView_SourceEdges(), sourceEdgesRefresher);
0899: Refresher targetEdgesRefresher = new Refresher() {
0900: public void refresh() {
0901: refreshTargetConnections();
0902: }
0903: };
0904: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0905: .getView_TargetEdges(), targetEdgesRefresher);
0906: Refresher fontRefresher = new Refresher() {
0907: public void refresh() {
0908: refreshFont();
0909: }
0910: };
0911: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0912: .getFontStyle_FontHeight(), fontRefresher);
0913: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0914: .getFontStyle_FontName(), fontRefresher);
0915: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0916: .getFontStyle_Bold(), fontRefresher);
0917: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0918: .getFontStyle_Italic(), fontRefresher);
0919:
0920: Refresher backgroundColorRefresher = new Refresher() {
0921: public void refresh() {
0922: refreshBackgroundColor();
0923: }
0924: };
0925: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0926: .getFillStyle_FillColor(), backgroundColorRefresher);
0927: Refresher foregroundColorRefresher = new Refresher() {
0928: public void refresh() {
0929: refreshForegroundColor();
0930: }
0931: };
0932: structuralFeatures2Refresher.put(NotationPackage.eINSTANCE
0933: .getLineStyle_LineColor(), foregroundColorRefresher);
0934: }
0935:
0936: /**
0937: * @generated
0938: */
0939: private static class CreateMessageExchange4001StartCommand extends
0940: AbstractCommand {
0941: /**
0942: * @generated
0943: */
0944: private View source;
0945:
0946: /**
0947: * @generated
0948: */
0949: public CreateMessageExchange4001StartCommand(
0950: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx) {
0951: //Until the mouse button is pressed, the source of the connection is in request.getTargetEditPart(), not in request.getSourceEditPart().
0952: source = (View) requestEx.getTargetEditPart().getModel();
0953: }
0954:
0955: /**
0956: * @generated
0957: */
0958: public void execute() {
0959: //This command never gets executed
0960: }
0961:
0962: /**
0963: * @generated
0964: */
0965: public void undo() {
0966: //This command never gets executed
0967: }
0968:
0969: /**
0970: * @generated
0971: */
0972: public void redo() {
0973: //This command never gets executed
0974: }
0975:
0976: /**
0977: * @generated
0978: */
0979: public boolean canUndo() {
0980: return true;
0981: }
0982:
0983: /**
0984: * @generated
0985: */
0986: protected boolean prepare() {
0987: if (source == null) {
0988: return false;
0989: }
0990: ComponentFlowEditorDocument container = (ComponentFlowEditorDocument) getRelationshipContainer(
0991: source.getElement(), componentflowPackage.eINSTANCE
0992: .getComponentFlowEditorDocument());
0993: if (container == null) {
0994: return false;
0995: }
0996:
0997: return true;
0998: }
0999:
1000: /**
1001: * Finds container element for the new relationship of the specified type.
1002: * Default implementation goes up by containment hierarchy starting from
1003: * the specified element and returns the first element that is instance of
1004: * the specified container class.
1005: *
1006: * @generated
1007: */
1008: protected EObject getRelationshipContainer(EObject element,
1009: EClass containerClass) {
1010: for (; element != null; element = element.eContainer()) {
1011: if (containerClass.isSuperTypeOf(element.eClass())) {
1012: return element;
1013: }
1014: }
1015: return null;
1016: }
1017:
1018: }
1019:
1020: /**
1021: * @generated
1022: */
1023: private static class CreateMessageExchange4001Command extends
1024: AbstractCommand {
1025: /**
1026: * @generated
1027: */
1028: private final View source;
1029:
1030: /**
1031: * @generated
1032: */
1033: private final View target;
1034:
1035: /**
1036: * @generated
1037: */
1038: private final Edge createdEdge;
1039:
1040: /**
1041: * @generated
1042: */
1043: private final org.eclipse.emf.common.command.Command domainModelAddCommand;
1044:
1045: /**
1046: * @generated
1047: */
1048: public CreateMessageExchange4001Command(
1049: ComponentFlowEditorPaletteFactory.CreateConnectionRequestEx requestEx) {
1050: if (requestEx.getSourceEditPart().getModel() instanceof View) {
1051: source = (View) requestEx.getSourceEditPart()
1052: .getModel();
1053: } else {
1054: source = null;
1055: }
1056: if (requestEx.getTargetEditPart().getModel() instanceof View) {
1057: target = (View) requestEx.getTargetEditPart()
1058: .getModel();
1059: } else {
1060: target = null;
1061: }
1062: if (source == null || target == null) {
1063: createdEdge = null;
1064: domainModelAddCommand = org.eclipse.emf.common.command.UnexecutableCommand.INSTANCE;
1065: return;
1066: }
1067: createdEdge = NotationFactory.eINSTANCE.createEdge();
1068: MessageExchange createdDomainElement = componentflowFactory.eINSTANCE
1069: .createMessageExchange();
1070: createdEdge.setElement(createdDomainElement);
1071:
1072: DomainElementInitializer.MessageExchange_4001
1073: .initializeElement(createdDomainElement);
1074: MessageExchangeViewFactory.decorateView(createdEdge);
1075: TransactionalEditingDomain domainModelEditDomain = TransactionUtil
1076: .getEditingDomain(source.getDiagram().getElement());
1077: org.eclipse.emf.common.command.CompoundCommand addLinkEndsCommand = new org.eclipse.emf.common.command.CompoundCommand();
1078: EObject container = getRelationshipContainer(source
1079: .getElement(), componentflowPackage.eINSTANCE
1080: .getComponentFlowEditorDocument());
1081: if (container == null) {
1082: domainModelAddCommand = null;
1083: return;
1084: }
1085: addLinkEndsCommand
1086: .append(AddCommand
1087: .create(
1088: domainModelEditDomain,
1089: container,
1090: componentflowPackage.eINSTANCE
1091: .getComponentFlowEditorDocument_MessageExchanges(),
1092: createdDomainElement));
1093:
1094: if (createdDomainElement.getSourceElement() != null) {
1095: domainModelAddCommand = null;
1096: return;
1097: }
1098: addLinkEndsCommand.append(SetCommand.create(
1099: domainModelEditDomain, createdDomainElement,
1100: componentflowPackage.eINSTANCE
1101: .getMessageExchange_SourceElement(), source
1102: .getElement()));
1103:
1104: if (createdDomainElement.getTargetElement() != null) {
1105: domainModelAddCommand = null;
1106: return;
1107: }
1108: addLinkEndsCommand.append(SetCommand.create(
1109: domainModelEditDomain, createdDomainElement,
1110: componentflowPackage.eINSTANCE
1111: .getMessageExchange_TargetElement(), target
1112: .getElement()));
1113: domainModelAddCommand = addLinkEndsCommand;
1114: }
1115:
1116: /**
1117: * Finds container element for the new relationship of the specified type.
1118: * Default implementation goes up by containment hierarchy starting from
1119: * the specified element and returns the first element that is instance of
1120: * the specified container class.
1121: *
1122: * @generated
1123: */
1124: protected EObject getRelationshipContainer(EObject element,
1125: EClass containerClass) {
1126: for (; element != null; element = element.eContainer()) {
1127: if (containerClass.isSuperTypeOf(element.eClass())) {
1128: return element;
1129: }
1130: }
1131: return null;
1132: }
1133:
1134: /**
1135: * @generated
1136: */
1137: public boolean canExecute() {
1138: if (source == null || target == null || createdEdge == null
1139: || domainModelAddCommand == null
1140: || !domainModelAddCommand.canExecute()) {
1141: return false;
1142: }
1143:
1144: return true;
1145: }
1146:
1147: /**
1148: * @generated
1149: */
1150: public boolean canUndo() {
1151: return source != null && target != null
1152: && createdEdge != null
1153: && domainModelAddCommand != null
1154: && domainModelAddCommand.canUndo();
1155: }
1156:
1157: /**
1158: * @generated
1159: */
1160: public void execute() {
1161: domainModelAddCommand.execute();
1162: source.getDiagram().insertEdge(createdEdge);
1163: createdEdge.setSource(source);
1164: createdEdge.setTarget(target);
1165: }
1166:
1167: /**
1168: * @generated
1169: */
1170: public void undo() {
1171: domainModelAddCommand.undo();
1172: source.getDiagram().removeEdge(createdEdge);
1173: createdEdge.setSource(null);
1174: createdEdge.setTarget(null);
1175: }
1176:
1177: /**
1178: * @generated
1179: */
1180: public void redo() {
1181: execute();
1182: }
1183: }
1184:
1185: /**
1186: * @generated
1187: */
1188: public class SEFigure extends org.eclipse.draw2d.RectangleFigure {
1189:
1190: /**
1191: * @generated
1192: */
1193: public SEFigure() {
1194:
1195: this
1196: .setBackgroundColor(org.eclipse.draw2d.ColorConstants.orange
1197:
1198: );
1199: this .setPreferredSize(getMapMode().DPtoLP(80), getMapMode()
1200: .DPtoLP(50));
1201: createContents();
1202: }
1203:
1204: /**
1205: * @generated NOT
1206: */
1207: private void createContents() {
1208: /*org.eclipse.draw2d.Label fig_0 = new org.eclipse.draw2d.Label();
1209: fig_0.setText("<...>");
1210:
1211: setFigureSENameFigure(fig_0);
1212:
1213: Object layData0 = null;
1214:
1215: this.add(fig_0, layData0);*/
1216: }
1217:
1218: /**
1219: * @generated
1220: */
1221: private org.eclipse.draw2d.Label fSENameFigure;
1222:
1223: /**
1224: * @generated
1225: */
1226: public org.eclipse.draw2d.Label getFigureSENameFigure() {
1227: return fSENameFigure;
1228: }
1229:
1230: /**
1231: * @generated
1232: */
1233: private void setFigureSENameFigure(org.eclipse.draw2d.Label fig) {
1234: fSENameFigure = fig;
1235: }
1236:
1237: /**
1238: * @generated
1239: */
1240: private boolean myUseLocalCoordinates = false;
1241:
1242: /**
1243: * @generated
1244: */
1245: protected boolean useLocalCoordinates() {
1246: return myUseLocalCoordinates;
1247: }
1248:
1249: /**
1250: * @generated
1251: */
1252: protected void setUseLocalCoordinates(
1253: boolean useLocalCoordinates) {
1254: myUseLocalCoordinates = useLocalCoordinates;
1255: }
1256:
1257: }
1258:
1259: /**
1260: * @generated
1261: */
1262: private static class MapModeWorkaround {
1263: /**
1264: * @generated
1265: */
1266: public int DPtoLP(int dp) {
1267: return dp;
1268: }
1269:
1270: /**
1271: * @generated
1272: */
1273: public static MapModeWorkaround INSTANCE = new MapModeWorkaround();
1274: }
1275:
1276: /**
1277: * @generated
1278: */
1279: private MapModeWorkaround getMapMode() {
1280: return MapModeWorkaround.INSTANCE;
1281: }
1282: }
|