Skip to content
Snippets Groups Projects
Commit 63a63f7c authored by Thomas's avatar Thomas
Browse files

Fixed the containsCompartment rule to check whether a model already

contains a CompartmentType. Fixes #10

This is actually used for RoleModels to guarantee that there can only be
one role model added, if the compartment type feature is disabled.
parent 3cb03f7a
No related branches found
No related tags found
No related merge requests found
//compartmentTypes
//If Compartment_Types is not set, then only one CompartmentType can be
//added in the top-level view (This will be named RoleModel).
Add CompartmentType (!Compartment_Types) when !InType(CompartmentType) and !ContainsCompartment();
Add CompartmentType (!Compartment_Types) when !InType(CompartmentType);
Create CompartmentType (!Compartment_Types) when !InType(CompartmentType) and !ContainsCompartment();
Direct_Edit CompartmentType (true) when true;
\ No newline at end of file
......@@ -4,13 +4,8 @@
<featureRule xsi:type="editpolicymodel:NotFeatureRule">
<rule xsi:type="editpolicymodel:IsFeature" featureName="Compartment_Types"/>
</featureRule>
<constraintRule xsi:type="editpolicymodel:AndConstraintRule">
<rules xsi:type="editpolicymodel:NotConstraintRule">
<constraintRule xsi:type="editpolicymodel:NotConstraintRule">
<rule xsi:type="editpolicymodel:InType" type="CompartmentType"/>
</rules>
<rules xsi:type="editpolicymodel:NotConstraintRule">
<rule xsi:type="editpolicymodel:ContainsCompartment"/>
</rules>
</constraintRule>
</policies>
<policies actionType="CompartmentType">
......
......@@ -194,8 +194,12 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern {
org.framed.iorm.model.Shape shape = (org.framed.iorm.model.Shape) addContext.getNewObject();
if (shape.getType() == Type.COMPARTMENT_TYPE) {
if (UIUtil.getLinkedModelForDiagram(getDiagram()) != null) {
System.out.println("getContainer():" + addContext.getTargetContainer()+".");
if (addContext.getTargetContainer() instanceof Diagram)
return EditPolicyService.getHandler(this.getDiagram()).canAdd(addContext, Type.COMPARTMENT_TYPE);
} } }
}
}
}
return false;
}
......@@ -371,6 +375,8 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern {
@Override
public boolean canCreate(ICreateContext createContext) {
if(UIUtil.getLinkedModelForDiagram(getDiagram()) != null) {
System.out.println("getContainer():" + createContext.getTargetContainer()+".");
if (createContext.getTargetContainer() instanceof Diagram)
return EditPolicyService.getHandler(getDiagram()).canCreate(createContext, this.modelType);
}
return false;
......@@ -451,7 +457,8 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern {
if (businessObjects.size() == 1) {
if (businessObjects.get(0) instanceof org.framed.iorm.model.Shape) {
org.framed.iorm.model.Shape shape = (org.framed.iorm.model.Shape) businessObjects.get(0);
if(shape.getType() == Type.COMPARTMENT_TYPE) return true;
if (shape.getType() == Type.COMPARTMENT_TYPE)
return true;
}
}
}
......
......@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
......@@ -225,11 +226,24 @@ public class ConstraintRuleVisitor {
}
if (container == null)
return false;
//TODO: this does not work, it only finds the enclosing compartment type if it exists, and is semantically equivalent to In(CompartmentType).
// Check if immediate container element contains another compartment type
EObject o = UIUtil.getBusinessObjectForPictogramElement(container);
if (!(o instanceof org.framed.iorm.model.Model))
return false;
org.framed.iorm.model.Model model = (org.framed.iorm.model.Model) o;
System.out.println("containsCompartmentVisitor: size()=" + model.getElements().size());
for (ModelElement e : model.getElements())
if (e.getType().equals(Type.COMPARTMENT_TYPE))
return true;
return false;
// TODO: this does not work, it only finds the enclosing compartment type if it
// exists, and is semantically equivalent to In(CompartmentType).
// travers Containers to find the compartment type.
Diagram compartmentDiagram = findContainerDiagramOfType(container, Type.COMPARTMENT_TYPE);
System.out.println("containsCompartmentVisitor: TEST: " + compartmentDiagram != null);
return compartmentDiagram != null;
// Diagram compartmentDiagram = findContainerDiagramOfType(container,
// Type.COMPARTMENT_TYPE);
// System.out.println("containsCompartmentVisitor: TEST: " + compartmentDiagram
// != null);
// return compartmentDiagram != null;
}
private boolean sourceEqualsTargetVisitor(SourceEqualsTarget rule) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment