Jump to: navigation, search

Howto: Register Annotation EditPart Providers

Revision as of 07:47, 1 July 2008 by Yuri.xored.com (Talk | contribs)

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

< To: Tigerstripe_APIs

Annotation Framework provides own edit parts to show annotations on the GMF diagram. This parts can be customized by user. It can be done with the annotation edit part provider which map annotations to the specified edit parts:

 public interface IAnnotationEditPartProvider {
   public Class<? extends AnnotationEditPart> getAnnotationEditPartClass(Annotation annotation);
 }

This provider should be registered using org.eclipse.tigerstripe.annotation.ui.diagrams.annotationEditpartProviders extension point:

 <extension
     point="org.eclipse.tigerstripe.annotation.ui.diagrams.annotationEditpartProviders">
   <provider
       class="org.eclipse.tigerstripe.annotation.ui.example.editpartProvider.AnnotationEditPartProvider"
       id="org.eclipse.tigerstripe.annotation.ui.example.editpartProvider">
   </provider>
 </extension>

All annotation edit parts should extend org.eclipse.tigerstripe.annotation.ui.diagrams.parts.AnnotationEditPart class and will be automatically refreshed when annotation changed and so on. The simple example of the annotation edit part is following:

 public class SimpleAnnotationEditPart extends AnnotationEditPart {
   public SimpleAnnotationEditPart (View view) {
     super(view);
   }
   protected NodeFigure createNodeFigure() {
     BorderedNodeFigure figure = new BorderedNodeFigure(new Label());
     return figure;
   }
   protected void refreshVisuals() {
     BorderedNodeFigure figure = (BorderedNodeFigure)getFigure();
     Label label = (Label)figure.getMainFigure();
     Annotation annotation = getAnnotation();
     label.setText(DisplayAnnotationUtil.getText(annotation));
     label.setIcon(DisplayAnnotationUtil.getImage(annotation));
     super.refreshVisuals();
   }
 }

Annotation edit part can use getAnnotation() method to get annotation represented by this part. This part also free to use custom edit policies and other edit part features.