Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Eclipse Custom Editor file programmatically from file system

I am developing an Eclipse Plugin with my custom text editor.

I need to open files programmatically inside this custom editor. When I open it using Eclipse's DefaultTextEditor, the file opens file and I am able to edit the text, etc.

But when I try to open the file using my editor, the editor turns up blank and is uneditable. Here is the source that I am using.

    File file = new File(filename);
    IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(file.toURI());
    FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = window.getActivePage();

    try {
          // this works fine    
          page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEditor");         

          // this is where the issue is
          page.openEditor(editorInput, "MyEditor.editor");          

    } catch (PartInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Thanks

like image 608
KaaL- Avatar asked Mar 23 '26 23:03

KaaL-


1 Answers

Try to use IDE.openEditor(...).

This Eclipse wiki has more information about this:

http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F

like image 77
alex makedonsky Avatar answered Mar 26 '26 14:03

alex makedonsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!