diff --git a/org.framed.iorm.ui/core/rolemodel/RoleModel.ecl b/org.framed.iorm.ui/core/rolemodel/RoleModel.ecl index 9100a340b90a2f400e573f486721e17bcb993016..33fd10e30934288f6470a231b21e0a6e7298a007 100644 --- a/org.framed.iorm.ui/core/rolemodel/RoleModel.ecl +++ b/org.framed.iorm.ui/core/rolemodel/RoleModel.ecl @@ -1,7 +1,7 @@ //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 diff --git a/org.framed.iorm.ui/core/rolemodel/RoleModel.editpolicy b/org.framed.iorm.ui/core/rolemodel/RoleModel.editpolicy index 53f0552799863e6d3fe39f9d52168ff4458d5d7b..a86ad583522893a7ec672d39226cfa1dcc82c479 100644 --- a/org.framed.iorm.ui/core/rolemodel/RoleModel.editpolicy +++ b/org.framed.iorm.ui/core/rolemodel/RoleModel.editpolicy @@ -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"> - <rule xsi:type="editpolicymodel:InType" type="CompartmentType"/> - </rules> - <rules xsi:type="editpolicymodel:NotConstraintRule"> - <rule xsi:type="editpolicymodel:ContainsCompartment"/> - </rules> + <constraintRule xsi:type="editpolicymodel:NotConstraintRule"> + <rule xsi:type="editpolicymodel:InType" type="CompartmentType"/> </constraintRule> </policies> <policies actionType="CompartmentType"> diff --git a/org.framed.iorm.ui/core/rolemodel/RoleModelPattern.java b/org.framed.iorm.ui/core/rolemodel/RoleModelPattern.java index 6b86a48fed60de19b8ddcf72c94b4c8fd6a63ac4..17bc739a15a7e73c1b557b512bbf88892a194cd4 100644 --- a/org.framed.iorm.ui/core/rolemodel/RoleModelPattern.java +++ b/org.framed.iorm.ui/core/rolemodel/RoleModelPattern.java @@ -190,12 +190,16 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern { */ @Override public boolean canAdd(IAddContext addContext) { - if(addContext.getNewObject() instanceof org.framed.iorm.model.Shape) { + if (addContext.getNewObject() instanceof org.framed.iorm.model.Shape) { org.framed.iorm.model.Shape shape = (org.framed.iorm.model.Shape) addContext.getNewObject(); - if(shape.getType()==Type.COMPARTMENT_TYPE) { - if(UIUtil.getLinkedModelForDiagram(getDiagram()) != null) { - return EditPolicyService.getHandler(this.getDiagram()).canAdd(addContext, Type.COMPARTMENT_TYPE); - } } } + 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,7 +375,9 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern { @Override public boolean canCreate(ICreateContext createContext) { if(UIUtil.getLinkedModelForDiagram(getDiagram()) != null) { - return EditPolicyService.getHandler(getDiagram()).canCreate(createContext, this.modelType); + System.out.println("getContainer():" + createContext.getTargetContainer()+"."); + if (createContext.getTargetContainer() instanceof Diagram) + return EditPolicyService.getHandler(getDiagram()).canCreate(createContext, this.modelType); } return false; } @@ -446,12 +452,13 @@ public class RoleModelPattern extends FRaMEDShapePattern implements IPattern { @Override public boolean canLayout(ILayoutContext layoutContext) { PictogramElement element = layoutContext.getPictogramElement(); - if(element instanceof ContainerShape) { + if (element instanceof ContainerShape) { EList<EObject> businessObjects = element.getLink().getBusinessObjects(); - if(businessObjects.size()==1) { - if(businessObjects.get(0) instanceof org.framed.iorm.model.Shape) { + 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; } } } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java index 0532c402091b31378d014502c50c336a5382d4ee..a081a3b562df3994e00db482ca895bdf0118127a 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java @@ -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) {