Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Open a file in the editor from code
Open a file in the editor from code [message #1003503] Mon, 21 January 2013 11:33 Go to next message
Marco Orlandin is currently offline Marco OrlandinFriend
Messages: 6
Registered: January 2013
Junior Member
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 12:12]

Report message to a moderator

Re: Open a file in the editor from code [message #1003618 is a reply to message #1003503] Mon, 21 January 2013 16:14 Go to previous message
Dani Megert is currently offline Dani MegertFriend
Messages: 3801
Registered: July 2009
Senior Member
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
Previous Topic:How to override/modify a perspective layout from another plugin?
Next Topic:Add specific visual Editor from plugin to E4 RCP Application
Goto Forum:
  


Current Time: Fri Nov 28 13:54:14 GMT 2014

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

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