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

#Commit 28.10 21:00

fully implemented the reconnection feature 
parent 44c3ef26
No related branches found
No related tags found
No related merge requests found
......@@ -2,16 +2,35 @@ package org.framed.iorm.ui.graphitifeatures;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IReconnectionContext;
import org.eclipse.graphiti.features.context.impl.CustomContext;
import org.eclipse.graphiti.features.context.impl.ReconnectionContext;
import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.DefaultReconnectionFeature;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;
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.ConnectionPatternUtil;
import org.framed.iorm.ui.util.GeneralUtil;
import org.framed.iorm.ui.util.PropertyUtil;
//TODO
public class FRaMEDReconnectFeature extends DefaultReconnectionFeature {
/**
* the identifier for a diagram of a stepped in compartment view gathered from
* {@link IdentifierLiterals}
*/
private static final String DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM = IdentifierLiterals.DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM;
/**
* the name of the edit relationship feature gathered from {@link NameLiterals}
*/
private final String EDIT_FULFILLMENT_FEATURE_NAME = NameLiterals.EDIT_FULFILLMENT_FEATURE_NAME;
//TODO
public FRaMEDReconnectFeature(IFeatureProvider featureProvider) {
super(featureProvider);
......@@ -25,6 +44,7 @@ public class FRaMEDReconnectFeature extends DefaultReconnectionFeature {
if(relation.getType() == Type.RELATIONSHIP) return canReconnectRelationship(context);
if(relation.getType() == Type.RELATIONSHIP_EXCLUSION ||
relation.getType() == Type.RELATIONSHIP_IMPLICATION) return canReconnectInterRelCon(context);
if(relation.getType() == Type.FULFILLMENT) return canReconnectFulfillment(context);
return false;
}
......@@ -60,4 +80,65 @@ public class FRaMEDReconnectFeature extends DefaultReconnectionFeature {
return false;
}
//TODO
private boolean canReconnectFulfillment(IReconnectionContext context) {
Anchor newAnchor = context.getNewAnchor();
org.framed.iorm.model.ModelElement newShape = ConnectionPatternUtil.getModelElementForAnchor(newAnchor);
if(newShape != null) {
if(context.getReconnectType() == ReconnectionContext.RECONNECT_SOURCE)
return newShape.getType() == Type.NATURAL_TYPE || newShape.getType() == Type.DATA_TYPE ||
newShape.getType() == Type.COMPARTMENT_TYPE ||
(newShape.getType() == Type.ROLE_TYPE && PropertyUtil.isDiagram_KindValue(getDiagram(), DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM));
else
return newShape.getType() == Type.COMPARTMENT_TYPE;
}
return false;
}
//TODO
@Override
public void postReconnect(IReconnectionContext context) {
//Step 1 TODO
changeSourceOrTargetOfRelation(context);
//Step 2 TODO
Connection connection = context.getConnection();
Relation relation = (Relation) getBusinessObjectForPictogramElement(connection);
//Option 1
if(relation.getType() == Type.RELATIONSHIP_EXCLUSION ||
relation.getType() == Type.RELATIONSHIP_IMPLICATION) {
Anchor graphicalNewAnchor = null;
graphicalNewAnchor = ConnectionPatternUtil.getGraphicalAnchorForBusinessModelAnchor(context.getNewAnchor());
if(graphicalNewAnchor == null) return;
if(context.getReconnectType() == ReconnectionContext.RECONNECT_SOURCE)
connection.setStart(graphicalNewAnchor);
else
connection.setEnd(graphicalNewAnchor);
}
//Option 2 TODO
if(relation.getType() == Type.FULFILLMENT) {
if(context.getReconnectType() == ReconnectionContext.RECONNECT_TARGET) {
changeSourceOrTargetOfRelation(context);
CustomContext customContext = new CustomContext();
PictogramElement[] pictogramElement = new PictogramElement[1];
pictogramElement[0] = connection;
customContext.setPictogramElements(pictogramElement);
ICustomFeature[] customFeatures = getFeatureProvider().getCustomFeatures(customContext);
EditFulfillmentFeature editFulfillmentFeature = (EditFulfillmentFeature) GeneralUtil
.findFeatureByName(customFeatures, EDIT_FULFILLMENT_FEATURE_NAME);
if (editFulfillmentFeature.canExecute(customContext))
editFulfillmentFeature.execute(customContext);
}
}
}
private void changeSourceOrTargetOfRelation(IReconnectionContext context) {
Connection connection = context.getConnection();
Relation relation = (Relation) getBusinessObjectForPictogramElement(connection);
Anchor newAnchor = context.getNewAnchor();
org.framed.iorm.model.ModelElement newShape = ConnectionPatternUtil.getModelElementForAnchor(newAnchor);
if(context.getReconnectType() == ReconnectionContext.RECONNECT_SOURCE)
relation.setSource(newShape);
else
relation.setTarget(newShape);
}
}
......@@ -224,9 +224,9 @@ public class FulfillmentPattern extends FRaMEDConnectionPattern {
Anchor sourceAnchor = createContext.getSourceAnchor();
org.framed.iorm.model.ModelElement sourceShape = ConnectionPatternUtil.getModelElementForAnchor(sourceAnchor);
if (sourceShape != null) {
if (sourceShape.getType() == Type.NATURAL_TYPE || sourceShape.getType() == Type.DATA_TYPE
|| sourceShape.getType() == Type.COMPARTMENT_TYPE
|| (sourceShape.getType() == Type.ROLE_TYPE && PropertyUtil.isDiagram_KindValue(getDiagram(), DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM)))
if (sourceShape.getType() == Type.NATURAL_TYPE || sourceShape.getType() == Type.DATA_TYPE ||
sourceShape.getType() == Type.COMPARTMENT_TYPE ||
(sourceShape.getType() == Type.ROLE_TYPE && PropertyUtil.isDiagram_KindValue(getDiagram(), DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM)))
return true;
}
return false;
......
......@@ -8,7 +8,6 @@ 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.util.IColorConstant;
import org.framed.iorm.model.OrmFactory;
import org.framed.iorm.model.Relation;
......@@ -17,8 +16,6 @@ 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
/**
* This is the abstract super class of the patterns for inter relationship contraints. It collects similiar operations
......@@ -84,8 +81,8 @@ public abstract class AbstractInterRelationshipConstraintPattern extends FRaMEDC
//Step 1
Anchor graphicalSourceAnchor = null,
graphicalTargetAnchor = null;
graphicalSourceAnchor = this.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getSourceAnchor());
graphicalTargetAnchor = this.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getTargetAnchor());
graphicalSourceAnchor = ConnectionPatternUtil.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getSourceAnchor());
graphicalTargetAnchor = ConnectionPatternUtil.getGraphicalAnchorForBusinessModelAnchor(addConnectionContext.getTargetAnchor());
if(graphicalSourceAnchor == null || graphicalTargetAnchor == null) return null;
//Step 2
Connection connection = pictogramElementCreateService.createFreeFormConnection(getDiagram());
......@@ -177,21 +174,4 @@ public abstract class AbstractInterRelationshipConstraintPattern extends FRaMEDC
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;
}
}
......@@ -3,6 +3,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;
import org.framed.iorm.ui.literals.IdentifierLiterals;
import org.framed.iorm.ui.pattern.connections.RelationshipPattern; //*import for javadoc link
/**
* This class offers several utility operations mostly used by the graphiti connection patterns.
......@@ -10,6 +12,8 @@ import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
*/
public class ConnectionPatternUtil {
static String SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR = IdentifierLiterals.SHAPE_ID_RELATIONSHIP_ANCHOR_DECORATOR;
/**
* helper method to get the {@link ModelElement} for a given anchor
* @param anchor the anchor that belongs to the model element to get
......@@ -35,4 +39,21 @@ public class ConnectionPatternUtil {
}
return null;
}
/**
* 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
*/
public static 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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment