4

I would like to make a Eclipse plugin (text editor). I would "read" the text under the cursor and show a dynamical generated hover that depends on the text. Now I have the problem that I don't know how I can read the text and "add" the hover.

It's my first Eclipse Plugin so I am happy for each tip I can get.

Edit:

I'd like to integrate it into the default Eclipse Java editor. I have tried to create a new plugin with a editor template but I think it is the wrong way.

Last Edit:

The answer from PKeidel is exactly what I'm looking for :)

Thanks PKeidel

phoenix
  • 49
  • 7
  • 1
    please explain what youv got right now, an editor-view? an plugin-skeleton? – Grim Oct 18 '12 at 14:13
  • What a java-element do you need to mark?http://help.eclipse.org/helios/topic/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/util/package-summary.html – Grim Oct 19 '12 at 09:41
  • I would mark a String parameter for a method. Now I have a new Editor with a working Hover. But I would integrate the Hover into the Default Java Editor. I make it with an own SourceViewerConfiguration. How can I add the Hover Configuration to the Default Editor but nothing else? (Synthax Highlighting, CodeScanner, ...) – phoenix Oct 19 '12 at 13:08
  • @phoenix have you managed to do this? – Teshte Nov 07 '16 at 14:37

1 Answers1

4

Your fault is that you created a completly new Editor instead of a plugin for the existing Java Editor. Plugins will be activated via extension points. In your case you have to use org.eclipse.jdt.ui.javaEditorTextHovers more....

<plugin>
   <extension
         point="org.eclipse.jdt.ui.javaEditorTextHovers">
      <hover
            activate="true"
            class="path.to_your.hoverclass"
            id="id.path.to_your.hoverclass">
      </hover>
   </extension>

</plugin>


The class argument holds the path to your Class that implements IJavaEditorTextHover.

public class LangHover implements IJavaEditorTextHover
{
    @Override
    public String getHoverInfo(ITextViewer textviewer, IRegion region)
    {
         if(youWantToShowAOwnHover)
           return "Your own hover Text goes here"";
         return null; // Shows the default Hover (Java Docs)
    }
}

That should do it ;-)

PKeidel
  • 2,559
  • 1
  • 21
  • 29