Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

IModelComponent References in Annotation Attributes

Revision as of 07:15, 31 October 2011 by Anton.xored.com (Talk | contribs) (Scenario 1 - Creating new annotation attribute)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< To: Tigerstripe_APIs

Basics

When there is a need to reference IModelComponent(s) in the annotation attribute, Tigerstripe has a special facility to simplify the GUI creation for attribute editing.

Tigerstripe provides a standard dialog GUI for such cases. To indicate that your feature should be editable in this manner, contribute to the org.eclipse.tigerstripe.workbench.ui.base.modelReferenceEditor extension point.

For full examples, see org.eclipse.tigerstripe.annotation.example plugin, ReferencesExample annotation in it, and plugin.xml parts that mention it.

Scenario 1 - Creating new annotation attribute

We recommend using org.eclipse.tigerstripe.workbench.annotation.modelReference.ModelReference EClass to encapsulate the reference.

ModelReference benefits are:

  • automatic (de-)serialization of the reference into Tigerstripe URI
  • resolve() method, for convenience in the generator code

The bare minimum amount of work you need to do, is putting something like this in plugin.xml:

<extension point="org.eclipse.tigerstripe.workbench.ui.base.modelReferenceEditor">
  <editor
    annotationAttribute="entity"
    annotationClass="ReferencesExample"
    annotationPackage="http://eclipse.org/tigerstripe/examples/annotation">
    <visible interface="org.eclipse.tigerstripe.workbench.model.deprecated_.IManagedEntityArtifact" />
  </editor>
</extension>

This says:

The result is this:

Tigerstripe Annotation Select Entity.png

Scenario 2 - Using new GUI for the old string attribute

You have a string attribute in your annotation, and you don't want to change your annotation ecore model and generators.

This time, let attribute point to another entity's attribute.

You will need to subclass ModelReferenceCellEditor now, and provide the code for (de-)serialization.

<editor
  annotationAttribute="stringRefToAttribute"
  annotationClass="ReferencesExample"
  annotationPackage="http://eclipse.org/tigerstripe/examples/annotation"
  cellEditor="org.eclipse.tigerstripe.annotation.example.ui.BackwardsCompatibleCellEditor">
  <visible interface="org.eclipse.tigerstripe.workbench.model.deprecated_.IManagedEntityArtifact" />
  <visible interface="org.eclipse.tigerstripe.workbench.model.deprecated_.IField" />
  <valid interface="org.eclipse.tigerstripe.workbench.model.deprecated_.IField" />
</editor>
public class BackwardsCompatibleCellEditor extends ModelReferenceCellEditor {
  @Override
  protected IModelComponent[] valueToComponents(Object value) {
    if (value == null) {
      return NO_COMPONENTS;
    }
    // parse the string and return IModelComponents
  }
  @Override
  protected Object componentToValue(IModelComponent component) {
    final IField field = (IField)component;
    // convert field to model string
  }
}

Customization options

You can customize dialog title and message in plugin.xml (see extension point documentation for details). Also, ModelReferenceCellEditor provides multiple customization points in form of protected methods, which you can override.

Back to the top