Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipse plugin to read contents of a editor
    primarykey
    data
    text
    <p>I want to write a eclipse plugin which reads the contents from the editor window and displays it to me. This should've been a very simple task after I found how to do this on this post <a href="https://stackoverflow.com/questions/1694748/adding-item-to-eclipse-text-viewer-context-menu">Adding item to Eclipse text viewer context menu</a></p> <p>Before I state my problem, lemme state what I did till now:</p> <p>I am developing on eclipse 3.7 and I created a simple hello world plugin whose code was auto-generated by eclipse for me. </p> <p>Here is the run function:</p> <pre><code>public void run(IAction action) { MessageDialog.openInformation( window.getShell(), "AnirudhPlugin", "Hello, Eclipse world"); try { IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if(part instanceof IReusableEditor){ System.out.println("is of type reusable editor"); final IReusableEditor editor = (IReusableEditor)part; if(editor instanceof AbstractTextEditor){ System.out.println("abstract"); } if(editor instanceof StatusTextEditor){ System.out.println("status"); } if(editor instanceof TextEditor){ System.out.println("text"); } if(editor instanceof AbstractDecoratedTextEditor){ System.out.println("abs dec"); } if(editor instanceof CommonSourceNotFoundEditor){ System.out.println("comm"); } } if ( part instanceof ITextEditor ) { final ITextEditor editor = (ITextEditor)part; IDocumentProvider prov = editor.getDocumentProvider(); IDocument doc = prov.getDocument( editor.getEditorInput() ); ISelection sel = editor.getSelectionProvider().getSelection(); if ( sel instanceof TextSelection ) { final TextSelection textSel = (TextSelection)sel; String newText = "/*" + textSel.getText() + "*/"; MessageDialog.openInformation( window.getShell(), "AnirudhPlugin", newText); doc.replace( textSel.getOffset(), textSel.getLength(), newText ); } }else{ MessageDialog.openInformation( window.getShell(), "AnirudhPlugin", "Not ITextEditor"); } } catch ( Exception ex ) { ex.printStackTrace(); } } </code></pre> <p>Now when I run this code, I get the output that its of type "reusable editor" unlike what it should've been "ITextEditor" (please correct me I am making some silly statement since I am a newbie in eclipse Plugin dev). I tried to check IReusableEditor instance type(as you can see in the code above, I have tried to check by using "instance of") but to my surprise itsnot pointing to any of the classes which implements IReusableEditor interface.</p> <p>The editor from which I was trying to read was a simple editor window in which I had written some java code. </p> <p>Also I get doc2 variable value as null for the following</p> <pre><code>final IDocument doc2 = (IDocument) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getAdapter(IDocument.class); </code></pre> <p>Please let me know where am I doing the mistake, thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload