Class Annotation

java.lang.Object
com.nomagic.magicdraw.annotation.Annotation

@OpenApiAll public class Annotation extends Object
Annotation is additional information about particular model element or symbol (target) or any other object. In contrast with annotation target, annotations are not stored in the project. They are rather computed in runtime. This additional information is paint text only: description (text) and short name (kind). Annotations can come from various sources, e.g. from OCL or some custom validation. Therefore, many annotations can be bound to the same target. Importance of each annotation is denoted by severity level. See AnnotationPriorityComparator for details. Annotations provide ready to use action which user can make e.g. in order to fix some problem in the model. Annotation are identified by kind, target, severity and actions - see equals() method for details.
  • Field Details

  • Constructor Details

    • Annotation

      public Annotation(@CheckForNull BaseElement target, Constraint constraint)
      Creates and initializes a new Annotation object from specified parameters. Actions list will be empty.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
    • Annotation

      public Annotation(@CheckForNull BaseElement target, Constraint constraint, List<? extends NMAction> actions)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
      actions - annotation actions, can be an empty list.
    • Annotation

      public Annotation(@CheckForNull BaseElement target, Constraint constraint, String text)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
      text - annotation text
    • Annotation

      public Annotation(@CheckForNull BaseElement target, Constraint constraint, String text, List<? extends NMAction> actions)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
      text - annotation text
      actions - annotation actions, can be an empty list.
    • Annotation

      public Annotation(@CheckForNull BaseElement target, Constraint constraint, String text, List<? extends NMAction> actions, @CheckForNull String kind)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
      text - annotation text
      actions - annotation actions, can be an empty list.
      kind - annotation kind (short annotation name)
    • Annotation

      public Annotation(EnumerationLiteral severity, String kind, String text, @CheckForNull BaseElement target)
      Creates annotation object without actions. None of the can be null.
      Parameters:
      severity - - defines how important the annotation is, e.g. it may influence the display order of annotation if there are many for the same element
      kind - short unique name
      text - message, detailed description of the problem. It may be displayed in tooltips, tables etc..
      target - model element or presentation element that annotation is assigned to.
      See Also:
    • Annotation

      public Annotation(EnumerationLiteral severity, String kind, String text, @CheckForNull BaseElement target, List<? extends NMAction> actions)
      Creates annotation object with actions. None of them can be null.
      Parameters:
      severity - - defines how important the annotation is, e.g. it may influence the display order of annotation if there are many for the same element
      kind - short unique name
      text - message, detailed description of the problem. It may be displayed in tooltips, tables etc..
      target - model element or presentation element that annotation is assigned to.
      actions - annotation actions, can be an empty list.
      See Also:
    • Annotation

      public Annotation(@CheckForNull Object target, Constraint constraint)
      Creates and initializes a new Annotation object from specified parameters. Actions list will be empty.
      Parameters:
      target - model element or presentation element that annotation is assigned to.
      constraint - constraint that is violated.
    • Annotation

      public Annotation(Constraint constraint)
      Creates and initializes a new Annotation object from specified parameters. Target is unspecified (null).
      Parameters:
      constraint - constraint that is violated.
    • Annotation

      public Annotation(Constraint constraint, List<? extends NMAction> actions)
      Creates and initializes a new Annotation object from specified parameters. Target is unspecified (null).
      Parameters:
      constraint - constraint that is violated.
      actions - annotation actions, can be an empty list.
    • Annotation

      public Annotation(@CheckForNull Object target, Constraint constraint, List<? extends NMAction> actions)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - model object that annotation is assigned to.
      constraint - constraint that is violated.
      actions - annotation actions, can be an empty list.
    • Annotation

      public Annotation(@CheckForNull Object target, Constraint constraint, String text, List<? extends NMAction> actions)
      Creates and initializes a new Annotation object from specified parameters.
      Parameters:
      target - object that annotation is assigned to.
      constraint - constraint that is violated.
      text - annotation text
      actions - annotation actions, can be an empty list.
    • Annotation

      public Annotation(EnumerationLiteral severity, String kind, String text, Object target)
      Creates annotation object without actions. None of the can be null.
      Parameters:
      severity - - defines how important the annotation is, e.g. it may influence the display order of annotation if there are many for the same element
      kind - short unique name
      text - message, detailed description of the problem. It may be displayed in tooltips, tables etc..
      target - object that annotation is assigned to.
      See Also:
    • Annotation

      public Annotation(EnumerationLiteral severity, String kind, String text, @CheckForNull Object target, List<? extends NMAction> actions)
      Creates annotation object with actions. None of them can be null.
      Parameters:
      severity - - defines how important the annotation is, e.g. it may influence the display order of annotation if there are many for the same element
      kind - short unique name
      text - message, detailed description of the problem. It may be displayed in tooltips, tables etc..
      target - object that annotation is assigned to.
      actions - annotation actions, can be an empty list.
      See Also:
  • Method Details

    • dispose

      public void dispose()
    • resolveSeverity

      @CheckForNull protected EnumerationLiteral resolveSeverity(Constraint constraint)
    • constructText

      protected String constructText(@CheckForNull BaseElement target, Constraint constraint)
    • setText

      public void setText(String text)
      Sets annotation text.
      Parameters:
      text - text to set.
    • initInternal

      protected void initInternal(List<? extends NMAction> actions)
      initializes actions, severity color/icon and scopes
    • getKind

      public String getKind()
      Returns annotation kind (short annotation name)
      Returns:
      annotation kind
    • getTarget

      @CheckForNull public BaseElement getTarget()
      Returns annotation target - the project entity to which the annotation is bound to. The method can return null if the annotation is bound to any other project but to a project entity.
      Returns:
      annotation target
    • getTargetObject

      @CheckForNull public Object getTargetObject()
      Returns an object to which the annotation is bound.
      Returns:
      target object.
    • getProject

      @CheckForNull public Project getProject()
      Gets project that annotation belongs to.
      Returns:
      Project or null if the project was already disposed.
    • getText

      public String getText()
      Returns annotation message.
      Returns:
      annotation message
    • getToolTipText

      public String getToolTipText()
      Returns annotation tool tip text.
      Returns:
      annotation tool tip text.
    • setToolTipText

      public void setToolTipText(@CheckForNull String toolTipText)
      Sets annotation tool tip text.
      Parameters:
      toolTipText - text to set.
    • getActions

      public List<? extends NMAction> getActions()
      Returns annotation actions.
      Returns:
      annotation actions
    • setActions

      protected void setActions(List<? extends NMAction> actions)
    • getSeverity

      public EnumerationLiteral getSeverity()
      Returns annotation severity level - one of the SeverityKind enumeration. Usually it's either an error, warning, info or debug level.
      Returns:
      annotation severity
      See Also:
    • getPriority

      public int getPriority()
      Returns:
      Priority of this annotation. Higher severity annotations have higher priority
    • setPriority

      protected final void setPriority(int priority)
    • getSeverityColor

      public Color getSeverityColor()
      Calculates severity level color. The color may be used to draw decorations around the shape.
      Returns:
      calculated severity level color
    • setSeverityColor

      public void setSeverityColor(Color severityColor)
      Set severity color, The color may be used to draw decorations around the shape.
      Parameters:
      severityColor - color
    • getSeverityImageIcon

      @CheckForNull public Image getSeverityImageIcon()
      Annotation icon by severity.
      Returns:
      Image element of stereotype applied to the severity level.
    • getConstraint

      @CheckForNull public Constraint getConstraint()
      Returns constraint that represents validation rule.
      Returns:
      constraint.
    • setSeverityIcon

      public void setSeverityIcon(Image severityIcon)
      Set annotation icon by severity
      Parameters:
      severityIcon - icon
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getParentObject

      @CheckForNull public Object getParentObject()
      Returns parent object.
      Returns:
      parent object.
    • setParentObject

      public void setParentObject(@CheckForNull Object parentObject)
      Sets parent object.
      Parameters:
      parentObject - new parent object.
    • getIcon

      @CheckForNull public static Icon getIcon(Annotation annotation)
      Returns icon of this annotation
      Parameters:
      annotation - annotation
      Returns:
      icon
    • getSeverityLevels

      public static List<EnumerationLiteral> getSeverityLevels(Project project)
      A utility method for accessing available in the project severity levels (they are mapped to Enumeration Literals).
      Parameters:
      project - an owner of Enumeration
      Returns:
      a list of EnumerationLiterals corresponding to severity levels. Literals are sorted by priority (first is highest)
    • getSeverityLevel

      @CheckForNull public static EnumerationLiteral getSeverityLevel(Project project, String name)
      Searches for a severity level with a given name in a project.
      Parameters:
      project - project
      name - severity name
      Returns:
      return severity level with a given name or null
      See Also:
    • getPainters

      public Collection<AnnotationPainter> getPainters()
      Returns:
      painters
    • addPainter

      public void addPainter(AnnotationPainter painter)
      Add painter
      Parameters:
      painter - painter
    • removePainter

      public void removePainter(AnnotationPainter painter)
      Remove painter
      Parameters:
      painter - painter