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