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