Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
framed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rosi
framed
Commits
94358062
Commit
94358062
authored
Jun 5, 2018
by
Thomas
Browse files
Options
Downloads
Patches
Plain Diff
Refactored and Formated source file.
parent
ff81a42a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java
+107
-103
107 additions, 103 deletions
.../org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java
with
107 additions
and
103 deletions
org.framed.iorm.ui/src/org/framed/iorm/ui/editPolicy/ConstraintRuleVisitor.java
+
107
−
103
View file @
94358062
...
...
@@ -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
())
.
findFirs
t
()
;
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
.
isPresen
t
()
)
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment