title: Grab selected text from Eclipse Java editor
body: <p>I'm developing an Eclipse plug-in where upon pressing a button, the plug-in takes the selected text in the Java editor and puts in a text box which appears. </p>
  
  <p>My code looks like this: I got it from here: <a href="http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg02200.html" rel="nofollow noreferrer">http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg02200.html</a></p>
  
  <pre><code>private ITextSelection getSelection(ITextEditor editor) {
       ISelection selection = editor.getSelectionProvider()
              .getSelection();
       return (ITextSelection) selection;
  }
  
  private String getSelectedText(ITextEditor editor) {
       return getSelection(editor).getText();
  }
  </code></pre>
  
  <p>The problem is how will I get the <code>ITextEditor</code> of the Java editor being displayed. Coincidentally it's the next question in the thread in the link I posted but it's unanswered :(</p>