Skip to main content



      Home
Home » Modeling » EMF » Getting the File name and Path From EMF URI(File name and Path From EMF URI without loading resources)
Getting the File name and Path From EMF URI [message #630487] Sun, 03 October 2010 06:14 Go to next message
Eclipse UserFriend
Hi,
I wanted to create a search implementation which shows filenames of all the files available in the workspace.
The result which I have is in the form of array of URIs (org.eclipse.emf.common.util.URI).
But i want to retrieve the file names and paths for them.

I followed two approaches for this:-
1) I tried getting the resource set and then getting the resource from the resource set.
-This approach works absolutely fine but the problem is that, for search if i want to retrieve filenames and their paths, getResource (or) getEobject will load the resources and then we can perform any action on them. This is very inefficient way of showing the search results as i just require the file names.

2) I tried getting the file for it and then getting the file name:-
IPath path = new Path(files[i].toPlatformString(true));//Here files[i] is the URI
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
String fileObject = file.getName();
Even Here I Have to get the File to retrieve the name.

Can anyone suggest me a way to get the file name and the absolute path of the file directly from the URI. The URI here is org.eclipse.emf.common.util.URI and not java.net.URI.

[Updated on: Sun, 03 October 2010 06:17] by Moderator

Re: Getting the File name and Path From EMF URI [message #630506 is a reply to message #630487] Sun, 03 October 2010 10:46 Go to previous messageGo to next message
Eclipse UserFriend
I think 2nd option is already good. Following code does same thing for you:

Quote:

URI resolvedFile = CommonPlugin.resolve(uri);
ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resolvedFile.toFileString()));



Regards,
Ashwani Kr Sharma
Re: Getting the File name and Path From EMF URI [message #630511 is a reply to message #630487] Sun, 03 October 2010 11:55 Go to previous message
Eclipse UserFriend
Animesh,

URI.lastSegment is far more direct.


Animesh Kumar wrote:
> Hi,
> I wanted to create a search implementation which shows filenames of
> all the files available in the workspace.
> The result which I have is in the form of array of URIs
> (org.eclipse.emf.common.util.URI). But i want to retrieve the file
> names and paths for them.
>
> I followed two approaches for this:-
> 1) I tried getting the resource set and then getting the resource from
> the resource set.
> -This approach works absolutely fine but the problem is that, for
> search if i want to retrieve filenames and their paths, getResource
> (or) getEobject will load the resources and then we can perform any
> action on them. This is very inefficient way of showing the search
> results as i just require the file names.
>
> 2) I tried getting the file for it and then getting the file name:-
> IPath path = new Path(files[i].toPlatformString(true));
> IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
> String fileObject = file.getName();
> Even Here I Have to get the File to retrieve the name.
>
> Can anyone suggest me a way to get the file name and the absolute path
> of the file directly from the URI. The URI here is
> org.eclipse.emf.common.util.URI and not java.net.URI.
>
>
Previous Topic:How to model an array of element ?
Next Topic:Best Practice for EMF and WTP
Goto Forum:
  


Current Time: Sun Jul 06 23:19:56 EDT 2025

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

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

Back to the top