Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Getting handle to a file outside eclipse workspace
Getting handle to a file outside eclipse workspace [message #510969] Fri, 29 January 2010 11:05 Go to next message
Rohan  is currently offline Rohan
Messages: 12
Registered: October 2009
Junior Member
I wanted to get a handle to a file/folder using its absolute pathname. The resource need not necessarily be present in the eclipse workspace. Is there any way i can do so?
Re: Getting handle to a file outside eclipse workspace [message #510995 is a reply to message #510969] Fri, 29 January 2010 08:40 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
Rohan,

No, an IResource must necessarily be in the workspace. It's possible to
create links... You can use
IWorkspaceRoot.getFilesForLocation/getFilesForLocationURI to locate a
resource based on its absolute path.


Rohan wrote:
> I wanted to get a handle to a file/folder using its absolute pathname.
> The resource need not necessarily be present in the eclipse workspace.
> Is there any way i can do so?
Re: Getting handle to a file outside eclipse workspace [message #511358 is a reply to message #510969] Mon, 01 February 2010 11:26 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
Rohan wrote:
> I wanted to get a handle to a file/folder using its absolute pathname.
> The resource need not necessarily be present in the eclipse workspace.
> Is there any way i can do so?
What do you want to do?

Dani
Re: Getting handle to a file outside eclipse workspace [message #511531 is a reply to message #511358] Mon, 01 February 2010 22:12 Go to previous messageGo to next message
Rohit  is currently offline Rohit
Messages: 24
Registered: July 2009
Junior Member
Hi,

I have a somewhat similar issue. I want to open a file external to Eclipse (file does not exist in any Eclipse project currently) in an Eclipse editor.
I tried a few ways to do it which required the package org.eclipse.core.runtime version 2.1. I downloaded that particular api and compiled it with no errors but it gave me the following runtime error

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 number 85 was
IWorkspaceRoot ws = ResourcesPlugin.getWorkspace().getRoot();

Here are a 2 of my code snippets which I tried out

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();
			}



Is there any way to do this using the Eclipse 3.5 api's ? I went through a lot of forums and google search with the above results which do not work. Please guide me to an article/post/ideas or code snippets for the same. Help me out if possible.

Thanks,
Rohit
Re: Getting handle to a file outside eclipse workspace [message #511544 is a reply to message #511531] Mon, 01 February 2010 23:25 Go to previous message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
Rohit wrote on Mon, 01 February 2010 17:12
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();
		}*/

What errors did you get with this code? When you say it doesn't work, what do you mean? Does the editor open with an error? Does the editor open at all? Did you try stepping through the code?

Please provide more information.
Previous Topic:Bundle error in org.eclipse.e4.ui.widgets-rap
Next Topic:Toolbar and command doesn't appear on custom view.
Goto Forum:
  


Current Time: Mon Sep 22 12:16:54 GMT 2014

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

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