public String getInformation(ITextViewer textViewer, IRegion subject) {
   if (fImplementation != null) {
     String s = fImplementation.getHoverInfo(textViewer, subject);
     if (s != null && s.trim().length() > 0) return s;
   }
   return null;
 }
  @Override
  public Object getHoverInfo2(ITextViewer textViewer, IRegion region) {
    // Overridden from ITextHoverExtension2. We try and return the richest help available; this
    // means trying to call getHoverInfo2() on any contributors, and falling back on getHoverInfo().
    lastReturnedHover = null;

    // Return any annotation info - i.e. errors and warnings.
    String annotationHover = super.getHoverInfo(textViewer, region);

    if (annotationHover != null) {
      return escapeHtmlEntities(annotationHover);
    }

    // Check through the contributed hover providers.
    for (ITextHover hoverContributer : hoverContributors) {
      if (hoverContributer instanceof ITextHoverExtension2) {
        Object hoverInfo =
            ((ITextHoverExtension2) hoverContributer).getHoverInfo2(textViewer, region);

        if (hoverInfo != null) {
          lastReturnedHover = hoverContributer;

          return hoverInfo;
        }
      } else {
        String hoverText = hoverContributer.getHoverInfo(textViewer, region);

        if (hoverText != null) {
          lastReturnedHover = hoverContributer;

          return hoverText;
        }
      }
    }

    // Check for a dartdoc contribution.
    return getDartDocHover(region);
  }
示例#3
0
    /**
     * Tries to make a text hover focusable (or "sticky").
     *
     * @param sourceViewer the source viewer to display the hover over
     * @param textHover the hover to make focusable
     * @return <code>true</code> if successful, <code>false</code> otherwise
     */
    @SuppressWarnings("deprecation")
    private boolean makeTextHoverFocusable(ISourceViewer sourceViewer, ITextHover textHover) {
      Point hoverEventLocation = ((ITextViewerExtension2) sourceViewer).getHoverEventLocation();
      int offset =
          computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
      if (offset == -1) return false;

      try {
        IRegion hoverRegion = textHover.getHoverRegion(sourceViewer, offset);
        if (hoverRegion == null) return false;

        String hoverInfo = textHover.getHoverInfo(sourceViewer, hoverRegion);

        IInformationControlCreator controlCreator = null;
        if (textHover instanceof IInformationProviderExtension2)
          controlCreator =
              ((IInformationProviderExtension2) textHover).getInformationPresenterControlCreator();

        IInformationProvider informationProvider =
            new InformationProvider(hoverRegion, hoverInfo, controlCreator);

        fInformationPresenter.setOffset(offset);
        fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
        fInformationPresenter.setMargins(
            6, 6); // default values from AbstractInformationControlManager
        String contentType =
            TextUtilities.getContentType(
                sourceViewer.getDocument(), AutoconfPartitionScanner.AUTOCONF_MACRO, offset, true);
        fInformationPresenter.setInformationProvider(informationProvider, contentType);
        fInformationPresenter.showInformation();

        return true;

      } catch (BadLocationException e) {
        return false;
      }
    }
  @SuppressWarnings("deprecation")
  @Override
  public String getHoverInfo(ITextViewer textViewer, IRegion region) {
    // Return any annotation info - i.e. errors and warnings.
    String annotationHover = super.getHoverInfo(textViewer, region);

    if (annotationHover != null) {
      return escapeHtmlEntities(annotationHover);
    }

    // Check through the contributed hover providers.
    for (ITextHover hoverContributer : hoverContributors) {
      String hoverText = hoverContributer.getHoverInfo(textViewer, region);

      if (hoverText != null) {
        lastReturnedHover = hoverContributer;

        return hoverText;
      }
    }

    // Check for a dartdoc contribution.
    return getDartDocHover(region);
  }