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:

  • MIModuleConfigurations
  • MIContainers
  • MIParameterValues
  • MIIdentifiables

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, like getName() of a container
  • setLabel(String) ()} - Changes the label
  • getText() - Returns the text of the annotation.
  • setText(String) ()} - Changes the text
  • isChangeable() - Returns true, if the annotation is changeable
  • delete() - 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.

Get a UserAnnotation of a container
// 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)

Create a new UserAnnotation
transaction {
    // We already have the container "cont"
    def anno = cont.userAnnotations.createAndAdd("MyAnno")
    anno.text = "My Text"
}

Create or get the existing UserAnnotation by label name
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.