Take the 2-minute tour ×

For my Eclipse plugin I have created a new perspective. This perspective consists of two views that I have created and a third view that is the default editor (as I assume). Now I want to open a source code file in the default editor. For this source code file I have only the source code in a String. So I may have first to create a temporary file. But more important: How can I access the default editor from my view? Couldn't find any documentation.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You have lots of options, but one of them is to call IDE.openEditor(). There are lots of variants of this, but they generally use a resource. BTW, and editor (EditorPart) and view (ViewPart) are different things in Eclipse, they are both implementations of a IWorkbenchPart.

You can also create a "hidden" resource if you like so that the file that you want to open is not visible in the workspace. If you just want a text editor the default editor can be fine, but you can also construct an IEditorInput to have more control over which sort of editor you want.

Specifically to create a resource:

IProject project = ResourcesPlugin.getWorkspace().getRoot().findProject("projectName");
IFile file = project.getFile("filename");
file.create(inputStream, true, null);
share|improve this answer
add comment

I am not exactly sure, but I think IDE.openEditor(...) is what you are looking for. See here for more details.

share|improve this answer
Thanks, this seems to be useful, but I don't know how to get a IFile from a String with source code. –  RoflcoptrException Dec 17 '11 at 16:23
I edited my answer to add this. –  Francis Upton Dec 17 '11 at 16:51
add comment

Your Answer

