diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/FRaMEDDeleteConnectionFeature.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/FRaMEDDeleteConnectionFeature.java index 18eef98fc72123eb81da8c73b2a5481be5b9de70..3f4fe843c4b7d06b824a26fae7847f26d23d25dc 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/FRaMEDDeleteConnectionFeature.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/graphitifeatures/FRaMEDDeleteConnectionFeature.java @@ -10,8 +10,11 @@ import org.eclipse.graphiti.features.context.impl.MultiDeleteInfo; import org.eclipse.graphiti.mm.pictograms.Connection; import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; +import org.framed.iorm.model.Relation; +import org.framed.iorm.model.Type; import org.framed.iorm.ui.literals.IdentifierLiterals; import org.framed.iorm.ui.providers.FeatureProvider; +import org.framed.iorm.ui.util.ConnectionPatternUtil; import org.framed.iorm.ui.util.GeneralUtil; import org.framed.iorm.ui.util.PropertyUtil; @@ -27,7 +30,8 @@ public class FRaMEDDeleteConnectionFeature extends DefaultDeleteFeature { /** * the identifiers for the connection decorators to delete with when deleting a connection */ - protected static final String SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR = IdentifierLiterals.SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR; + protected static final String SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR = IdentifierLiterals.SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR, + SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR = IdentifierLiterals.SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR; /** * Class constructor @@ -53,7 +57,8 @@ public class FRaMEDDeleteConnectionFeature extends DefaultDeleteFeature { */ @Override public void delete(IDeleteContext deleteContext) { - deleteAttachedConstraints(deleteContext); + Relation relation = (Relation) getBusinessObjectForPictogramElement(deleteContext.getPictogramElement()); + if(relation.getType() == Type.RELATIONSHIP) deleteAttachedConstraints(deleteContext); ((DeleteContext) deleteContext).setMultiDeleteInfo(new MultiDeleteInfo(false, false, 0)); super.delete(deleteContext); } @@ -62,26 +67,31 @@ public class FRaMEDDeleteConnectionFeature extends DefaultDeleteFeature { * deletes intra and inter relationship constraints when deleting a relationship using the * following steps: * <p> - * Step 1: find intra relationship constraints by iterating over the connection decorators of the - * relationship to delete<br> - * Step 2: TODO - * Step 3: delete the business objects of all found intra and inter relationship constraints + * Step 1: find intra relationship constraints business elements by checking the referenced relations of the relationship + * to delete<br> + * Step 2: find inter relationship constraints pictogram elements by checking the anchor for the pictogram model + * of the relationship to delete + * Step 3: delete the business objects and pictogram elements of all found intra and inter relationship constraints * @param deleteContext the context with a reference to the relationship to delete */ private void deleteAttachedConstraints(IDeleteContext deleteContext) { - List<ConnectionDecorator> decoratorsToDelete = new ArrayList<ConnectionDecorator>(); Connection connection = (Connection) deleteContext.getPictogramElement(); + Relation relation = (Relation) getBusinessObjectForPictogramElement(connection); + List<Relation> relationsToDeleteAlso = new ArrayList<Relation>(); + List<Connection> connectionsToDeleteAlso = new ArrayList<Connection>(); //Step 1 - for(ConnectionDecorator decorator : connection.getConnectionDecorators()) { - if(PropertyUtil.isShape_IdValue(decorator, SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR)) - decoratorsToDelete.add(decorator); - } + relationsToDeleteAlso.addAll(relation.getReferencedRelation()); //Step 2 - //TODO - //Step 3 - for(ConnectionDecorator decorator : decoratorsToDelete) { - deleteBusinessObject(GeneralUtil.getBusinessObjectForPictogramElement(decorator)); + ConnectionDecorator anchorDecorator = + ConnectionPatternUtil.getConnectionDecoratorByShapeId(connection, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR); + connectionsToDeleteAlso.addAll(anchorDecorator.getAnchors().get(0).getIncomingConnections()); + connectionsToDeleteAlso.addAll(anchorDecorator.getAnchors().get(0).getOutgoingConnections()); + //Step 4 + for(Relation relationToDeleteAlso : relationsToDeleteAlso) { + deleteBusinessObject(relationToDeleteAlso); } - } - + for(Connection connectionToDeleteAlso : connectionsToDeleteAlso) { + DeleteContext deleteContextForInterRelCon = new DeleteContext(connectionToDeleteAlso); + delete(deleteContextForInterRelCon); + } } } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/RelationshipPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/RelationshipPattern.java index 23819cdb0702251af56962abcda06345656e6e13..272aa82ddadf7ccf3941c69ab4efe52fc303b333 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/RelationshipPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/RelationshipPattern.java @@ -10,11 +10,8 @@ import org.eclipse.graphiti.mm.algorithms.Polyline; import org.eclipse.graphiti.mm.algorithms.Rectangle; import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.pictograms.Anchor; -import org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor; -import org.eclipse.graphiti.mm.pictograms.ChopboxAnchor; import org.eclipse.graphiti.mm.pictograms.Connection; import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; -import org.eclipse.graphiti.mm.pictograms.FixPointAnchor; import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.util.IColorConstant; import org.framed.iorm.model.NamedElement; @@ -126,12 +123,20 @@ public class RelationshipPattern extends FRaMEDConnectionPattern { /** * adds the relationship to the pictogram diagram using the following steps: * <p> - * Step 1: create a connection shape and polyline as its graphic algorithm<br> - * Step 2: create the a connection decorator for the relationships name<br> - * Step 3: create the a connection decorators for the cardinalities<br> - * TODO - * Step 4: link the pictogram elements and the business objects<br> - * Step 5: opens the wizard to edit the relationships name and cardinalities + * Step 1: creates the connection shape and polyline as its graphic algorithm<br> + * Step 2: creates a connection decorator for the relationships name<br> + * Step 3: creates the connection decorators for the cardinalities<br> + * Step 4: creates a connection decorator for the anchor for inter relationship constraints + * in the visual model + * Step 5: link the pictogram elements and the business objects<br> + * Step 6: set the values for the property shape id of all connection decorators + * Step 7: adds the anchor for inter relationship constraints in the business model + * Step 8: opens the wizard to edit the relationships name and cardinalities + * <p> + * Relationships have two different anchors attached to them. One for the inter relationship + * constraint to hook in the pictogram model. This anchor is used in the operation {@link #add}. + * The other is hooked in by inter relationship constraints in business model and is used in the + * operation {@link #create}. */ @Override public PictogramElement add(IAddContext addContext) { @@ -158,38 +163,35 @@ public class RelationshipPattern extends FRaMEDConnectionPattern { Text sourceLabel = graphicAlgorithmService.createText(connectionDecoratorForSourceLabel, addedRelationship.getSourceLabel().getName()); graphicAlgorithmService.setLocation(sourceLabel, 0, -1*DISTANCE_FROM_CONNECTION_LINE); sourceLabel.setForeground(manageColor(COLOR_TEXT)); - ConnectionDecorator connectionDecoratorForTargetLabel = pictogramElementCreateService.createConnectionDecorator(connection, true, 0.9, true); Text targetLabel = graphicAlgorithmService.createText(connectionDecoratorForTargetLabel, addedRelationship.getTargetLabel().getName()); graphicAlgorithmService.setLocation(targetLabel, 0, -1*DISTANCE_FROM_CONNECTION_LINE); targetLabel.setForeground(manageColor(COLOR_TEXT)); - //Step 4 ConnectionDecorator connectionDecoratorForAnchor = pictogramElementCreateService.createConnectionDecorator(connection, true, 0.5, true); Rectangle rectangle = graphicAlgorithmService.createRectangle(connectionDecoratorForAnchor); graphicAlgorithmService.setSize(rectangle, 1, 1); - //TODO erkl�ren addAnchor graphical model pictogramElementCreateService.createChopboxAnchor(connectionDecoratorForAnchor); - //Step 4 + //Step 5 link(connection, addedRelationship); link(connectionDecoratorForName, addedRelationship); link(connectionDecoratorForSourceLabel, addedRelationship); link(connectionDecoratorForTargetLabel, addedRelationship); link(connectionDecoratorForAnchor, addedRelationship); - //TODO + //Step 6 PropertyUtil.setShape_IdValue(connectionDecoratorForName, SHAPE_ID_RELATIONSHIP_NAME_DECORATOR); PropertyUtil.setShape_IdValue(connectionDecoratorForSourceLabel, SHAPE_ID_RELATIONSHIP_SOURCE_CARDINALITY_DECORATOR); PropertyUtil.setShape_IdValue(connectionDecoratorForTargetLabel, SHAPE_ID_RELATIONSHIP_TARGET_CARDINALITY_DECORATOR); PropertyUtil.setShape_IdValue(connectionDecoratorForAnchor, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR); - //Step 5 + //Step 7 + pictogramElementCreateService.createChopboxAnchor(connection); + //Step 8 CustomContext customContext = new CustomContext(); PictogramElement[] pictogramElement = new PictogramElement[1]; pictogramElement[0] = connection; customContext.setPictogramElements(pictogramElement); - //TODO erkl�ren CreateAnchor businessmodel - pictogramElementCreateService.createChopboxAnchor(connection); EditRelationshipFeature editRelationshipFeature = getEditRelationshipFeature(customContext); if(editRelationshipFeature.canExecute(customContext)) editRelationshipFeature.execute(customContext); diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/AbstractInterRelationshipConstraintPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/AbstractInterRelationshipConstraintPattern.java index 9a8376774ba79a40cdcb9f2fc87cd501c3477cfe..efe3878eef312e432dd62d027285c9b388239ae1 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/AbstractInterRelationshipConstraintPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/AbstractInterRelationshipConstraintPattern.java @@ -1,11 +1,14 @@ package org.framed.iorm.ui.pattern.connections.interrelationship; +import org.eclipse.graphiti.features.context.IAddConnectionContext; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.features.context.ICreateConnectionContext; import org.eclipse.graphiti.features.context.impl.AddConnectionContext; +import org.eclipse.graphiti.mm.algorithms.Polyline; +import org.eclipse.graphiti.mm.algorithms.styles.LineStyle; import org.eclipse.graphiti.mm.pictograms.Anchor; import org.eclipse.graphiti.mm.pictograms.Connection; -import org.eclipse.graphiti.services.Graphiti; +import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; import org.eclipse.graphiti.util.IColorConstant; import org.framed.iorm.model.OrmFactory; import org.framed.iorm.model.Relation; @@ -14,11 +17,20 @@ import org.framed.iorm.ui.literals.IdentifierLiterals; import org.framed.iorm.ui.literals.LayoutLiterals; import org.framed.iorm.ui.pattern.connections.FRaMEDConnectionPattern; import org.framed.iorm.ui.util.ConnectionPatternUtil; +import org.framed.iorm.ui.util.PropertyUtil; +import org.framed.iorm.ui.pattern.connections.RelationshipPattern; //*import for javadoc link -//TODO +/** + * This is the abstract super class of the patterns for inter relationship contraints. It collects similiar operations + * an attributes of the patterns {@link RelationshipImplicationConstraintPattern} and + * {@link RelationshipExclusionConstraintPattern}. + * @author Kevin Kassin + */ public class AbstractInterRelationshipConstraintPattern extends FRaMEDConnectionPattern { - //TODO + /** + * values for the property shape id gathered from {@link IdentifierLiterals} + */ protected final String SHAPE_ID_INTER_REL_CON = IdentifierLiterals.SHAPE_ID_INTER_REL_CON, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR = IdentifierLiterals.SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR; @@ -59,6 +71,33 @@ public class AbstractInterRelationshipConstraintPattern extends FRaMEDConnection return false; } + /** + * executes some tasks of adding an inter relationship constraint + * <p> + * See {@link RelationshipImplicationConstraintPattern#add} for an explanation. + * @param addContext the context with references to the anchors the business model element + * of a inter relationship constraint uses + * @return the created connection + */ + public Connection addConnectionForInterRelationshipConstraint(IAddContext addContext) { + IAddConnectionContext addConnectionContext = (IAddConnectionContext) addContext; + //Step 1 + Anchor graphicalSourceAnchor = null, + graphicalTargetAnchor = null; + graphicalSourceAnchor = this.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getSourceAnchor()); + graphicalTargetAnchor = this.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getTargetAnchor()); + if(graphicalSourceAnchor == null || graphicalTargetAnchor == null) return null; + //Step 2 + Connection connection = pictogramElementCreateService.createFreeFormConnection(getDiagram()); + connection.setStart(graphicalSourceAnchor); + connection.setEnd(graphicalTargetAnchor); + Polyline polyline = graphicAlgorithmService.createPolyline(connection); + polyline.setForeground(manageColor(COLOR_CONNECTIONS)); + polyline.setLineStyle(LineStyle.DASH); + polyline.setLineWidth(2); + return connection; + } + //create feature //~~~~~~~~~~~~~~ /** @@ -72,70 +111,87 @@ public class AbstractInterRelationshipConstraintPattern extends FRaMEDConnection * (5) target and source connection are of the same type * @return if the inter relationship constraint can be added */ - @Override - public boolean canCreate(ICreateConnectionContext createContext) { - Anchor sourceAnchor = createContext.getSourceAnchor(); - Anchor targetAnchor = createContext.getTargetAnchor(); - org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); - org.framed.iorm.model.ModelElement targetConnection = ConnectionPatternUtil.getModelElementForAnchor(targetAnchor); - if(sourceConnection != null && targetConnection != null) { - if(sourceConnection.getContainer() == targetConnection.getContainer() && - !(sourceConnection.equals(targetConnection))) { - if(sourceConnection.getType() == Type.RELATIONSHIP) - if(targetConnection.getType() == sourceConnection.getType()) - return true; - } } - return false; - } + @Override + public boolean canCreate(ICreateConnectionContext createContext) { + Anchor sourceAnchor = createContext.getSourceAnchor(); + Anchor targetAnchor = createContext.getTargetAnchor(); + org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); + org.framed.iorm.model.ModelElement targetConnection = ConnectionPatternUtil.getModelElementForAnchor(targetAnchor); + if(sourceConnection != null && targetConnection != null) { + if(sourceConnection.getContainer() == targetConnection.getContainer() && + !(sourceConnection.equals(targetConnection))) { + if(sourceConnection.getType() == Type.RELATIONSHIP) + if(targetConnection.getType() == sourceConnection.getType()) + return true; + } } + return false; + } - /** - * checks if a inter relationship constraint can be started from a given source connection - * <p> - * returns true if<br> - * (1) source connection is not null and<br> - * (2) source connection is of valid type - * @return if a inter relationship constraint can be started - */ - @Override - public boolean canStartConnection(ICreateConnectionContext createContext) { - Anchor sourceAnchor = createContext.getSourceAnchor(); - org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); - if(sourceConnection != null){ - if(sourceConnection.getType() == Type.RELATIONSHIP) - return true; - } - return false; - } + /** + * checks if a inter relationship constraint can be started from a given source connection + * <p> + * returns true if<br> + * (1) source connection is not null and<br> + * (2) source connection is of valid type + * @return if a inter relationship constraint can be started + */ + @Override + public boolean canStartConnection(ICreateConnectionContext createContext) { + Anchor sourceAnchor = createContext.getSourceAnchor(); + org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); + if(sourceConnection != null){ + if(sourceConnection.getType() == Type.RELATIONSHIP) + return true; + } + return false; + } - /** - * creates the business object of a inter relationship constraint of the given type using the following steps: - * <p> - * Step 1: get source and target connection<br> - * Step 2: get new inter relationship constraint and add it to the resource of the diagram<br> - * Step 3: set source, target and container of inter relationship constraint<br> - * @param type the type to create a inter relationship constraint of - * @param aircp the sub class calling this operation - */ - public Connection createInterRelationshipConstraint(ICreateConnectionContext createContext, Type type, AbstractInterRelationshipConstraintPattern aircp) { - //Step 1 - Anchor sourceAnchor = createContext.getSourceAnchor(); - Anchor targetAnchor = createContext.getTargetAnchor(); - org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); - org.framed.iorm.model.ModelElement targetConnection = ConnectionPatternUtil.getModelElementForAnchor(targetAnchor); - //Step 2 - Relation newInterRelationshipConstraint = OrmFactory.eINSTANCE.createRelation(); - newInterRelationshipConstraint.setType(type); - if(newInterRelationshipConstraint.eResource() != null) getDiagram().eResource().getContents().add(newInterRelationshipConstraint); - //Step 3 - newInterRelationshipConstraint.setContainer(sourceConnection.getContainer()); - sourceConnection.getContainer().getElements().add(newInterRelationshipConstraint); - newInterRelationshipConstraint.setSource(sourceConnection); - newInterRelationshipConstraint.setTarget(targetConnection); - //Step 4 - AddConnectionContext addContext = new AddConnectionContext(sourceAnchor, targetAnchor); - addContext.setNewObject(newInterRelationshipConstraint); - Connection newConnection = null; - if(aircp.canAdd(addContext)) newConnection = (Connection) aircp.add(addContext); - return newConnection; - } + /** + * creates the business object of a inter relationship constraint of the given type using the following steps: + * <p> + * Step 1: get source and target connection<br> + * Step 2: get new inter relationship constraint and add it to the resource of the diagram<br> + * Step 3: set source, target and container of inter relationship constraint<br> + * @param type the type to create a inter relationship constraint of + * @param aircp the sub class calling this operation + */ + public Connection createInterRelationshipConstraint(ICreateConnectionContext createContext, Type type, AbstractInterRelationshipConstraintPattern aircp) { + //Step 1 + Anchor sourceAnchor = createContext.getSourceAnchor(); + Anchor targetAnchor = createContext.getTargetAnchor(); + org.framed.iorm.model.ModelElement sourceConnection = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor); + org.framed.iorm.model.ModelElement targetConnection = ConnectionPatternUtil.getModelElementForAnchor(targetAnchor); + //Step 2 + Relation newInterRelationshipConstraint = OrmFactory.eINSTANCE.createRelation(); + newInterRelationshipConstraint.setType(type); + if(newInterRelationshipConstraint.eResource() != null) getDiagram().eResource().getContents().add(newInterRelationshipConstraint); + //Step 3 + newInterRelationshipConstraint.setContainer(sourceConnection.getContainer()); + sourceConnection.getContainer().getElements().add(newInterRelationshipConstraint); + newInterRelationshipConstraint.setSource(sourceConnection); + newInterRelationshipConstraint.setTarget(targetConnection); + //Step 4 + AddConnectionContext addContext = new AddConnectionContext(sourceAnchor, targetAnchor); + addContext.setNewObject(newInterRelationshipConstraint); + Connection newConnection = null; + if(aircp.canAdd(addContext)) newConnection = (Connection) aircp.add(addContext); + return newConnection; + } + + /** + * fetches the anchor used for the pictogram model for a given anchor that is used by a business model element + * of a inter relationship constraint uses + * <p> + * See {@link RelationshipPattern#add} for further informations. + * @param businessModelAnchor the anchor a business model element of a inter relationship constraint uses + * @return the equivalent anchor for the pictogram element of the inter relationship constraint + */ + protected Anchor getGraphicalAnchorForBusinessModelAnchor(Anchor businessModelAnchor) { + Connection connection = (Connection) businessModelAnchor.getParent(); + for(ConnectionDecorator connectionDecorator : connection.getConnectionDecorators()) { + if(PropertyUtil.isShape_IdValue(connectionDecorator, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR)) + return connectionDecorator.getAnchors().get(0); + } + return null; + } } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipExclusionConstraintPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipExclusionConstraintPattern.java new file mode 100644 index 0000000000000000000000000000000000000000..88ec693e1d29e7f64bbeea0728bfbdf8022131cf --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipExclusionConstraintPattern.java @@ -0,0 +1,121 @@ +package org.framed.iorm.ui.pattern.connections.interrelationship; + +import org.eclipse.graphiti.features.context.IAddContext; +import org.eclipse.graphiti.features.context.ICreateConnectionContext; +import org.eclipse.graphiti.mm.algorithms.Polygon; +import org.eclipse.graphiti.mm.algorithms.Polyline; +import org.eclipse.graphiti.mm.pictograms.Connection; +import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; +import org.framed.iorm.model.Relation; +import org.framed.iorm.model.Type; +import org.framed.iorm.ui.literals.IdentifierLiterals; +import org.framed.iorm.ui.literals.NameLiterals; +import org.framed.iorm.ui.util.PropertyUtil; + +/** + * This graphiti pattern is used to work with {@link Relation}s + * of the type {@link Type#RELATIONSHIP_EXCLUSION} in the editor. + * <p> + * It deals with the following aspects of exclusion inter relationship constraints:<br> + * (1) creating the constraints, especially their business object<br> + * (2) adding the constraints to the diagram, especially their pictogram elements<br> + * <p> + * It is a subclass of {@link AbstractInterRelationshipConstraintPattern} and several operations used here are implemented there. + * @author Kevin Kassin + */ +public class RelationshipExclusionConstraintPattern extends AbstractInterRelationshipConstraintPattern { + + /** + * the name of the feature gathered from {@link NameLiterals} + */ + private final String RELATIONSHIP_EXCLUSION_FEATURE_NAME = NameLiterals.RELATIONSHIP_EXCLUSION_FEATURE_NAME; + + /** + * the identifier for the icon of the create feature gathered from {@link IdentifierLiterals} + */ + private static final String IMG_ID_FEATURE_RELATIONSHIP_EXCLUSION = IdentifierLiterals.IMG_ID_FEATURE_RELATIONSHIP_EXCLUSION; + + /** + * Class constructor + */ + public RelationshipExclusionConstraintPattern() { + super(); + } + + /** + * get method for the features name + * @return the name of the feature + */ + @Override + public String getCreateName() { + return RELATIONSHIP_EXCLUSION_FEATURE_NAME; + } + + /** + * get method for the identifier of the icon for the create feature + * @return the id of the icon + */ + @Override + public String getCreateImageId() { + return IMG_ID_FEATURE_RELATIONSHIP_EXCLUSION; + } + + //add feature + //~~~~~~~~~~~ + /** + * uses the super types equivalent operation to calculate if the relationship exclusion can be added + */ + @Override + public boolean canAdd(IAddContext addContext) { + return canAddInterRelationshipConstraint(addContext, Type.RELATIONSHIP_EXCLUSION); + } + + /** + * adds the role equivalences to the pictogram diagram using the following steps: + * <p> + * Step 1: get anchors used to hook in the inter relationship constraint for the pictogram model<br> + * Step 2: create a connection shape and dashed polyline as its graphic algorithm<br> + * Step 3: create the connection decorators and their graphics algorithms<br> + * Step 4: link the pictogram elements and the business objects<br> + * <p> + * Step 1 and 2 are executed by the operation + * {@link AbstractInterRelationshipConstraintPattern#addConnectionForInterRelationshipConstraint}. + */ + @Override + public PictogramElement add(IAddContext addContext) { + Relation addedRoleImplication = (Relation) addContext.getNewObject(); + //Step 1 and 2 + Connection connection = addConnectionForInterRelationshipConstraint(addContext); + if(connection == null) return null; + //Step 3 + ConnectionDecorator connectionDecoratorTarget = + pictogramElementCreateService.createConnectionDecorator(connection, false, 1.0, true); + int points[] = new int[] { 0, ARROWHEAD_HEIGHT, //Point 1 + -1*ARROWHEAD_LENGTH, 0, //P2 + 0, -1*ARROWHEAD_HEIGHT };//P3 + Polyline polylineTarget = graphicAlgorithmService.createPolyline(connectionDecoratorTarget, points); + polylineTarget.setLineWidth(2); + polylineTarget.setForeground(manageColor(COLOR_CONNECTIONS)); + PropertyUtil.setShape_IdValue(connectionDecoratorTarget, SHAPE_ID_INTER_REL_CON); + ConnectionDecorator connectionDecoratorSource = + pictogramElementCreateService.createConnectionDecorator(connection, false, 0, true); + Polyline polylineSource = graphicAlgorithmService.createPolyline(connectionDecoratorSource, points); + polylineSource.setLineWidth(2); + polylineSource.setForeground(manageColor(COLOR_CONNECTIONS)); + PropertyUtil.setShape_IdValue(connectionDecoratorSource, SHAPE_ID_INTER_REL_CON); + //Step 4 + link(connection, addedRoleImplication); + return connection; + } + + //create feature + //~~~~~~~~~~~~~~ + /** + * uses the super types equivalent operation to create the relationship exclusion + */ + @Override + public Connection create(ICreateConnectionContext createContext) { + return super.createInterRelationshipConstraint(createContext, Type.RELATIONSHIP_EXCLUSION, this); + } +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipImplicationConstraintPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipImplicationConstraintPattern.java index 84f158e9cb2ba1b31cc0717c61701e7924654655..7da329d12e41cf9ca813dabb4db53155044c1517 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipImplicationConstraintPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/interrelationship/RelationshipImplicationConstraintPattern.java @@ -1,24 +1,28 @@ package org.framed.iorm.ui.pattern.connections.interrelationship; -import org.eclipse.graphiti.datatypes.ILocation; -import org.eclipse.graphiti.features.context.IAddConnectionContext; import org.eclipse.graphiti.features.context.IAddContext; import org.eclipse.graphiti.features.context.ICreateConnectionContext; import org.eclipse.graphiti.mm.algorithms.Polygon; -import org.eclipse.graphiti.mm.algorithms.Polyline; -import org.eclipse.graphiti.mm.algorithms.styles.LineStyle; -import org.eclipse.graphiti.mm.pictograms.Anchor; import org.eclipse.graphiti.mm.pictograms.Connection; import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.services.Graphiti; import org.framed.iorm.model.Relation; import org.framed.iorm.model.Type; import org.framed.iorm.ui.literals.IdentifierLiterals; import org.framed.iorm.ui.literals.NameLiterals; import org.framed.iorm.ui.util.PropertyUtil; -//TODO +/** + * This graphiti pattern is used to work with {@link Relation}s + * of the type {@link Type#RELATIONSHIP_IMPLICATION} in the editor. + * <p> + * It deals with the following aspects of implication inter relationship constraints:<br> + * (1) creating the constraints, especially their business object<br> + * (2) adding the constraints to the diagram, especially their pictogram elements<br> + * <p> + * It is a subclass of {@link AbstractInterRelationshipConstraintPattern} and several operations used here are implemented there. + * @author Kevin Kassin + */ public class RelationshipImplicationConstraintPattern extends AbstractInterRelationshipConstraintPattern { /** @@ -59,7 +63,7 @@ public class RelationshipImplicationConstraintPattern extends AbstractInterRelat //add feature //~~~~~~~~~~~ /** - * uses the super types equivalent operation to calculate if the relationship implications can be added + * uses the super types equivalent operation to calculate if the relationship implication can be added */ @Override public boolean canAdd(IAddContext addContext) { @@ -69,37 +73,21 @@ public class RelationshipImplicationConstraintPattern extends AbstractInterRelat /** * adds the role equivalences to the pictogram diagram using the following steps: * <p> - * Step 1: create a connection shape and dashed polyline as its graphic algorithm - * Step 2: create the connection decorators and arrowheads as their graphics algorithms - * Step 3: link the pictogram elements and the business objects + * Step 1: get anchors used to hook in the inter relationship constraint for the pictogram model<br> + * Step 2: create a connection shape and dashed polyline as its graphic algorithm<br> + * Step 3: create the connection decorator and an arrowhead as their graphics algorithms<br> + * Step 4: link the pictogram elements and the business objects<br> + * <p> + * Step 1 and 2 are executed by the operation + * {@link AbstractInterRelationshipConstraintPattern#addConnectionForInterRelationshipConstraint}. */ @Override public PictogramElement add(IAddContext addContext) { - IAddConnectionContext addConnectionContext = (IAddConnectionContext) addContext; - Relation addedRoleImplication = (Relation) addContext.getNewObject(); - //TEST - Connection sourceConnection = (Connection) addConnectionContext.getSourceAnchor().getParent(); - Connection targetConnection = (Connection) addConnectionContext.getTargetAnchor().getParent(); - Anchor graphicalSourceAnchor = null, - graphicalTargetAnchor = null; - for(ConnectionDecorator connectionDecorator : sourceConnection.getConnectionDecorators()) { - if(PropertyUtil.isShape_IdValue(connectionDecorator, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR)) - graphicalSourceAnchor = connectionDecorator.getAnchors().get(0); - } - for(ConnectionDecorator connectionDecorator : targetConnection.getConnectionDecorators()) { - if(PropertyUtil.isShape_IdValue(connectionDecorator, SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR)) - graphicalTargetAnchor = connectionDecorator.getAnchors().get(0); - } - if(graphicalSourceAnchor == null || graphicalTargetAnchor == null) return null; - //Step 1 - Connection connection = pictogramElementCreateService.createFreeFormConnection(getDiagram()); - connection.setStart(graphicalSourceAnchor); - connection.setEnd(graphicalTargetAnchor); - Polyline polyline = graphicAlgorithmService.createPolyline(connection); - polyline.setForeground(manageColor(COLOR_CONNECTIONS)); - polyline.setLineStyle(LineStyle.DASH); - polyline.setLineWidth(2); - //Step2 + Relation addedRoleImplication = (Relation) addContext.getNewObject(); + //Step 1 and 2 + Connection connection = addConnectionForInterRelationshipConstraint(addContext); + if(connection == null) return null; + //Step 3 ConnectionDecorator connectionDecorator; connectionDecorator = pictogramElementCreateService.createConnectionDecorator(connection, false, 1.0, true); int points[] = new int[] { -1*ARROWHEAD_LENGTH, ARROWHEAD_HEIGHT, //Point 1 @@ -109,7 +97,7 @@ public class RelationshipImplicationConstraintPattern extends AbstractInterRelat arrowhead.setForeground(manageColor(COLOR_CONNECTIONS)); arrowhead.setBackground(manageColor(COLOR_ARROWHEAD)); PropertyUtil.setShape_IdValue(connectionDecorator, SHAPE_ID_INTER_REL_CON); - //Step 3 + //Step 4 link(connection, addedRoleImplication); return connection; } @@ -117,7 +105,7 @@ public class RelationshipImplicationConstraintPattern extends AbstractInterRelat //create feature //~~~~~~~~~~~~~~ /** - * uses the super types equivalent operation to create the relationship implications + * uses the super types equivalent operation to create the relationship implication */ @Override public Connection create(ICreateConnectionContext createContext) { diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/intrarelationship/AbstractIntraRelationshipConstraintPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/intrarelationship/AbstractIntraRelationshipConstraintPattern.java index 0f0db74b58d66fe326db015f7f6fe33598851c86..f59089fe2001c044e8c4fd0e41b360eb12bdaf29 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/intrarelationship/AbstractIntraRelationshipConstraintPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/intrarelationship/AbstractIntraRelationshipConstraintPattern.java @@ -25,8 +25,8 @@ import org.framed.iorm.ui.util.PropertyUtil; /** * This is the abstract super class of the patterns for intra relationship contraints. It collects similiar operations - * of the patterns {@link AcyclicConstraintPattern}, {@link CyclicConstraintPattern}, {@link IrreflexiveConstraintPattern}, - * {@link ReflexiveConstraintPattern} and {@link TotalConstraintPattern}. + * and attributes of the patterns {@link AcyclicConstraintPattern}, {@link CyclicConstraintPattern}, + * {@link IrreflexiveConstraintPattern}, {@link ReflexiveConstraintPattern} and {@link TotalConstraintPattern}. * <p> * This is implemented as shape pattern instead of a connection pattern since its easier for the user to click on a relationship to * add a constraint. This would not be able if a connection pattern would be used. As a developer this solution is also preferred as @@ -176,6 +176,7 @@ public abstract class AbstractIntraRelationshipConstraintPattern extends FRaMEDS */ public Object[] createIntraRelationshipConstraint(ICreateContext createContext, Type type, AbstractIntraRelationshipConstraintPattern aircp) { Connection targetConnection = createContext.getTargetConnection(); + Relation targetRelation = (Relation) getBusinessObjectForPictogramElement(targetConnection); Anchor sourceAnchor = targetConnection.getStart(), targetAnchor = targetConnection.getEnd(); Relation newIntraRelCon = OrmFactory.eINSTANCE.createRelation(); @@ -185,7 +186,8 @@ public abstract class AbstractIntraRelationshipConstraintPattern extends FRaMEDS model.getElements().add(newIntraRelCon); newIntraRelCon.setContainer(model); newIntraRelCon.setSource(ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor)); - newIntraRelCon.setTarget(ConnectionPatternUtil.getModelElementForAnchor(targetAnchor)); + newIntraRelCon.setTarget(ConnectionPatternUtil.getModelElementForAnchor(targetAnchor)); + targetRelation.getReferencedRelation().add(newIntraRelCon); AddContext addContext = new AddContext(); addContext.setNewObject(newIntraRelCon); addContext.setTargetConnection(targetConnection); diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/AbstractRoleConstraintPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/AbstractRoleConstraintPattern.java index 0b2800c658ae16c781f545c1a24c911c0429feac..dae9a31aa39629c69bbcde6e5dad6a7a42228a52 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/AbstractRoleConstraintPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/AbstractRoleConstraintPattern.java @@ -16,7 +16,7 @@ import org.framed.iorm.ui.util.ConnectionPatternUtil; /** * This is the abstract super class of the patterns for role constraint. It collects similiar operations - * of the patterns {@link RoleImplicationPattern}, {@link RoleEquivalencePattern} and + * and attributes of the patterns {@link RoleImplicationPattern}, {@link RoleEquivalencePattern} and * {@link RoleProhibitionPattern}. * @author Kevin Kassin */ diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/RoleProhibitionPattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/RoleProhibitionPattern.java index 18cec74cdf46b32a5b360874213276ffaad875e2..75c335bc10e3493d75928f087136176355161af2 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/RoleProhibitionPattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/connections/roleconstraint/RoleProhibitionPattern.java @@ -96,21 +96,18 @@ public class RoleProhibitionPattern extends AbstractRoleConstraintPattern { polyline.setLineStyle(LineStyle.DASH); polyline.setLineWidth(2); //Step2 - ConnectionDecorator connectionDecoratorTarget; - connectionDecoratorTarget = pictogramElementCreateService.createConnectionDecorator(connection, false, 1.0, true); - int pointsTarget[] = new int[] { 0, ARROWHEAD_HEIGHT, //Point 1 + ConnectionDecorator connectionDecoratorTarget = + pictogramElementCreateService.createConnectionDecorator(connection, false, 1.0, true); + int points[] = new int[] { 0, ARROWHEAD_HEIGHT, //Point 1 -1*ARROWHEAD_LENGTH, 0, //P2 0, -1*ARROWHEAD_HEIGHT }; //P3 - Polyline polylineTarget = graphicAlgorithmService.createPolyline(connectionDecoratorTarget, pointsTarget); + Polyline polylineTarget = graphicAlgorithmService.createPolyline(connectionDecoratorTarget, points); polylineTarget.setLineWidth(2); polylineTarget.setForeground(manageColor(COLOR_CONNECTIONS)); PropertyUtil.setShape_IdValue(connectionDecoratorTarget, SHAPE_ID_ROLE_CONSTRAINT_DECORATOR); - ConnectionDecorator connectionDecoratorSource; - connectionDecoratorSource = pictogramElementCreateService.createConnectionDecorator(connection, false, 0, true); - int pointsSource[] = new int[] { 0, ARROWHEAD_HEIGHT, //Point 1 - -1*ARROWHEAD_LENGTH, 0, //P2 - 0, -1*ARROWHEAD_HEIGHT }; //P3 - Polyline polylineSource = graphicAlgorithmService.createPolyline(connectionDecoratorSource, pointsSource); + ConnectionDecorator connectionDecoratorSource = + pictogramElementCreateService.createConnectionDecorator(connection, false, 0, true); + Polyline polylineSource = graphicAlgorithmService.createPolyline(connectionDecoratorSource, points); polylineSource.setLineWidth(2); polylineSource.setForeground(manageColor(COLOR_CONNECTIONS)); PropertyUtil.setShape_IdValue(connectionDecoratorSource, SHAPE_ID_ROLE_CONSTRAINT_DECORATOR); diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/FRaMEDShapePattern.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/FRaMEDShapePattern.java index 932416574a577c4ae3aa6574258f8d282b155afa..ed95bebabd2d19566bced8e0b5ed11b9b1373ac9 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/FRaMEDShapePattern.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/pattern/shapes/FRaMEDShapePattern.java @@ -16,6 +16,7 @@ import org.eclipse.graphiti.pattern.AbstractPattern; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; +import org.framed.iorm.ui.providers.FeatureProvider; import org.framed.iorm.ui.util.ShapePatternUtil; /** @@ -106,7 +107,8 @@ public abstract class FRaMEDShapePattern extends AbstractPattern { for(Connection connection : connectionsToDelete) { DeleteContext connectionDeleteContext = new DeleteContext(connection); connectionDeleteContext.setMultiDeleteInfo(new MultiDeleteInfo(false, false, 0)); - IDeleteFeature deleteFeature = createDeleteFeature(connectionDeleteContext); + IDeleteFeature deleteFeature = + ((FeatureProvider) getFeatureProvider()).getDeleteFeatureAdditional(connectionDeleteContext); deleteFeature.delete(connectionDeleteContext); } } } } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/FeatureProvider.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/FeatureProvider.java index f6c6947031307c47f7d8e5fb6de762c6cb231d49..1e704e03dea0dd9a38a7a1c41bff4a109ad286ca 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/FeatureProvider.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/FeatureProvider.java @@ -20,6 +20,7 @@ import org.framed.iorm.ui.graphitifeatures.StepInFeature; import org.framed.iorm.ui.graphitifeatures.StepInNewTabFeature; import org.framed.iorm.ui.graphitifeatures.StepOutFeature; import org.framed.iorm.ui.pattern.connections.*; +import org.framed.iorm.ui.pattern.connections.interrelationship.RelationshipExclusionConstraintPattern; import org.framed.iorm.ui.pattern.connections.interrelationship.RelationshipImplicationConstraintPattern; import org.framed.iorm.ui.pattern.connections.intrarelationship.AbstractIntraRelationshipConstraintPattern; import org.framed.iorm.ui.pattern.connections.intrarelationship.AcyclicConstraintPattern; @@ -74,7 +75,7 @@ public class FeatureProvider extends DefaultFeatureProviderWithPatterns { addPattern(new ReflexiveConstraintPattern()); addPattern(new TotalConstraintPattern()); addConnectionPattern(new RelationshipImplicationConstraintPattern()); - //addConnectionPattern(new RelationshipProhibitionConstraintPattern()); + addConnectionPattern(new RelationshipExclusionConstraintPattern()); } /** diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java index 90b67921ba3124d769a34b2ebb6bde8cd4b676c1..865d5d15626278c14187dcfdef7178300e6e4ff1 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java @@ -62,7 +62,7 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{ REFLEXIVE_FEATURE_NAME = NameLiterals.REFLEXIVE_FEATURE_NAME, TOTAL_FEATURE_NAME = NameLiterals.TOTAL_FEATURE_NAME, RELATIONSHIP_IMPLICATION_FEATURE_NAME = NameLiterals.RELATIONSHIP_IMPLICATION_FEATURE_NAME, - RELATIONSHIP_PROHIBITION_FEATURE_NAME = NameLiterals.RELATIONSHIP_EXCLUSION_FEATURE_NAME; + RELATIONSHIP_EXCLUSION_FEATURE_NAME = NameLiterals.RELATIONSHIP_EXCLUSION_FEATURE_NAME; /** * the value for the property diagram kind to identify diagrams belonging to a group or compartment type gathered * from {@link IdentiferLiterals} @@ -133,7 +133,7 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{ createFeaturesToHideInTopLevelView.add(REFLEXIVE_FEATURE_NAME); createFeaturesToHideInTopLevelView.add(TOTAL_FEATURE_NAME); createFeaturesToHideInTopLevelView.add(RELATIONSHIP_IMPLICATION_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(RELATIONSHIP_PROHIBITION_FEATURE_NAME); + createFeaturesToHideInTopLevelView.add(RELATIONSHIP_EXCLUSION_FEATURE_NAME); //feature to hide in the compartment view createFeaturesToHideInCompartmentView.add(NATURALTYPE_FEATURE_NAME); createFeaturesToHideInCompartmentView.add(DATATYPE_FEATURE_NAME); diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/util/ConnectionPatternUtil.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/util/ConnectionPatternUtil.java index d54a593f1dfdd20d69bb51f58774312177386fab..a2e878d2a9852ece919f7e1a71cbe3f3f9a2f4c9 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/util/ConnectionPatternUtil.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/util/ConnectionPatternUtil.java @@ -1,6 +1,8 @@ package org.framed.iorm.ui.util; import org.eclipse.graphiti.mm.pictograms.Anchor; +import org.eclipse.graphiti.mm.pictograms.Connection; +import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; /** * This class offers several utility operations mostly used by the graphiti connection patterns. @@ -24,4 +26,13 @@ public class ConnectionPatternUtil { } return null; } + + //TODO + public static ConnectionDecorator getConnectionDecoratorByShapeId(Connection connection, String SHAPE_ID) { + for(ConnectionDecorator decorator : connection.getConnectionDecorators()) { + if(PropertyUtil.isShape_IdValue(decorator,SHAPE_ID)) + return decorator; + } + return null; + } }