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
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
acceptDiagram
(DiagramPresentationElement diagram) void
dispose()
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 Project
Get the project.void
init
(Project project, Constraint constraint) This is the first method that is invoked on the implementation of theValidationRule
interface.boolean
isElementInScope
(Element element) If DiagramValidator is to be used in passive validation, then model part to validate can be selected.boolean
needsRun()
Returns whether the validation rule needs to run.protected boolean
needsRun
(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 void
setNeedsRun
(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:ValidationRule
This is the first method that is invoked on the implementation of theValidationRule
interface. Implementation can initialize internal state if required.- Specified by:
init
in 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:ValidationRule
Run the validation.- Specified by:
run
in interfaceValidationRule
- Parameters:
project
- a project of the constraintconstraint
- a constraint object- Returns:
- set of
Annotation
objects
-
getAnnotations
ReturnAnnotation
object for eachElement
orPresentationElement
which 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 constructAnnotation
objects.- Returns:
- annotations targeting elements from the diagrams in scope
-
needsRun
public boolean needsRun()Description copied from interface:ValidationRule
Returns whether the validation rule needs to run.- Specified by:
needsRun
in 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:
dispose
in 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
-