Interface ModelingRules
public interface ModelingRules
Encapsulates model rules. Model rules are used to veto certain actions and
can function as a helper for the MVC-controller of Modeling Tool. The rules
can also overrule what types of symbols and relations that can be placed
in a model.
Note that multiple rules can be in place at the same time and that all rules will be consulted before performing a certain action. Implementations must keep this in mind when determining if an action is allowed or not. For example if the implementation's intention is to only govern a certain set of
Note that multiple rules can be in place at the same time and that all rules will be consulted before performing a certain action. Implementations must keep this in mind when determining if an action is allowed or not. For example if the implementation's intention is to only govern a certain set of
ModelType
s, it should return true for all actions that are done
towards other ModelType
s.- Author:
- Per-Erik
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The result returned from rule methods. -
Method Summary
Modifier and TypeMethodDescriptionaccept
(MTCompleteModel model, MTSymbol symbol) Returns true if thisModelingRules
accepts that a given symbol is added to a given model.accept
(MTCompleteModel model, EdgeType edgeType, MTCompleteVertex from, MTCompleteVertex to) Returns true if thisModelRules
accept that an edge of type edgeType is placed between two vertices in a model.
NOTE: This method can be seen as providing further filtering on edge type recommendations.acceptCopiesOf
(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns an ok result if the model accepts adding copies of vertices and edges from another model.acceptMakingCopiesOf
(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns an ok result if is accepted to make copies of vertices and edges from the model.acceptRelation
(ModelType modelType, EdgeType edgeType) Returns true if thisModelRules
accept thatMTCompleteEdge
s of type edgeType is placed inMTCompleteModel
s of modelType.acceptSymbol
(ModelType modelType, SymbolType symbolType) Returns true if thisModelRules
accept that symbols of type symbolType is placed inMTCompleteModel
s of modelType.acceptTypeChange
(MTModelHeader model, ModelType newType) Returns an OK result if these rules accept changing the type of a model.acceptTypeChange
(SymbolVariant newVariant, MTCompleteVertex toChangeVariantOf) Returns true if thisModelRules
accept that the symbol of the vertextoChangeTypeOf
changes variant tonewVariant
.boolean
Returns true if these rules apply to a model of a given type, otherwise everything is assumed to be OK according to these rules in a model of this type.canRemove
(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns true if everything in bothvertices
andedges
can be removed frommodel
, false otherwise.default void
modifyRemovedContent
(Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Lets the rules modify the content being removed when the user selects vertices/edges and tries to remove them
-
Method Details
-
applyTo
Returns true if these rules apply to a model of a given type, otherwise everything is assumed to be OK according to these rules in a model of this type. -
acceptMakingCopiesOf
ModelingRules.Result acceptMakingCopiesOf(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns an ok result if is accepted to make copies of vertices and edges from the model. This can be used to block copying of content that you know should not be allowed to be pasted anywhere else, and show the user a message explaining why.- Parameters:
model
- The source model.vertices
- The vertices being copied.edges
- The edges being copied.- Returns:
- An ok result if making copies is allowed.
-
acceptCopiesOf
ModelingRules.Result acceptCopiesOf(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns an ok result if the model accepts adding copies of vertices and edges from another model. The edges added are always edges between two of the vertices invertices
.model
is the model the content will be added to. You should not usevertex.getModel()
,vertex.getInEdges()
orvertex.getOutEdges()
to determine validity, unless the state of the source model is somehow involved in determining if content can be added. NOTE: When copies are added, the other accept methods will not be called, it is up to this implementation to decide if it is OK.- Parameters:
model
- The source model.vertices
- The vertices being copied.edges
- The edges being copied.- Returns:
- An ok result if the content can be copied to
model
.
-
canRemove
ModelingRules.Result canRemove(MTCompleteModel model, Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Returns true if everything in bothvertices
andedges
can be removed frommodel
, false otherwise.- Parameters:
model
- The model to remove fromvertices
- The vertices to removeedges
- The edges to remove- Returns:
- An ok result if everything in both
vertices
andedges
can be removed frommodel
, false otherwise.
-
acceptSymbol
Returns true if thisModelRules
accept that symbols of type symbolType is placed inMTCompleteModel
s of modelType.- Parameters:
modelType
- AModelType
in wich symbols of the givenSymbolType
can be placed or not.symbolType
- TheSymbolType
to accept.- Returns:
- An ok result if this
ModelRules
accept that symbols of typesymbolType
is placed inMTCompleteModel
s of modelType.
-
accept
Returns true if thisModelingRules
accepts that a given symbol is added to a given model.- Parameters:
model
- The model.symbol
- The symbol being added.- Returns:
- An ok result if adding the symbol is ok.
-
acceptRelation
Returns true if thisModelRules
accept thatMTCompleteEdge
s of type edgeType is placed inMTCompleteModel
s of modelType.- Parameters:
modelType
- AModelType
in wich edges of the givenEdgeType
can be placed or not.edgeType
- TheEdgeType
to accept.- Returns:
- An ok result if this
ModelRules
accept thatEdge
s of type edgeType is placed inMTCompleteModel
s of modelType.
-
accept
ModelingRules.Result accept(MTCompleteModel model, EdgeType edgeType, MTCompleteVertex from, MTCompleteVertex to) Returns true if thisModelRules
accept that an edge of type edgeType is placed between two vertices in a model.
NOTE: This method can be seen as providing further filtering on edge type recommendations. NOTE: This method does not send a model type directly but as the class description says, all methods of this interface should return true unless they specifically want to prohibit a certain action. That is, implementors should be as allowing as possible and this is particularly true for this method.- Parameters:
model
- The model that the edge will be added to.edgeType
- TheEdgeType
to be placed.from
- The vertex that the edge will start from. The vertex is not necessarily part of the model if this is a paste operation, but it will be added if all vertices and edges are accepted.to
- The vertex that the edge will end at. The vertex is not necessarily part of the model if this is a paste operation, but it will be added if all vertices and edges are accepted.- Returns:
- An ok result if this
ModelRules
accept that an edge of type edgeType is placed between the two vertices.
-
acceptTypeChange
Returns true if thisModelRules
accept that the symbol of the vertextoChangeTypeOf
changes variant tonewVariant
. This method will be called for variant changes as well as type changes (where the type to change to will benewVariant.getType()
, and it is mandated that this method returns true when changing between variants in the same type. Thus, if the vertex's symbol is of the same type asnewVariant
, true must be returned. A way of achieving this is to alway include the linesif(toChangeTypeOf.getType().equals(newVariant.getType())) { return true; }
Parameter discussion: The reason that a vertex is sent and not the 'old'SymbolVariant
, is that some model rules need to check the vertex's relations to other vertices (it's out- and in edges) to be able to decide what variants the vertex's symbol can be of. Most rules though, will be likely to only check the variant oftoChangeVariantOf
and ignore other vertex properties.
An example where the vertex is needed:
Library of Alexandria
, is a vertex with a symbol of type "Library
"The Bible
, is a vertex with a symbol of type "Book
"has
, is an edge of type "Has a copy of
"contained in
, is an edge of type "Contained In
"
ModelRules
relating to the real world might deem the following ok
-----------------has-------- | | ∨ Library of Alexandria The Bible ∧ | | ------------contained in----
However, changing the type of "Library of Alexandria
" to a type of "Person
" might break the rule. (Books can't be contained in Persons.) Given a vertex, the model rule can traverse the vertex sub-graph and find that this is a breaking change. If only two variants where sent in, such decisions could not be made.- Parameters:
newVariant
- The variant that the symbol oftoChangeTypeOf
might get if this method returns true.toChangeVariantOf
- A vertex that has a symbol that the change might occur on if this method returns true. It is guaranteed that the model containingtoChangeTypeOf
will be of aModelType
that would return instances of thisModelRules
.- Returns:
- An ok result if this model rules accept that the symbol of
toChangeTypeOf
changes variant tonewVariant
and type tonewVariant.getType()
, false otherwise. Note that returning an ok result is no guarantee that the change will occur since the symbol might be part of other models that have other model rules. A non-ok result is however guaranteed to veto the change. Also note that returning a non-ok result when all types intoChangeTypeOf
are of the same type asnewType
is a provisional error. (This might be a non-error in future versions.)
-
acceptTypeChange
Returns an OK result if these rules accept changing the type of a model.- Parameters:
model
- The model to change type of.newType
- The type to change to.- Returns:
- An OK result if the type change is ok.
-
modifyRemovedContent
default void modifyRemovedContent(Collection<MTCompleteVertex> vertices, Collection<MTCompleteEdge> edges) Lets the rules modify the content being removed when the user selects vertices/edges and tries to remove them- Parameters:
vertices
- The vertices the user tries to remove, can be added to or removed fromedges
- The edges the user tries to remove, can be added to or removed from
-