@Override
    public void run() {

      ISourceViewer sourceViewer = getSourceViewer();
      if (sourceViewer == null) {
        fTextOperationAction.run();
        return;
      }

      if (sourceViewer instanceof ITextViewerExtension4) {
        ITextViewerExtension4 extension4 = (ITextViewerExtension4) sourceViewer;
        if (extension4.moveFocusToWidgetToken()) return;
      }

      if (sourceViewer instanceof ITextViewerExtension2) {
        // does a text hover exist?
        ITextHover textHover = ((ITextViewerExtension2) sourceViewer).getCurrentTextHover();
        if (textHover != null && makeTextHoverFocusable(sourceViewer, textHover)) return;
      }

      if (sourceViewer instanceof ISourceViewerExtension3) {
        // does an annotation hover exist?
        IAnnotationHover annotationHover =
            ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
        if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover))
          return;
      }

      // otherwise, just display the tooltip
      // fTextOperationAction.run();
    }
  @Override
  public void selected(final ITextViewer viewer, boolean smartToggle) {
    repairPresentation(viewer);
    fRememberedStyleRange = null;

    if (!insertCompletion() ^ smartToggle) {
      StyleRange range = createStyleRange(viewer);
      if (range == null) {
        return;
      }

      fRememberedStyleRange = range;

      if (viewer instanceof ITextViewerExtension4) {
        if (fTextPresentationListener == null) {
          fTextPresentationListener =
              new ITextPresentationListener() {
                @Override
                public void applyTextPresentation(TextPresentation textPresentation) {
                  fRememberedStyleRange = createStyleRange(viewer);
                  if (fRememberedStyleRange != null) {
                    textPresentation.mergeStyleRange(fRememberedStyleRange);
                  }
                }
              };
          ((ITextViewerExtension4) viewer).addTextPresentationListener(fTextPresentationListener);
        }
        repairPresentation(viewer);
      } else {
        updateStyle(viewer);
      }
    }
  }
 @Override
 public void unselected(ITextViewer viewer) {
   if (fTextPresentationListener != null) {
     ((ITextViewerExtension4) viewer).removeTextPresentationListener(fTextPresentationListener);
     fTextPresentationListener = null;
   }
   repairPresentation(viewer);
   fRememberedStyleRange = null;
 }
Example #4
0
  /**
   * Installs a document partitioner on the containing editor's document. This partitioner will
   * determine where contained editors should go.
   *
   * @param viewer
   */
  public void installPartitioner(ISourceViewer viewer) {
    FastPartitioner partitioner =
        new FastPartitioner(scanner, new String[] {ContainingEditorScanner.CONTAINED_EDITOR});
    partitioner.connect(doc);

    ((IDocumentExtension3) doc)
        .setDocumentPartitioner(ContainingEditorScanner.CONTAINED_EDITOR, partitioner);

    if (viewer instanceof ITextViewerExtension4) {
      ((ITextViewerExtension4) viewer).addTextPresentationListener(this);
    } else {
      EmbeddedCALPlugin.logWarning(
          "Cannot install Presentation Listener.  " + "The display may not update properly.",
          new RuntimeException());
    }
  }