Class Annotation


  • @OpenApiAll
    public class Annotation
    extends java.lang.Object
    Annotation is an 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, eg from OCL or some custom validation. Therefore many different 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 eg. in order to fix some problem in the model. Annotation are identified by kind, target, severity and actions - see equals() method for details.
    • Constructor Detail

      • 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,
                          java.util.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,
                          java.lang.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,
                          java.lang.String text,
                          java.util.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,
                          java.lang.String text,
                          java.util.List<? extends NMAction> actions,
                          @CheckForNull
                          java.lang.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,
                          java.lang.String kind,
                          java.lang.String text,
                          @CheckForNull
                          BaseElement target)
        Creates annotation object without actions. None of the can be null.
        Parameters:
        severity - - defines how important the annotation is, eg. 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:
        getSeverityLevels(com.nomagic.magicdraw.core.Project)
      • Annotation

        public Annotation​(EnumerationLiteral severity,
                          java.lang.String kind,
                          java.lang.String text,
                          @CheckForNull
                          BaseElement target,
                          java.util.List<? extends NMAction> actions)
        Creates annotation object with actions. None of them can be null.
        Parameters:
        severity - - defines how important the annotation is, eg. 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:
        getSeverityLevels(com.nomagic.magicdraw.core.Project)
      • Annotation

        public Annotation​(@CheckForNull
                          java.lang.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,
                          java.util.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
                          java.lang.Object target,
                          Constraint constraint,
                          java.util.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
                          java.lang.Object target,
                          Constraint constraint,
                          java.lang.String text,
                          java.util.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,
                          java.lang.String kind,
                          java.lang.String text,
                          java.lang.Object target)
        Creates annotation object without actions. None of the can be null.
        Parameters:
        severity - - defines how important the annotation is, eg. 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:
        getSeverityLevels(com.nomagic.magicdraw.core.Project)
      • Annotation

        public Annotation​(EnumerationLiteral severity,
                          java.lang.String kind,
                          java.lang.String text,
                          @CheckForNull
                          java.lang.Object target,
                          java.util.List<? extends NMAction> actions)
        Creates annotation object with actions. None of them can be null.
        Parameters:
        severity - - defines how important the annotation is, eg. 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:
        getSeverityLevels(com.nomagic.magicdraw.core.Project)
    • Method Detail

      • dispose

        public void dispose()
      • constructText

        protected java.lang.String constructText​(@CheckForNull
                                                 BaseElement target,
                                                 Constraint constraint)
      • setText

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

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

        public java.lang.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 java.lang.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 java.lang.String getText()
        Returns annotation message.
        Returns:
        annotation message
      • getToolTipText

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

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

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

        protected void setActions​(java.util.List<? extends NMAction> actions)
      • getPriority

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

        protected final void setPriority​(int priority)
      • getSeverityColor

        public java.awt.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​(java.awt.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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getParentObject

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

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

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

        public static java.util.List<EnumerationLiteral> getSeverityLevels​(Project project)
        An 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)
      • getPainters

        public java.util.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