Open a file programatically in Eclipse editor -- please help if possible [message #511208] |
Sun, 31 January 2010 01:06 |
Rohit Messages: 24 Registered: July 2009 |
Junior Member |
|
|
Hello guys,
This may be a well discussed topic for most of you. I am trying to open a file(a .c file to be specific) external to Eclipse programatically in Eclipse editor. I went through a lot of posts and forums/google search. I tried a few ways but to no avail.
Most of the things I tried I realised were for older versions of Eclipse API's.
Finally I found a way which required org.eclipse.core.runtime plugin. However the version was 2.1. I tried to include that and the code gave me no compile errors, but a runtime error saying
Exception in thread "main" java.lang.VerifyError: (class: org/eclipse/core/runtime/Plugin, method: <init> signature: (Lorg/eclipse/core/runtime/IPluginDescriptor;)V) Incompatible object argument for function call
at com.example.mouse.FileOpen.main(FileOpen.java:85)
Line 85 was
IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
Here are some of my code snippets I tried but didnt work
1 ) File file = new File("/home/rohit/func.c");
IFileStore fileOnLocalDisk = EFS.getLocalFileSystem().getStore(file.toURI());
FileStoreEditorInput editorInput = new FileStoreEditorInput(fileOnLocalDisk);
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage page = window.getActivePage();
try {
page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEdtior");
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
2) IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();
IPath location = new Path("/home/rohit/func.c");
IFile file = ws.getFileForLocation(location);
IProject project = ws.getProject("External Files");
if (!project.exists())
try {
project.create(null);
if (!project.isOpen())
project.open(null);
//IFile file = project.getFile(location.lastSegment());
//file.createLink(location, IResource.NONE, null);
FileEditorInput fileEditorInput = new FileEditorInput(file);
IWorkbench workbench = PlatformUI.getWorkbench();
IEditorDescriptor desc = workbench.getEditorRegistry().getDefaultEditor(file.getName());
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
page.openEditor(fileEditorInput, desc.getId());
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Well there are few more but no point listing them because all of them gave me errors.
The point is how do I open an external file in Eclipse editor. Please point me to some article/post for Eclipse 3.5.1. There are many out there for older versions but nothing complete. I have spent a lot of time on this and have proceeded no where...
Any help would be greatly appreciated. Thank you for your time.
Rohit
[Updated on: Mon, 01 February 2010 17:12] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02874 seconds