Skip to content
Snippets Groups Projects
Commit a6329913 authored by Kevin Kassin's avatar Kevin Kassin
Browse files

#Commit 25.7 1:29

reimplemented first version of intra relationship constraints as
shapepattern
parent 0dbb7b93
No related branches found
No related tags found
No related merge requests found
Showing
with 158 additions and 119 deletions
......@@ -201,12 +201,17 @@ public class IdentifierLiterals {
public static final String SHAPE_ID_INHERITANCE_DECORATOR = "shape_inheritance_decorator";
/**
* identifiers used for the connection decoratos of the name and cardinalities of relationships
* identifiers used for the connection decorators of the name and cardinalities of relationships
*/
public static final String SHAPE_ID_RELATIONSHIP_NAME_DECORATOR = "shape_rst_name",
SHAPE_ID_RELATIONSHIP_SOURCE_CARDINALITY_DECORATOR = "shape_rst_source_cardinality",
SHAPE_ID_RELATIONSHIP_TARGET_CARDINALITY_DECORATOR = "shape_rst_target_cardinality";
/**
* identifier used for the connection decorators of the intra relationship constraints
*/
public static final String SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR = "shape_irc_name";
/**
* identifiers used for role types
* <p>
......
......@@ -4,23 +4,42 @@ import java.util.List;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.mm.algorithms.Text;
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.util.IColorConstant;
import org.framed.iorm.model.Model;
import org.framed.iorm.model.OrmFactory;
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.LayoutLiterals;
import org.framed.iorm.ui.pattern.shapes.FRaMEDShapePattern;
import org.framed.iorm.ui.util.ConnectionPatternUtil;
import org.framed.iorm.ui.util.DiagramUtil;
import org.framed.iorm.ui.util.PropertyUtil;
//TODO
public abstract class AbstractIntraRelationshipConstraintFeature extends FRaMEDConnectionPattern {
//TODO implemented as shapePattern since it should be clicked on a relationship
public abstract class AbstractIntraRelationshipConstraintFeature extends FRaMEDShapePattern {
/**
* the identifier for the icon of the create feature gathered from {@link IdentifierLiterals}
*/
private static final String IMG_ID_FEATURE_INTRARELATIONSHIP_CONSTRAINT = IdentifierLiterals.IMG_ID_FEATURE_INTRARELATIONSHIP_CONSTRAINT;
//TODO
protected static final String SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR = IdentifierLiterals.SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR;
/**
* the color values gathered from {@link LayoutLiterals}
*/
protected static final IColorConstant COLOR_CONNECTIONS = LayoutLiterals.COLOR_CONNECTIONS,
COLOR_TEXT = LayoutLiterals.COLOR_TEXT;
public AbstractIntraRelationshipConstraintFeature() {
super();
}
......@@ -35,92 +54,88 @@ public abstract class AbstractIntraRelationshipConstraintFeature extends FRaMEDC
return IMG_ID_FEATURE_INTRARELATIONSHIP_CONSTRAINT;
}
@Override
public boolean isMainBusinessObjectApplicable(Object mainBusinessObject) {
if(mainBusinessObject instanceof Relation) {
Relation relation = (Relation) mainBusinessObject;
if(relation.getType() == Type.ACYCLIC ||
relation.getType() == Type.CYCLIC ||
relation.getType() == Type.REFLEXIVE ||
relation.getType() == Type.IRREFLEXIVE ||
relation.getType() == Type.TOTAL)
return true;
}
return false;
}
@Override
protected boolean isPatternControlled(PictogramElement pictogramElement) {
return isMainBusinessObjectApplicable(this.getBusinessObjectForPictogramElement(pictogramElement));
}
@Override
protected boolean isPatternRoot(PictogramElement pictogramElement) {
return isMainBusinessObjectApplicable(this.getBusinessObjectForPictogramElement(pictogramElement));
}
//add feature
//~~~~~~~~~~~
//TODO
public boolean canAddIntraRelationshipConstraint(IAddContext addContext, Type type) {
if(addContext.getNewObject() instanceof Relation) {
Relation relation = (Relation) addContext.getNewObject();
if(relation.getType() == type)
if(relation.getType() == type) {
return true;
}
} }
return false;
}
//TODO
public PictogramElement addIntraRelationshipConstraint(IAddContext addContext, Type type) {
Connection targetConnection = addContext.getTargetConnection();
ConnectionDecorator constraintName =
pictogramElementCreateService.createConnectionDecorator(targetConnection, true, 0.5, true);
Text nameText = graphicAlgorithmService.createText(constraintName, type.getName().toLowerCase());
nameText.setForeground(manageColor(COLOR_TEXT));
PropertyUtil.setShape_IdValue(constraintName, SHAPE_ID_INTRA_REL_CON_NAME_DECORATOR);
link(constraintName, addContext.getNewObject());
return constraintName;
}
//create feature
//~~~~~~~~~~~~~~
/**
* calculates if a intra relationship constraint can be created
* <p>
* returns true if<br>
* (1) target and source shape are not null and<br>
* (2) target and source shape is of valid type and<br>
* (3) source shapes container and targets shapes container are the same and<br>
* (4) the source shape is not equals the target shape and<br>
* (5) target and source shape are of the same type
* TODO
* @return if inheritance can be added
*/
//TODO auftrennen, bersichtlicher
public boolean canCreate(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
if(sourceShape != null && targetShape != null) {
if(sourceShape.getContainer() == targetShape.getContainer() &&
!(sourceShape.equals(targetShape))) {
if(sourceShape.getType() == Type.ROLE_TYPE &&
targetShape.getType() == sourceShape.getType()) {
List<Relation> commonRelationships =
ConnectionPatternUtil.getRelationsBetweenClassesOrRoles(sourceShape, targetShape, Type.RELATIONSHIP);
if(commonRelationships.size() == 1)
return true;
} } }
return false;
}
/**
* checks if a intra relationship constraint can be started from a given source shape
* <p>
* returns true if<br>
* (1) source shape is not null and<br>
* (2) source shape is of valid type and<br>
* (3) source shape has at least one relationship
* @return if a intra relationship constraint can be started
*/
@Override
public boolean canStartConnection(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
if(sourceShape != null){
if(sourceShape.getType() == Type.ROLE_TYPE) {
List<Relation> relationships =
ConnectionPatternUtil.getRelationForClassOrRole(sourceShape, Type.RELATIONSHIP);
if(relationships.size() >0) return true;
} }
public boolean canCreate(ICreateContext createContext) {
Connection targetConnection = createContext.getTargetConnection();
if(targetConnection != null &&
getBusinessObjectForPictogramElement(targetConnection) instanceof Relation) {
Relation relation = (Relation) getBusinessObjectForPictogramElement(targetConnection);
return (relation.getType() == Type.RELATIONSHIP);
}
return false;
}
public Connection createIntraRelationshipConstraint(ICreateConnectionContext createContext, Type type) {
//Step 1
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
//Step 2
public Object[] createIntraRelationshipConstraint(ICreateContext createContext, Type type) {
Connection targetConnection = createContext.getTargetConnection();
Anchor sourceAnchor = targetConnection.getStart(),
targetAnchor = targetConnection.getEnd();
//Step 1...
Relation newIntraRelCon = OrmFactory.eINSTANCE.createRelation();
newIntraRelCon.setType(type);
Model model = DiagramUtil.getLinkedModelForDiagram(getDiagram());
if(newIntraRelCon.eResource() != null) getDiagram().eResource().getContents().add(newIntraRelCon);
//Step 3
newIntraRelCon.setContainer(sourceShape.getContainer());
sourceShape.getContainer().getElements().add(newIntraRelCon);
newIntraRelCon.setSource(sourceShape);
newIntraRelCon.setTarget(targetShape);
//Step 4
AddConnectionContext addContext = new AddConnectionContext(sourceAnchor, targetAnchor);
addContext.setNewObject(newIntraRelCon);
Connection newConnection = null;
//if(canAdd(addContext)) newConnection = (Connection) add(addContext);
return newConnection;
model.getElements().add(newIntraRelCon);
newIntraRelCon.setContainer(model);
newIntraRelCon.setSource(ConnectionPatternUtil.getShapeForAnchor(sourceAnchor));
newIntraRelCon.setTarget(ConnectionPatternUtil.getShapeForAnchor(targetAnchor));
addGraphicalRepresentation(createContext, newIntraRelCon);
return new Object[] { newIntraRelCon };
}
}
......@@ -9,6 +9,7 @@ import org.framed.iorm.model.OrmFactory;
import org.framed.iorm.model.Relation;
import org.framed.iorm.model.Type;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.util.ConnectionPatternUtil;
/**
* This is the abstract sub class of the pattern for role constraint. It collects similiar operations
......@@ -61,8 +62,8 @@ public abstract class AbstractRoleConstraintPattern extends FRaMEDConnectionPatt
public boolean canCreate(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
if(sourceShape != null && targetShape != null) {
if(sourceShape.getContainer() == targetShape.getContainer() &&
!(sourceShape.equals(targetShape))) {
......@@ -84,7 +85,7 @@ public abstract class AbstractRoleConstraintPattern extends FRaMEDConnectionPatt
@Override
public boolean canStartConnection(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
if(sourceShape != null){
if(sourceShape.getType() == Type.ROLE_TYPE)
return true;
......@@ -106,8 +107,8 @@ public abstract class AbstractRoleConstraintPattern extends FRaMEDConnectionPatt
//Step 1
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
//Step 2
Relation newRoleConstraint = OrmFactory.eINSTANCE.createRelation();
newRoleConstraint.setType(type);
......
......@@ -2,13 +2,10 @@ package org.framed.iorm.ui.pattern.connections;
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.pictograms.Anchor;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.framed.iorm.model.OrmFactory;
import org.framed.iorm.model.Relation;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.framed.iorm.model.Type;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.literals.NameLiterals;
//TODO
......@@ -42,13 +39,15 @@ public class CyclicConstraintPattern extends AbstractIntraRelationshipConstraint
return canAddIntraRelationshipConstraint(addContext, Type.CYCLIC);
}
@Override
public PictogramElement add(IAddContext addContext) {
return addIntraRelationshipConstraint(addContext, Type.CYCLIC);
}
//create feature
//~~~~~~~~~~~~~~
@Override
public Connection create(ICreateConnectionContext createContext) {
public Object[] create(ICreateContext createContext) {
return createIntraRelationshipConstraint(createContext, Type.CYCLIC);
}
}
package org.framed.iorm.ui.pattern.connections;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.pattern.AbstractConnectionPattern;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.framed.iorm.model.Shape; //*import for javadoc link
/**
* This class is an abstract super class for the graphiti connection patterns.
......@@ -31,19 +29,4 @@ public class FRaMEDConnectionPattern extends AbstractConnectionPattern {
* the graphics algorithm service used to create graphics algorithms in the subclasses
*/
protected final IGaService graphicAlgorithmService = Graphiti.getGaService();
/**
* helper method to get the {@link Shape} for a given anchor
* @param anchor the anchor that belongs to the shape to get
* @return the shape that has the give anchor
*/
public org.framed.iorm.model.Shape getShapeForAnchor(Anchor anchor) {
Object object = null;
if (anchor != null) { object = getBusinessObjectForPictogramElement(anchor.getParent()); }
if (object != null) {
if (object instanceof org.framed.iorm.model.Shape)
return (org.framed.iorm.model.Shape) object;
}
return null;
}
}
......@@ -17,6 +17,7 @@ import org.framed.iorm.model.Type;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.literals.LayoutLiterals;
import org.framed.iorm.ui.literals.NameLiterals;
import org.framed.iorm.ui.util.ConnectionPatternUtil;
import org.framed.iorm.ui.util.PropertyUtil;
/**
......@@ -152,8 +153,8 @@ public class InheritancePattern extends FRaMEDConnectionPattern {
public boolean canCreate(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
if(sourceShape != null && targetShape != null) {
if(sourceShape.getContainer() == targetShape.getContainer() &&
!(sourceShape.equals(targetShape))) {
......@@ -178,7 +179,7 @@ public class InheritancePattern extends FRaMEDConnectionPattern {
@Override
public boolean canStartConnection(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
if(sourceShape != null){
if(sourceShape.getType() == Type.NATURAL_TYPE ||
sourceShape.getType() == Type.DATA_TYPE ||
......@@ -202,8 +203,8 @@ public class InheritancePattern extends FRaMEDConnectionPattern {
//Step 1
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
//Step 2
Relation newInheritance = OrmFactory.eINSTANCE.createRelation();
newInheritance.setType(Type.INHERITANCE);
......
......@@ -21,6 +21,7 @@ import org.framed.iorm.ui.graphitifeatures.EditRelationshipFeature;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.literals.LayoutLiterals;
import org.framed.iorm.ui.literals.NameLiterals;
import org.framed.iorm.ui.util.ConnectionPatternUtil;
import org.framed.iorm.ui.util.NameUtil;
import org.framed.iorm.ui.util.PropertyUtil;
......@@ -200,8 +201,8 @@ public class RelationshipPattern extends FRaMEDConnectionPattern {
public boolean canCreate(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
if(sourceShape != null && targetShape != null) {
if(sourceShape.getContainer() == targetShape.getContainer()) {
if(sourceShape.getType() == Type.ROLE_TYPE)
......@@ -222,7 +223,7 @@ public class RelationshipPattern extends FRaMEDConnectionPattern {
@Override
public boolean canStartConnection(ICreateConnectionContext createContext) {
Anchor sourceAnchor = createContext.getSourceAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
if(sourceShape != null){
if(sourceShape.getType() == Type.ROLE_TYPE)
return true;
......@@ -244,8 +245,8 @@ public class RelationshipPattern extends FRaMEDConnectionPattern {
//Step 1
Anchor sourceAnchor = createContext.getSourceAnchor();
Anchor targetAnchor = createContext.getTargetAnchor();
org.framed.iorm.model.Shape sourceShape = getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = getShapeForAnchor(targetAnchor);
org.framed.iorm.model.Shape sourceShape = ConnectionPatternUtil.getShapeForAnchor(sourceAnchor);
org.framed.iorm.model.Shape targetShape = ConnectionPatternUtil.getShapeForAnchor(targetAnchor);
//Step 2
Relation newRelationship = OrmFactory.eINSTANCE.createRelation();
......
......@@ -100,7 +100,7 @@ public class RoleEquivalencePattern extends AbstractRoleConstraintPattern {
@Override
public PictogramElement add(IAddContext addContext) {
IAddConnectionContext addConnectionContext = (IAddConnectionContext) addContext;
Relation addedInheritance = (Relation) addContext.getNewObject();
Relation addedRoleEquivalence = (Relation) addContext.getNewObject();
Anchor sourceAnchor = addConnectionContext.getSourceAnchor();
Anchor targetAnchor = addConnectionContext.getTargetAnchor();
//Step 1
......@@ -131,7 +131,7 @@ public class RoleEquivalencePattern extends AbstractRoleConstraintPattern {
arrowheadSource.setBackground(manageColor(COLOR_ARROWHEAD));
PropertyUtil.setShape_IdValue(connectionDecoratorSource, SHAPE_ID_ROLE_CONSTRAINT_DECORATOR);
//Step 3
link(connection, addedInheritance);
link(connection, addedRoleEquivalence);
return connection;
}
......
......@@ -100,7 +100,7 @@ public class RoleImplicationPattern extends AbstractRoleConstraintPattern {
@Override
public PictogramElement add(IAddContext addContext) {
IAddConnectionContext addConnectionContext = (IAddConnectionContext) addContext;
Relation addedInheritance = (Relation) addContext.getNewObject();
Relation addedRoleImplication = (Relation) addContext.getNewObject();
Anchor sourceAnchor = addConnectionContext.getSourceAnchor();
Anchor targetAnchor = addConnectionContext.getTargetAnchor();
//Step 1
......@@ -122,7 +122,7 @@ public class RoleImplicationPattern extends AbstractRoleConstraintPattern {
arrowhead.setBackground(manageColor(COLOR_ARROWHEAD));
PropertyUtil.setShape_IdValue(connectionDecorator, SHAPE_ID_ROLE_CONSTRAINT_DECORATOR);
//Step 3
link(connection, addedInheritance);
link(connection, addedRoleImplication);
return connection;
}
......
......@@ -97,7 +97,7 @@ public class RoleProhibitionPattern extends AbstractRoleConstraintPattern {
@Override
public PictogramElement add(IAddContext addContext) {
IAddConnectionContext addConnectionContext = (IAddConnectionContext) addContext;
Relation addedInheritance = (Relation) addContext.getNewObject();
Relation addedRoleProhibtion = (Relation) addContext.getNewObject();
Anchor sourceAnchor = addConnectionContext.getSourceAnchor();
Anchor targetAnchor = addConnectionContext.getTargetAnchor();
//Step 1
......@@ -128,7 +128,7 @@ public class RoleProhibitionPattern extends AbstractRoleConstraintPattern {
polylineSource.setForeground(manageColor(COLOR_CONNECTIONS));
PropertyUtil.setShape_IdValue(connectionDecoratorSource, SHAPE_ID_ROLE_CONSTRAINT_DECORATOR);
//Step 3
link(connection, addedInheritance);
link(connection, addedRoleProhibtion);
return connection;
}
......
......@@ -26,6 +26,7 @@ import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.FixPointAnchor;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.pattern.AbstractPattern;
......
......@@ -69,7 +69,7 @@ public class FeatureProvider extends DefaultFeatureProviderWithPatterns {
addConnectionPattern(new RoleImplicationPattern());
addConnectionPattern(new RoleEquivalencePattern());
addConnectionPattern(new RoleProhibitionPattern());
addConnectionPattern(new CyclicConstraintPattern());
addPattern(new CyclicConstraintPattern());
}
/**
......
......@@ -3,6 +3,10 @@ package org.framed.iorm.ui.util;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.IMappingProvider; //*import for javadoc link
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.framed.iorm.model.Relation;
import org.framed.iorm.model.Shape;
import org.framed.iorm.model.Type;
......@@ -31,4 +35,33 @@ public class ConnectionPatternUtil {
return commonRelations;
}
/**
* helper method to get the {@link Shape} for a given anchor
* @param anchor the anchor that belongs to the shape to get
* @return the shape that has the give anchor
*/
public static org.framed.iorm.model.Shape getShapeForAnchor(Anchor anchor) {
Object object = null;
if (anchor != null) { object = getBusinessObjectForPictogramElement(anchor.getParent()); }
if (object != null) {
if (object instanceof org.framed.iorm.model.Shape)
return (org.framed.iorm.model.Shape) object;
}
return null;
}
/**
* returns the first linked business object of a pictogram
* <p>
* This operation is build after method {@link IMappingProvider#getBusinessObjectForPictogramElement} to avoid
* a dependency.<br>
* This is a convenience method for getAllBusinessObjectsForPictogramElement(PictogramElement), because in many
* usecases only a single business object is linked.
* @param pictogramElement the pictogram element to get business object for
* @return the first business object of a pictogram element
*/
private static EObject getBusinessObjectForPictogramElement(PictogramElement pictogramElement) {
return pictogramElement.getLink().getBusinessObjects().get(0);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment