Package com.nomagic.magicdraw.validation
Class DiagramValidator
java.lang.Object
com.nomagic.magicdraw.validation.DiagramValidator
- All Implemented Interfaces:
ValidationRule
- Direct Known Subclasses:
OpenedDiagramValidator
Rule to validate elements of diagrams by a given scope (all diagrams in project, only active diagrams or diagrams from a specific scope).
Rule is triggered after various diagram related events like changes in the owned symbols, switching the active diagram.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptDiagram(DiagramPresentationElement diagram) voiddispose()Unregisters all listeners that were registered and releases other resources.abstract Set<Annotation>getAnnotations(Project project, Constraint constraint) protected final Collection<DiagramPresentationElement>protected final Stream<DiagramPresentationElement>protected List<PresentationElement>getPresentationElements(Element element) protected List<PresentationElement>getPresentationElements(Element element, Collection<DiagramPresentationElement> diagrams) protected ProjectGet the project.voidinit(Project project, Constraint constraint) This is the first method that is invoked on the implementation of theValidationRuleinterface.booleanisElementInScope(Element element) If DiagramValidator is to be used in passive validation, then model part to validate can be selected.booleanneedsRun()Returns whether the validation rule needs to run.protected booleanneedsRun(PropertyChangeEvent event) Check if validator needs to re-run after given change event occurred.final Set<Annotation>run(Project project, Constraint constraint) Run the validation.protected voidsetNeedsRun(boolean run) Sets flag if this validator has to be re-run, meaning ifgetAnnotations(Project, Constraint)method should be called again.
-
Constructor Details
-
DiagramValidator
public DiagramValidator()
-
-
Method Details
-
init
Description copied from interface:ValidationRuleThis is the first method that is invoked on the implementation of theValidationRuleinterface. Implementation can initialize internal state if required.- Specified by:
initin interfaceValidationRule- Parameters:
project- a project of the constraintconstraint- a constraint object
-
needsRun
Check if validator needs to re-run after given change event occurred.- Parameters:
event- event occurred.- Returns:
- true need to validate.
-
run
Description copied from interface:ValidationRuleRun the validation.- Specified by:
runin interfaceValidationRule- Parameters:
project- a project of the constraintconstraint- a constraint object- Returns:
- set of
Annotationobjects
-
getAnnotations
ReturnAnnotationobject for eachElementorPresentationElementwhich should be annotated. Only the elements represented in diagrams returned bygetDiagrams()method should be analyzed.- Parameters:
project- currently active projectconstraint- a validation rule or a legend item. Use this element to constructAnnotationobjects.- Returns:
- annotations targeting elements from the diagrams in scope
-
needsRun
public boolean needsRun()Description copied from interface:ValidationRuleReturns whether the validation rule needs to run.- Specified by:
needsRunin interfaceValidationRule- Returns:
- true if validation rule needs to run, otherwise false
-
setNeedsRun
protected void setNeedsRun(boolean run) Sets flag if this validator has to be re-run, meaning ifgetAnnotations(Project, Constraint)method should be called again. Actual re-run is done by the validation engine.- Parameters:
run- true to mark validator for rerun
-
dispose
public void dispose()Unregisters all listeners that were registered and releases other resources.- Specified by:
disposein interfaceValidationRule
-
getProject
Get the project.- Returns:
- project
-
getDiagramsStream
- Returns:
- Stream of the same diagrams as returned by
getDiagrams()method. Convenience method.
-
getDiagrams
- Returns:
- collection of diagrams for which used elements annotations should be calculated in
getAnnotations(Project, Constraint)method.
-
acceptDiagram
- Returns:
- true if the diagram in scope should be returned by
getDiagrams()method
-
getPresentationElements
- Parameters:
element- element to get presentation elements for- Returns:
- presentation elements of the given element from all diagrams that are currently in scope
-
getPresentationElements
protected List<PresentationElement> getPresentationElements(Element element, Collection<DiagramPresentationElement> diagrams) - Parameters:
element- element to get presentation elements fordiagrams- diagrams of interest- Returns:
- presentation elements of the given element from given diagrams
-
isElementInScope
If DiagramValidator is to be used in passive validation, then model part to validate can be selected. So certain elements used in the diagram should be validated (they are in selected model scope) and certain should be ignored.Only annotate the element, or it's symbol if the element is in scope. Recommendation is to call this method for failing elements only as the last check, since many calls to this method might affect performance in certain scenarios
- Parameters:
element- element which is used in any of the diagrams in scope- Returns:
- true if the element is in the model scope for the current validation
-