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