Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:14 Go to next message
Animesh Kumar is currently offline Animesh KumarFriend
Messages: 18
Registered: September 2010
Location: Bangalore
Junior Member
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.



Regards,
Animesh

[Updated on: Sun, 03 October 2010 10:17]

Report message to a moderator

Re: Getting the File name and Path From EMF URI [message #630506 is a reply to message #630487] Sun, 03 October 2010 14:46 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

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 15:55 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30540
Registered: July 2009
Senior Member
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: Mon Oct 14 04:33:38 GMT 2019

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

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

Back to the top