Open File in Editor [message #330786] |
Wed, 13 August 2008 13:39  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
>
|
|
|
Powered by
FUDForum. Page generated in 0.04043 seconds