/* * (c) 2011 - 2013 University of Mannheim: Software Engineering Group */ package de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.GridData; import org.eclipse.draw2d.GridLayout; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.RectangleFigure; import org.eclipse.draw2d.ScalablePolygonShape; import org.eclipse.draw2d.Shape; import org.eclipse.draw2d.StackLayout; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PrecisionPoint; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.gef.EditPart; import org.eclipse.gef.EditPolicy; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.editpolicies.LayoutEditPolicy; import org.eclipse.gef.editpolicies.NonResizableEditPolicy; import org.eclipse.gef.requests.CreateRequest; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil; import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout; import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.widgets.Display; import de.itemis.gmf.runtime.layout.ScaleInnerFigureLayout; /** * @generated */ public class InversionEditPart extends ShapeNodeEditPart { /** * @generated */ public static final int VISUAL_ID = 3065; /** * @generated */ protected IFigure contentPane; /** * @generated */ protected IFigure primaryShape; /** * @generated */ public InversionEditPart(View view) { super(view); } /** * @generated */ protected void createDefaultEditPolicies() { installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy()); super.createDefaultEditPolicies(); installEditPolicy( EditPolicyRoles.SEMANTIC_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.edit.policies.InversionItemSemanticEditPolicy()); installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy()); installEditPolicy( EditPolicyRoles.CANONICAL_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.edit.policies.InversionCanonicalEditPolicy()); installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy()); // XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE); removeEditPolicy(EditPolicyRoles.POPUPBAR_ROLE); installEditPolicy( EditPolicyRoles.POPUPBAR_ROLE, new de.uni_mannheim.informatik.swt.models.plm.diagram.custom.popupbartools.editpolicy.PLMModelElementPopupBarEditPolicy()); } /** * @generated */ protected LayoutEditPolicy createLayoutEditPolicy() { org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() { protected EditPolicy createChildEditPolicy(EditPart child) { EditPolicy result = child .getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); if (result == null) { result = new NonResizableEditPolicy(); } return result; } protected Command getMoveChildrenCommand(Request request) { return null; } protected Command getCreateCommand(CreateRequest request) { return null; } }; return lep; } /** * @generated */ protected IFigure createNodeShape() { return primaryShape = new InversionFigure(); } /** * @generated */ public InversionFigure getPrimaryShape() { return (InversionFigure) primaryShape; } /** * @generated */ protected boolean addFixedChild(EditPart childEditPart) { if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel51EditPart) { ((de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel51EditPart) childEditPart) .setLabel(getPrimaryShape().getFigureInversionNameFigure()); return true; } return false; } /** * @generated */ protected boolean removeFixedChild(EditPart childEditPart) { if (childEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel51EditPart) { return true; } return false; } /** * @generated */ protected void addChildVisual(EditPart childEditPart, int index) { if (addFixedChild(childEditPart)) { return; } super.addChildVisual(childEditPart, -1); } /** * @generated */ protected void removeChildVisual(EditPart childEditPart) { if (removeFixedChild(childEditPart)) { return; } super.removeChildVisual(childEditPart); } /** * @generated */ protected IFigure getContentPaneFor(IGraphicalEditPart editPart) { return getContentPane(); } /** * @generated */ protected NodeFigure createNodePlate() { DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(60, 25); if (true) { HashMap<String, PrecisionPoint> anchorLocations = new HashMap<String, PrecisionPoint>(); anchorLocations.put("NORTH", new PrecisionPoint(0.5d, 0)); anchorLocations.put("EAST", new PrecisionPoint(1d, 0.5d)); anchorLocations.put("SOUTH", new PrecisionPoint(0.5d, 1d)); anchorLocations.put("WEST", new PrecisionPoint(0, 0.5d)); result = new de.uni_mannheim.informatik.swt.models.plm.diagram.custom.figures.DefaultSizeNodeFixedAnchors( 8, 8, anchorLocations); return result; } return result; } /** * Creates figure for this edit part. * * Body of this method does not depend on settings in generation model * so you may safely remove <i>generated</i> tag and modify it. * * @generated */ protected NodeFigure createNodeFigure() { NodeFigure figure = createNodePlate(); figure.setLayoutManager(new StackLayout()); IFigure shape = createNodeShape(); figure.add(shape); contentPane = setupContentPane(shape); return figure; } /** * Default implementation treats passed figure as content pane. * Respects layout one may have set for generated figure. * @param nodeShape instance of generated figure class * @generated */ protected IFigure setupContentPane(IFigure nodeShape) { if (nodeShape.getLayoutManager() == null) { ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout(); layout.setSpacing(5); nodeShape.setLayoutManager(layout); } return nodeShape; // use nodeShape itself as contentPane } /** * @generated */ public IFigure getContentPane() { if (contentPane != null) { return contentPane; } return super.getContentPane(); } /** * @generated */ protected void setForegroundColor(Color color) { if (primaryShape != null) { primaryShape.setForegroundColor(color); } } /** * @generated */ protected void setBackgroundColor(Color color) { if (primaryShape != null) { primaryShape.setBackgroundColor(color); } } /** * @generated */ protected void setLineWidth(int width) { if (primaryShape instanceof Shape) { ((Shape) primaryShape).setLineWidth(width); } } /** * @generated */ protected void setLineType(int style) { if (primaryShape instanceof Shape) { ((Shape) primaryShape).setLineStyle(style); } } /** * @generated */ public EditPart getPrimaryChildEditPart() { return getChildBySemanticHint(de.uni_mannheim.informatik.swt.models.plm.diagram.part.PLMVisualIDRegistry .getType(de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.WrappingLabel51EditPart.VISUAL_ID)); } /** * @generated */ public List<IElementType> getMARelTypesOnSource() { ArrayList<IElementType> types = new ArrayList<IElementType>(2); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015); return types; } /** * @generated */ public List<IElementType> getMARelTypesOnSourceAndTarget( IGraphicalEditPart targetEditPart) { LinkedList<IElementType> types = new LinkedList<IElementType>(); if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ConnectionEditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.EntityEditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.Connection2EditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.Entity2EditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.ConnectionEditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.EntityEditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.Connection2EditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015); } if (targetEditPart instanceof de.uni_mannheim.informatik.swt.models.plm.diagram.edit.parts.Entity2EditPart) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015); } return types; } /** * @generated */ public List<IElementType> getMATypesForTarget(IElementType relationshipType) { LinkedList<IElementType> types = new LinkedList<IElementType>(); if (relationshipType == de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.SetRelationshipBase_4013) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Connection_3060); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Entity_3085); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Connection_3086); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Entity_3069); } else if (relationshipType == de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.InversionInverse_4015) { types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Connection_3060); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Entity_3085); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Connection_3086); types.add(de.uni_mannheim.informatik.swt.models.plm.diagram.providers.PLMElementTypes.Entity_3069); } return types; } /** * Updates the connections after a value was set and does elision * * @generated */ @Override protected void handleNotificationEvent(Notification notification) { super.handleNotificationEvent(notification); if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer) { updateView(); } EStructuralFeature changedFeature = (EStructuralFeature) notification .getFeature(); if (notification.getNotifier() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Element) { if (changedFeature.getName().equalsIgnoreCase("elided") || changedFeature.getName().equalsIgnoreCase("expressed")) { updateView(); } } } /** * * @return null if no DSLRendering infotmation is available, else true or false * * @generated */ private Boolean getDSLRenderingValue() { //boolean collapse = false; //******************************************************** //Find the LMLVisualizer attached to this element //******************************************************** de.uni_mannheim.informatik.swt.models.plm.PLM.Element self = (de.uni_mannheim.informatik.swt.models.plm.PLM.Element) this .resolveSemanticElement(); //No rendering information found => all Connection remains expanded if (self.getVisualizer().size() == 0) { //Hide external name label IFigure boderItemContainer = (IFigure) figure.getChildren().get(1); ((IFigure) boderItemContainer.getChildren().get(0)) .setVisible(false); return null; } de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer r = self .getVisualizer().get(0); String dslRenderingString = r.getValueForKey("DSLRendering"); if ("".equals(dslRenderingString)) return null; return java.lang.Boolean.parseBoolean(dslRenderingString); } /** * @generated */ public void updateView() { setExpressedVisualState(); } /** * @generated */ public class InversionFigure extends ScalablePolygonShape { /** * @generated */ private WrappingLabel fFigureInversionNameFigure; /** * @generated */ public InversionFigure() { ScaleInnerFigureLayout layoutThis = new ScaleInnerFigureLayout(); this.setLayoutManager(layoutThis); this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode() .DPtoLP(30))); this.addPoint(new Point(getMapMode().DPtoLP(10), getMapMode() .DPtoLP(15))); this.addPoint(new Point(getMapMode().DPtoLP(20), getMapMode() .DPtoLP(5))); this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode() .DPtoLP(0))); this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode() .DPtoLP(0))); this.addPoint(new Point(getMapMode().DPtoLP(50), getMapMode() .DPtoLP(5))); this.addPoint(new Point(getMapMode().DPtoLP(60), getMapMode() .DPtoLP(15))); this.addPoint(new Point(getMapMode().DPtoLP(70), getMapMode() .DPtoLP(30))); this.addPoint(new Point(getMapMode().DPtoLP(70), getMapMode() .DPtoLP(50))); this.addPoint(new Point(getMapMode().DPtoLP(60), getMapMode() .DPtoLP(65))); this.addPoint(new Point(getMapMode().DPtoLP(50), getMapMode() .DPtoLP(75))); this.addPoint(new Point(getMapMode().DPtoLP(40), getMapMode() .DPtoLP(80))); this.addPoint(new Point(getMapMode().DPtoLP(30), getMapMode() .DPtoLP(80))); this.addPoint(new Point(getMapMode().DPtoLP(20), getMapMode() .DPtoLP(75))); this.addPoint(new Point(getMapMode().DPtoLP(10), getMapMode() .DPtoLP(65))); this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode() .DPtoLP(50))); this.setFill(true); this.setForegroundColor(ColorConstants.black); this.setPreferredSize(new Dimension(getMapMode().DPtoLP(60), getMapMode().DPtoLP(25))); createContents(); } /** * @generated */ private void createContents() { RectangleFigure nameRectangle0 = new RectangleFigure(); nameRectangle0.setFill(false); nameRectangle0.setOutline(false); this.add(nameRectangle0); GridLayout layoutNameRectangle0 = new GridLayout(); layoutNameRectangle0.numColumns = 1; layoutNameRectangle0.makeColumnsEqualWidth = true; layoutNameRectangle0.horizontalSpacing = 0; layoutNameRectangle0.verticalSpacing = 0; layoutNameRectangle0.marginWidth = 0; layoutNameRectangle0.marginHeight = 0; nameRectangle0.setLayoutManager(layoutNameRectangle0); fFigureInversionNameFigure = new WrappingLabel(); fFigureInversionNameFigure.setText("inverts"); fFigureInversionNameFigure.setForegroundColor(ColorConstants.black); fFigureInversionNameFigure.setFont(FFIGUREINVERSIONNAMEFIGURE_FONT); GridData constraintFFigureInversionNameFigure = new GridData(); constraintFFigureInversionNameFigure.verticalAlignment = GridData.CENTER; constraintFFigureInversionNameFigure.horizontalAlignment = GridData.CENTER; constraintFFigureInversionNameFigure.horizontalIndent = 0; constraintFFigureInversionNameFigure.horizontalSpan = 1; constraintFFigureInversionNameFigure.verticalSpan = 1; constraintFFigureInversionNameFigure.grabExcessHorizontalSpace = true; constraintFFigureInversionNameFigure.grabExcessVerticalSpace = true; nameRectangle0.add(fFigureInversionNameFigure, constraintFFigureInversionNameFigure); } /** * @generated */ public WrappingLabel getFigureInversionNameFigure() { return fFigureInversionNameFigure; } } /** * @generated */ static final Font FFIGUREINVERSIONNAMEFIGURE_FONT = new Font( Display.getCurrent(), Display.getDefault().getSystemFont() .getFontData()[0].getName(), 8, SWT.NORMAL); //Gives the option to diplay a Connection/Generalization/Specialization as black rectangle /** * @generated */ private Dimension cachedSize = null; /** * Sets the figure to visually expressed or computed. Depending on the expressed * value. * * @generated */ private void setExpressedVisualState() { IGraphicalEditPart parent = (IGraphicalEditPart) getParent(); de.uni_mannheim.informatik.swt.models.plm.PLM.Element self = (de.uni_mannheim.informatik.swt.models.plm.PLM.Element) resolveSemanticElement(); //Check is visible if (parent.resolveSemanticElement() instanceof de.uni_mannheim.informatik.swt.models.plm.PLM.Context) { de.uni_mannheim.informatik.swt.models.plm.PLM.Context container = (de.uni_mannheim.informatik.swt.models.plm.PLM.Context) parent .resolveSemanticElement(); if ((container.getOrigin().equalsIgnoreCase("computed") && self .isExpressed()) || (container.getOrigin().equalsIgnoreCase("expressed") && !self .isExpressed())) { if (EditPartUtil.isWriteTransactionInProgress(this, true, true)) { getNotationView().setVisible(false); } } } else { if (EditPartUtil.isWriteTransactionInProgress(this, true, true)) { getNotationView().setVisible(true); } } if (self.isExpressed()) { getPrimaryShape().setLineStyle(SWT.LINE_SOLID); } else { getPrimaryShape().setLineStyle(SWT.LINE_CUSTOM); getPrimaryShape().setLineDash(new float[] { 10 }); } } /** * @generated */ @Override public void addNotify() { super.addNotify(); //Entity EditParts do not have a outer BorderItemContainer in contrast //to Connections etc. as those have external labels updateView(); } /** * Registers the Edipart to fire handleNotification on changes * in LMLVisualizer. * * BUG: Only runs on EditPartCrearion. Items which are added Afterwards are not * listened to. * * @generated */ @Override protected void addSemanticListeners() { super.addSemanticListeners(); de.uni_mannheim.informatik.swt.models.plm.PLM.Element e = (de.uni_mannheim.informatik.swt.models.plm.PLM.Element) resolveSemanticElement(); //Register for listening to LMLVisualizer changes for (de.uni_mannheim.informatik.swt.models.plm.PLM.LMLVisualizer v : e .getVisualizer()) addListenerFilter( v.toString().substring(0, v.toString().indexOf(" ")), this, v); } }