Open a file in the editor from code [message #1003503] |
Mon, 21 January 2013 06:33  |
Eclipse User |
|
|
|
Hi,
i need to open a project in my RCP application from code. I've done with this function
@Override
public void run() {
IPath path = new Path("/MyReports/Coffee_4.jrxml");
IFile sampleFile = new FileTest(path,(Workspace)ResourcesPlugin.getWorkspace());
try {
EditorUtility.openInEditor(sampleFile, true);
} catch (PartInitException e) {
e.printStackTrace();
}
}
Where FileTest is a subclass of org.eclipse.core.internal.resources.File, since its constructor is protected. It works but i get a lot of "discouraged access" warnings, so probably this method isn't a clean one. Is there some other way to do this?
UPDATE:
I've found a more clean way with
@Override
public void run() {
IPath path = new Path("/MyReports/Coffee_4.jrxml");
IFile sampleFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
try {
EditorUtility.openInEditor(sampleFile, true);
} catch (PartInitException e) {
e.printStackTrace();
}
}
But i've still the same problem since even EditorUtility.openInEditor is discouraged
[Updated on: Mon, 21 January 2013 07:12] by Moderator
|
|
|
Re: Open a file in the editor from code [message #1003618 is a reply to message #1003503] |
Mon, 21 January 2013 11:14  |
Eclipse User |
|
|
|
On 21.01.2013 12:33, Marco Orlandin wrote:
> Hi,
> i need to open a project in my RCP application from code. I've done
> with this function
>
>
> @Override
> public void run() {
> IPath path = new Path("/MyReports/Coffee_4.jrxml");
> IFile sampleFile = new
> FileTest(path,(Workspace)ResourcesPlugin.getWorkspace());
> try {
> EditorUtility.openInEditor(sampleFile, true);
> } catch (PartInitException e) {
> e.printStackTrace();
> }
> }
>
>
> Where FileTest is a subclass of
> org.eclipse.core.internal.resources.File, since its constructor is
> protected. It works but i get a lot of "discouraged access" warnings,
> so probably this method isn't a clean one.
It's "clean" but not intended to use by clients. Same is true for
'EditorUtility'
> Is there some other way to do this?
Take a look at
org.eclipse.ui.ide.IDE.openEditorOnFileStore(IWorkbenchPage, IFileStore)
Dani
|
|
|
Powered by
FUDForum. Page generated in 0.24447 seconds