[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] How to open a file from a custom browser view ?

Hi,

I'm trying to develop my first Eclipse RCP based application.
I tried to create a very simple browser view, using the tree view example (sample view), because I couldn't get the common navigator view to work (I get empty labels, although everything else seems to be alright).
I also created an XML editor using the XML Editor template. When I create a new xml file, it opens within this editor which works just fine.


My problem is that, when I double-click on a file inside this treeview to open it with my XML editor, a new editor opens with the name of the file as tab title and just "ERROR" in the window. Nothing else, nothing in the log.

Here's the code of my doubleclick action :

ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection)selection).getFirstElement();

// open file
File f = new File("./");
String path = new String();
String fileName = new String();
if (obj instanceof TreeParent) {
f = ((TreeParent)obj).getFile();
path = ((TreeParent)obj).getPath();
fileName = ((TreeParent)obj).getName();
} else if (obj instanceof TreeObject) {
f = ((TreeObject)obj).getFile();
path = ((TreeObject)obj).getPath();
fileName = ((TreeObject)obj).getName();
}
// i know from tests that obj is always instanceof treeparent or treeobject, so the if/else condition shouldn't be the cause of the problem, IMO.

IFileStore ifs = EFS.getLocalFileSystem().getStore(new Path(path));
FileStoreEditorInput fInput = new FileStoreEditorInput(ifs);

try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(fInput, XMLEditor.ID);
} catch (PartInitException e) {
}



I really don't know what's wrong. The files aren't in the workspace, but I've read that using FileStoreEditorInput was the right way to do this.



You can also find the complete class here : http://www.crazy-east.info/public/ServiceView.java
I've put two lines like this :"//// first interesting part" and "//// second interesting part" to mark the two sections that I think may cause an error, as everything was generated by Eclipse.



Any help would be more than appreciated, thanks.