Additional Model API
User Annotations
In DaVinci Configurator the user can add AUTOSAR annotations to configuration elements. You can create, modify, read and delete these annotations like in the UI editors.
All sub types of MIHasAnnotation elements support annotations like:
MIModuleConfigurationsMIContainersMIParameterValuesMIIdentifiables
Although annotations are stored in the data model, their changeable state is independent of the configuration element changeable state. Annotations
can be added/changed/deleted on every existing configuration element with valid definition, except the project was opened in read-only mode.
The IUserAnnotation interface provide methods like:
getLabel()- Returns the label of the annotation, likegetName()of a containersetLabel(String)()} - Changes the labelgetText()- Returns the text of the annotation.setText(String)()} - Changes the textisChangeable()- Returnstrue, if the annotation is changeabledelete()- Deletes the annotation
Access User Annotations
The getUserAnnotations(MIHasAnnotation) method returns the IUserAnnotations for the model element. The returned
list provides additional methods defined in IUserAnnotationList.
// We already have the container "cont" or any other model element
def myContainer = cont
def annos = myContainer.userAnnotations // Retrieve the list of annotations
def anno = annos.byLabel("MyLabel") // Select the annotation with "MyLabel"
def text = anno.text // Get the Text
// Or short
text = myContainer.userAnnotations["MyLabel"].text
Creation and Modification of User Annotations
You can create new User Annotations with the methods:
createAndAdd(label)byLabelOrCreate(label)
transaction {
// We already have the container "cont"
def anno = cont.userAnnotations.createAndAdd("MyAnno")
anno.text = "My Text"
}
transaction {
// We already have the container "cont"
def anno = cont.userAnnotations.byLabelOrCreate("MyAnno")
anno.text = "My Text"
}
Notes
The IUserAnnotationList is updated, when the underlying model changes.
The IUserAnnotationList is read only list and does not permit any modify operations defined in java.util.List, but certain operations like
createAndAdd(String) will affect the list content. If you delete a contained IUserAnnotation the list will not be updated.