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 ModelTypes, it should return true for all actions that are done towards other ModelTypes.
Author:
Per-Erik
  • Method Details

    • applyTo

      boolean applyTo(ModelType modelType)
      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

      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

      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 in vertices. model is the model the content will be added to. You should not use vertex.getModel(), vertex.getInEdges() or vertex.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

      Returns true if everything in both vertices and edges can be removed from model, false otherwise.
      Parameters:
      model - The model to remove from
      vertices - The vertices to remove
      edges - The edges to remove
      Returns:
      An ok result if everything in both vertices and edges can be removed from model, false otherwise.
    • acceptSymbol

      ModelingRules.Result acceptSymbol(ModelType modelType, SymbolType symbolType)
      Returns true if this ModelRules accept that symbols of type symbolType is placed in MTCompleteModels of modelType.
      Parameters:
      modelType - A ModelType in wich symbols of the given SymbolType can be placed or not.
      symbolType - The SymbolType to accept.
      Returns:
      An ok result if this ModelRules accept that symbols of type symbolType is placed in MTCompleteModels of modelType.
    • accept

      Returns true if this ModelingRules 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

      ModelingRules.Result acceptRelation(ModelType modelType, EdgeType edgeType)
      Returns true if this ModelRules accept that MTCompleteEdges of type edgeType is placed in MTCompleteModels of modelType.
      Parameters:
      modelType - A ModelType in wich edges of the given EdgeType can be placed or not.
      edgeType - The EdgeType to accept.
      Returns:
      An ok result if this ModelRules accept that Edges of type edgeType is placed in MTCompleteModels of modelType.
    • accept

      Returns true if this ModelRules 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 - The EdgeType 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

      ModelingRules.Result acceptTypeChange(SymbolVariant newVariant, MTCompleteVertex toChangeVariantOf)
      Returns true if this ModelRules accept that the symbol of the vertex toChangeTypeOf changes variant to newVariant. This method will be called for variant changes as well as type changes (where the type to change to will be newVariant.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 as newVariant, true must be returned. A way of achieving this is to alway include the lines
       
       if(toChangeTypeOf.getType().equals(newVariant.getType())) {
            return true;
       }
      as the first lines of the method.

      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 of toChangeVariantOf 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"
      Then any 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 of toChangeTypeOf 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 containing toChangeTypeOf will be of a ModelType that would return instances of this ModelRules.
      Returns:
      An ok result if this model rules accept that the symbol of toChangeTypeOf changes variant to newVariant and type to newVariant.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 in toChangeTypeOf are of the same type as newType is a provisional error. (This might be a non-error in future versions.)
    • acceptTypeChange

      ModelingRules.Result acceptTypeChange(MTModelHeader model, ModelType newType)
      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 from
      edges - The edges the user tries to remove, can be added to or removed from