/**
   * Attaches a coverage annotation model for the given editor if the editor can be annotated. Does
   * nothing if the model is already attached.
   *
   * @param editor Editor to attach a annotation model to
   */
  public static boolean attach(ITextEditor editor) {
    IDocumentProvider provider = editor.getDocumentProvider();
    IEditorInput input = editor.getEditorInput();

    if (provider != null && input instanceof FileEditorInput) {
      IAnnotationModel model = provider.getAnnotationModel(input);

      if (model instanceof IAnnotationModelExtension) {
        IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

        ColorAnnotationModel colormodel = (ColorAnnotationModel) modelex.getAnnotationModel(KEY);

        if (colormodel == null) {
          IFile file = ((FileEditorInput) input).getFile();
          IFeatureProject project = CorePlugin.getFeatureProject(file);
          if (project != null
              && project.getComposer() != null
              && project.getComposer().needColor()) {
            IDocument document = provider.getDocument(input);
            colormodel = new ColorAnnotationModel(document, file, project, editor);
            modelex.addAnnotationModel(KEY, colormodel);

            return true;
          }
        } else {
          colormodel.updateAnnotations(!editor.isDirty());
        }
      }
    }
    return false;
  }