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

Refactored and Formated source file.

parent ff81a42a
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,10 @@ import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.framed.iorm.model.Model;
import org.framed.iorm.model.ModelElement;
import org.framed.iorm.model.Type;
import org.framed.iorm.ui.UIUtil;
import org.framed.iorm.ui.exceptions.NoDiagramFoundException;
import org.framed.iorm.ui.exceptions.NoModelFoundException;
import org.framed.iorm.ui.references.AbstractGroupingFeatureReference;
import editpolicymodel.AndConstraintRule;
import editpolicymodel.ConstraintRule;
......@@ -32,10 +29,10 @@ import editpolicymodel.OrConstraintRule;
import editpolicymodel.SourceEqualsTarget;
import editpolicymodel.SourceEqualsTargetType;
import editpolicymodel.TrueConstraintRule;
import compartment.AddCompartmentTypeContext;
/**
* This class provides the rule-parse for the command-rules. Using VisitorPattern
* This class provides the rule-parse for the command-rules. Using
* VisitorPattern
*
* @author Christian Deussen
*
......@@ -60,10 +57,10 @@ public class ConstraintRuleVisitor {
this.diagram = diagram;
}
public Diagram getDiagramWithName(String name, Diagram rootDiagram)
{
public Diagram getDiagramWithName(String name, Diagram rootDiagram) {
Diagram containerDiagram = UIUtil.getContainerDiagramForAnyDiagram(rootDiagram);
if(containerDiagram == null) throw new NoDiagramFoundException();
if (containerDiagram == null)
throw new NoDiagramFoundException();
for (Shape shape : containerDiagram.getChildren()) {
if (shape instanceof Diagram) {
if (((Diagram) shape).getName().equals(name))
......@@ -72,6 +69,7 @@ public class ConstraintRuleVisitor {
}
return null;
}
/**
* dispatch abstract rule
*
......@@ -80,8 +78,7 @@ public class ConstraintRuleVisitor {
* @param rule
* @return Boolean
*/
public boolean checkRule(ConstraintRule rule)
{
public boolean checkRule(ConstraintRule rule) {
if (rule instanceof InCompartment) {
return isInCompartmentRuleVisitor((InCompartment) rule);
}
......@@ -127,7 +124,6 @@ public class ConstraintRuleVisitor {
return true;
}
private boolean isInCompartmentRuleVisitor(InCompartment rule) {
ContainerShape container = null;
if (this.context instanceof AddContext) {
......@@ -135,49 +131,56 @@ public class ConstraintRuleVisitor {
} else if (this.context instanceof CreateContext) {
container = ((CreateContext) this.context).getTargetContainer();
}
if (container==null) return false;
if (container == null)
return false;
// travers Containers to find the compartment type.
Diagram compartmentDiagram = findContainerDiagramOfType(container, Type.COMPARTMENT_TYPE);
return compartmentDiagram != null;
}
/**
* Returns the grouping reference (diagram kind) of the given container type, if it exists.
* Note: this method is cached for better performance.
* Returns the grouping reference (diagram kind) of the given container type, if
* it exists. Note: this method is cached for better performance.
*
* @param type the IORM::Type of the container element
* @param type
* the IORM::Type of the container element
* @return the string reference of the diagram kind of the given container type
*/
private String getGroupingReference(Type type) {
if (groupingFeatureCache.containsKey(type)) return groupingFeatureCache.get(type);
Optional<String> result= UIUtil.getGroupingFeatureReferences().stream()
.filter(a -> a.getModelType()==type) // rule.getType();
.map(a -> a.getDiagramKind())
.findFirst();
if (!result.isPresent()) return null;
if (groupingFeatureCache.containsKey(type))
return groupingFeatureCache.get(type);
Optional<String> result = UIUtil.getGroupingFeatureReferences().stream().filter(a -> a.getModelType() == type) // rule.getType();
.map(a -> a.getDiagramKind()).findFirst();
if (!result.isPresent())
return null;
groupingFeatureCache.put(type, result.get());
return result.get();
}
/**
* This method checks if the given container shape is a Diagram of the Diagram Kind of the given type.
* Otherwise, the method traverses the containers to find a suitable candidate, if any exists.
* This method checks if the given container shape is a Diagram of the Diagram
* Kind of the given type. Otherwise, the method traverses the containers to
* find a suitable candidate, if any exists.
*
* @param sourceShape the ContainerShape to investigate
* @param type the IORM::Type of the container to look for
* @return the diagram of the correct diagram kind or null if no corresponding diagram was not found.
* @param sourceShape
* the ContainerShape to investigate
* @param type
* the IORM::Type of the container to look for
* @return the diagram of the correct diagram kind or null if no corresponding
* diagram was not found.
*/
public Diagram findContainerDiagramOfType(ContainerShape sourceShape, Type type) {
String groupingReference = getGroupingReference(type);
while ((sourceShape!=null) &&
!((sourceShape instanceof Diagram) && (UIUtil.isDiagram_KindValue((Diagram) sourceShape, groupingReference)))) {
while ((sourceShape != null) && !((sourceShape instanceof Diagram)
&& (UIUtil.isDiagram_KindValue((Diagram) sourceShape, groupingReference)))) {
sourceShape = sourceShape.getContainer();
}
if (sourceShape == null)
return null;
if (sourceShape instanceof Diagram)
return (Diagram) sourceShape;
throw new IllegalStateException("Invariant violated! findDiagramOfType found a sourceShape that was not a Diagram.");
throw new IllegalStateException(
"Invariant violated! findDiagramOfType found a sourceShape that was not a Diagram.");
}
private boolean andRuleVisitor(AndConstraintRule rule) {
......@@ -260,7 +263,8 @@ public class ConstraintRuleVisitor {
Anchor targetAnchor = this.getTargetAnchorFromContext(this.context);
ModelElement target = UIUtil.getModelElementForAnchor(targetAnchor);
System.out.println("sourceEqualsTargetTypeVisitor comparison: " + source.getType().getLiteral() + " == " + target.getType().getLiteral());
System.out.println("sourceEqualsTargetTypeVisitor comparison: " + source.getType().getLiteral() + " == "
+ target.getType().getLiteral());
return target.getType().getLiteral().equals(source.getType().getLiteral());
} catch (Exception e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment