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