Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Open File in Editor
Open File in Editor [message #330786] Wed, 13 August 2008 13:39 Go to next message
Nadav is currently offline NadavFriend
Messages: 29
Registered: July 2009
Junior Member
How do I write code that will open a java file in the Java Editor?

I thought to do IEditorPart
editor=PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input,
editorId), but I have two problems:
1)I'm not sure how to get an IEditorInput for a particular file
2) I don't know what the ID of the default java editor is
Re: Open File in Editor [message #330797 is a reply to message #330786] Wed, 13 August 2008 15:19 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Nadav wrote:
> How do I write code that will open a java file in the Java Editor?
>
> I thought to do IEditorPart
> editor=PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input,
> editorId), but I have two problems:
> 1)I'm not sure how to get an IEditorInput for a particular file
> 2) I don't know what the ID of the default java editor is
>
Use org.eclipse.jdt.ui.JavaUI.openInEditor(IJavaElement)

Dani
Re: Open File in Editor [message #330835 is a reply to message #330786] Thu, 14 August 2008 13:24 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Nadav wrote:
> How do I write code that will open a java file in the Java Editor?
>
> I thought to do IEditorPart
> editor=PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input,
> editorId), but I have two problems:
> 1)I'm not sure how to get an IEditorInput for a particular file
> 2) I don't know what the ID of the default java editor is
>

If you have an IFile, you can use org.eclipse.ui.ide.IDE.openEditor()
instead.

Hope this helps,
Eric
Re: Open File in Editor [message #330865 is a reply to message #330786] Thu, 14 August 2008 17:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: prasad.chand.gmail.com

Nadav wrote:
> How do I write code that will open a java file in the Java Editor?
>
> I thought to do IEditorPart
> editor=PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input,
> editorId), but I have two problems:
> 1)I'm not sure how to get an IEditorInput for a particular file

The following code should help for files outside the workbench otherwise
use IFile

IFileStore fileLocation =
EFS.getLocalFileSystem().getStore(new URI("file://" + fileSelected));
FileStoreEditorInput fileStoreEditorInput = new
FileStoreEditorInput(xmlLocation);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
page.openEditor((IEditorInput)fileStoreEditorInput,
<EDITOR_ID>);


> 2) I don't know what the ID of the default java editor is
I believe the ID is
org.eclipse.jdt.ui.CompilationUnitEditor

You can get the values from IEditorDescriptor api.

Prasad
Re: Open File in Editor [message #330867 is a reply to message #330865] Thu, 14 August 2008 18:01 Go to previous message
Eclipse UserFriend
Originally posted by: prasad.chand.gmail.com

Prasad Chand wrote:
> Nadav wrote:
>> How do I write code that will open a java file in the Java Editor?
>>
>> I thought to do IEditorPart
>> editor=PlatformUI.getWorkbench().getActiveWorkbenchWindow(). getActivePage().openEditor(input,
>> editorId), but I have two problems:
>> 1)I'm not sure how to get an IEditorInput for a particular file
>
> The following code should help for files outside the workbench otherwise
> use IFile
>
> IFileStore fileLocation =
> EFS.getLocalFileSystem().getStore(new URI("file://" + fileSelected));
> FileStoreEditorInput fileStoreEditorInput = new
> FileStoreEditorInput(xmlLocation);
> IWorkbenchPage page =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
> page.openEditor((IEditorInput)fileStoreEditorInput,
> <EDITOR_ID>);
>

oops the correct code is
IFileStore fileLocation =
EFS.getLocalFileSystem().getStore(new URI("file://" + filePathInOS));
FileStoreEditorInput fileStoreEditorInput = new
FileStoreEditorInput(fileLocation);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();

page.openEditor((IEditorInput)fileStoreEditorInput,
<EDITOR_ID>, true);

>
>> 2) I don't know what the ID of the default java editor is
> I believe the ID is
> org.eclipse.jdt.ui.CompilationUnitEditor
>
> You can get the values from IEditorDescriptor api.
>
> Prasad
>
Previous Topic:Are enabled activities persisted?
Next Topic:upgrading Eclipse platform?
Goto Forum:
  


Current Time: Sun Jun 30 09:48:50 GMT 2024

Powered by FUDForum. Page generated in 0.03080 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top