Package com.nomagic.magicdraw.annotation
Class Annotation
- java.lang.Object
-
- com.nomagic.magicdraw.annotation.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. SeeAnnotationPriorityComparator
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<? extends NMAction>
actions
private Constraint
constraint
static java.lang.String
DEBUG
static java.lang.String
ERROR
static java.lang.String
FATAL
static java.lang.String
INFO
private java.lang.String
kind
private java.util.Collection<AnnotationPainter>
painters
private java.lang.Object
parentObject
private int
priority
private EnumerationLiteral
severity
private java.awt.Color
severityColor
private Image
severityIcon
private java.lang.Object
targetObject
private java.lang.String
text
private java.lang.String
toolTipText
Annotation text adapted for tool tip.static java.lang.String
WARNING
-
Constructor Summary
Constructors Constructor Description Annotation(BaseElement target, Constraint constraint)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(BaseElement target, Constraint constraint, java.lang.String text)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(BaseElement target, Constraint constraint, java.lang.String text, java.util.List<? extends NMAction> actions)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(BaseElement target, Constraint constraint, java.lang.String text, java.util.List<? extends NMAction> actions, java.lang.String kind)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(BaseElement target, Constraint constraint, java.util.List<? extends NMAction> actions)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(Constraint constraint)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(Constraint constraint, java.util.List<? extends NMAction> actions)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(EnumerationLiteral severity, java.lang.String kind, java.lang.String text, BaseElement target)
Creates annotation object without actions.Annotation(EnumerationLiteral severity, java.lang.String kind, java.lang.String text, BaseElement target, java.util.List<? extends NMAction> actions)
Creates annotation object with actions.Annotation(EnumerationLiteral severity, java.lang.String kind, java.lang.String text, java.lang.Object target)
Creates annotation object without actions.Annotation(EnumerationLiteral severity, java.lang.String kind, java.lang.String text, java.lang.Object target, java.util.List<? extends NMAction> actions)
Creates annotation object with actions.Annotation(java.lang.Object target, Constraint constraint)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(java.lang.Object target, Constraint constraint, java.lang.String text, java.util.List<? extends NMAction> actions)
Creates and initializes a newAnnotation
object from specified parameters.Annotation(java.lang.Object target, Constraint constraint, java.util.List<? extends NMAction> actions)
Creates and initializes a newAnnotation
object from specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPainter(AnnotationPainter painter)
Add painterprivate static void
checkArguments(EnumerationLiteral severity, java.lang.String kind)
protected java.lang.String
constructText(BaseElement target, Constraint constraint)
void
dispose()
boolean
equals(java.lang.Object obj)
java.util.List<? extends NMAction>
getActions()
Returns annotation actions.Constraint
getConstraint()
Returns constraint that represents validation rule.static javax.swing.Icon
getIcon(Annotation annotation)
Returns icon of this annotationjava.lang.String
getKind()
Returns annotation kind (short annotation name)java.util.Collection<AnnotationPainter>
getPainters()
java.lang.Object
getParentObject()
Returns parent object.int
getPriority()
Project
getProject()
Gets project that annotation belongs to.EnumerationLiteral
getSeverity()
Returns annotation severity level - one of the SeverityKind enumeration.java.awt.Color
getSeverityColor()
Calculates severity level color.Image
getSeverityImageIcon()
Annotation icon by severity.static EnumerationLiteral
getSeverityLevel(Project project, java.lang.String name)
Searches for a severity level with a given name in a project.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).BaseElement
getTarget()
Returns annotation target - the project entity to which the annotation is bound to.java.lang.Object
getTargetObject()
Returns an object to which the annotation is bound.java.lang.String
getText()
Returns annotation message.java.lang.String
getToolTipText()
Returns annotation tool tip text.int
hashCode()
private void
init(java.lang.String text, java.util.List<? extends NMAction> actions)
protected void
initInternal(java.util.List<? extends NMAction> actions)
initializes actions, severity color/icon and scopesvoid
removePainter(AnnotationPainter painter)
Remove painterprotected EnumerationLiteral
resolveSeverity(Constraint constraint)
protected void
setActions(java.util.List<? extends NMAction> actions)
void
setParentObject(java.lang.Object parentObject)
Sets parent object.protected void
setPriority(int priority)
void
setSeverityColor(java.awt.Color severityColor)
Set severity color, The color may be used to draw decorations around the shape.void
setSeverityIcon(Image severityIcon)
Set annotation icon by severityvoid
setText(java.lang.String text)
Sets annotation text.void
setToolTipText(java.lang.String toolTipText)
Sets annotation tool tip text.
-
-
-
Field Detail
-
ERROR
public static final java.lang.String ERROR
- See Also:
- Constant Field Values
-
INFO
public static final java.lang.String INFO
- See Also:
- Constant Field Values
-
WARNING
public static final java.lang.String WARNING
- See Also:
- Constant Field Values
-
FATAL
public static final java.lang.String FATAL
- See Also:
- Constant Field Values
-
DEBUG
public static final java.lang.String DEBUG
- See Also:
- Constant Field Values
-
severity
private final EnumerationLiteral severity
-
priority
private int priority
-
severityColor
private java.awt.Color severityColor
-
severityIcon
private Image severityIcon
-
kind
private final java.lang.String kind
-
text
private java.lang.String text
-
toolTipText
private java.lang.String toolTipText
Annotation text adapted for tool tip.
-
targetObject
@CheckForNull private final java.lang.Object targetObject
-
actions
private java.util.List<? extends NMAction> actions
-
parentObject
@CheckForNull private java.lang.Object parentObject
-
constraint
private Constraint constraint
-
painters
private java.util.Collection<AnnotationPainter> painters
-
-
Constructor Detail
-
Annotation
public Annotation(@CheckForNull BaseElement target, Constraint constraint)
Creates and initializes a newAnnotation
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 newAnnotation
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 newAnnotation
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 newAnnotation
object from specified parameters.- Parameters:
target
- model element or presentation element that annotation is assigned to.constraint
- constraint that is violated.text
- annotation textactions
- 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 newAnnotation
object from specified parameters.- Parameters:
target
- model element or presentation element that annotation is assigned to.constraint
- constraint that is violated.text
- annotation textactions
- 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 elementkind
- short unique nametext
- 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 elementkind
- short unique nametext
- 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 newAnnotation
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 newAnnotation
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 newAnnotation
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 newAnnotation
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 newAnnotation
object from specified parameters.- Parameters:
target
- object that annotation is assigned to.constraint
- constraint that is violated.text
- annotation textactions
- 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 elementkind
- short unique nametext
- 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 elementkind
- short unique nametext
- 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()
-
resolveSeverity
@CheckForNull protected EnumerationLiteral resolveSeverity(Constraint constraint)
-
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.
-
init
private void init(java.lang.String text, java.util.List<? extends NMAction> actions)
-
checkArguments
private static void checkArguments(@CheckForNull EnumerationLiteral severity, java.lang.String kind)
-
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)
-
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:
getSeverityLevels(com.nomagic.magicdraw.core.Project)
-
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 classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.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)
-
getSeverityLevel
@CheckForNull public static EnumerationLiteral getSeverityLevel(Project project, java.lang.String name)
Searches for a severity level with a given name in a project.
-
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
-
-