@SuppressWarnings("deprecation")
  private void doELTooltipTest(String prefix, String value, String compare) {
    String documentContent = caTest.getDocument().get();
    int start = (documentContent == null ? -1 : documentContent.indexOf(prefix));
    assertFalse("Required node '" + prefix + "' not found in document", (start == -1));
    int offsetToTest = start + prefix.length();

    ITextHover hover = getTextHover(caTest.getViewer(), offsetToTest - 1);
    assertNotNull("Hover not found for value: '" + value + "'", hover);

    String hoverText = null;
    if (hover instanceof ITextHoverExtension2) {
      Object hoverInfo2 =
          ((ITextHoverExtension2) hover)
              .getHoverInfo2(
                  caTest.getViewer(), hover.getHoverRegion(caTest.getViewer(), offsetToTest));
      hoverText = String.valueOf(hoverInfo2);
    } else {
      hoverText =
          ((ITextHover) hover)
              .getHoverInfo(
                  caTest.getViewer(), hover.getHoverRegion(caTest.getViewer(), offsetToTest));
    }
    String hoverTextValue = HTML2TextUtil.html2Text(hoverText);
    String compareValue = HTML2TextUtil.html2Text(compare);
    // System.out.println("Hover Text: [" + hoverTextValue + "]\nExpected Value: [" + compareValue +
    // "]\nEqual: " + compareValue.equalsIgnoreCase(hoverTextValue) + "\n");
    assertTrue(
        "Hover exists but its value is not expected:\nHover Text: ["
            + hoverTextValue
            + "]\nExpected Value: ["
            + compareValue
            + "]",
        compareValue.equalsIgnoreCase(hoverTextValue));
  }
示例#2
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;
      }
    }