Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » "L" at the beginning of a path
"L" at the beginning of a path [message #1547] Wed, 06 May 2009 23:27 Go to next message
Tilaye is currently offline TilayeFriend
Messages: 2
Registered: July 2009
Junior Member
Hi,

This is probably a common issue but I couldn't find any discussion on
this. I am developing a plugin that lets the user select a file on Package
Explorer, right click on it, and then do some operation. I can get hold of
the selected object when my,

IObjectActionDelegate.selectionChanged(IAction action, ISelection
selection)

method gets called. Inside this method I do,

((IStructuredSelection)selection).getFirstElement()

which gives me the relative path of the file selected. This looks like,

L/PluginProject/src/file.xml

Everything is good except the "L" at the beginning of the path. Of course
I can strip it and go on with my life, but just wondering what this letter
stands for and should I expect the same behavior in other Eclipse
versions? I am currently using Eclipse 3.4.2 under Ubuntu.

Any help much appreciated!

Tilaye.
Re: "L" at the beginning of a path [message #1561 is a reply to message #1547] Thu, 07 May 2009 02:09 Go to previous messageGo to next message
Ben Vitale is currently offline Ben VitaleFriend
Messages: 247
Registered: July 2009
Senior Member
It sounds like you are just calling toString() on the selection. Maybe
check if the first element is an IResource, and then you can do
getPath() which has a few additional to*String() methods.

Hope that helps.

-Ben

Tilaye wrote:
> Hi,
>
> This is probably a common issue but I couldn't find any discussion on
> this. I am developing a plugin that lets the user select a file on
> Package Explorer, right click on it, and then do some operation. I can
> get hold of the selected object when my,
>
> IObjectActionDelegate.selectionChanged(IAction action, ISelection
> selection)
>
> method gets called. Inside this method I do,
>
> ((IStructuredSelection)selection).getFirstElement()
>
> which gives me the relative path of the file selected. This looks like,
>
> L/PluginProject/src/file.xml
>
> Everything is good except the "L" at the beginning of the path. Of
> course I can strip it and go on with my life, but just wondering what
> this letter stands for and should I expect the same behavior in other
> Eclipse versions? I am currently using Eclipse 3.4.2 under Ubuntu.
>
> Any help much appreciated!
>
> Tilaye.
>
Re: "L" at the beginning of a path [message #1581 is a reply to message #1547] Thu, 07 May 2009 03:42 Go to previous messageGo to next message
Charlie Kelly is currently offline Charlie KellyFriend
Messages: 276
Registered: July 2009
Senior Member
Not sure about "L"; but "R" is resource; "F" is File; etc.

HTH
Charlie

Tilaye wrote:
> Hi,
>
> This is probably a common issue but I couldn't find any discussion on
> this. I am developing a plugin that lets the user select a file on
> Package Explorer, right click on it, and then do some operation. I can
> get hold of the selected object when my,
>
> IObjectActionDelegate.selectionChanged(IAction action, ISelection
> selection)
>
> method gets called. Inside this method I do,
>
> ((IStructuredSelection)selection).getFirstElement()
>
> which gives me the relative path of the file selected. This looks like,
>
> L/PluginProject/src/file.xml
>
> Everything is good except the "L" at the beginning of the path. Of
> course I can strip it and go on with my life, but just wondering what
> this letter stands for and should I expect the same behavior in other
> Eclipse versions? I am currently using Eclipse 3.4.2 under Ubuntu.
>
> Any help much appreciated!
>
> Tilaye.
>
Re: "L" at the beginning of a path [message #1594 is a reply to message #1547] Thu, 07 May 2009 04:51 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
Tilaye wrote:
>
> just wondering what this letter stands for

from Resource.getTypeString() - L for File, F for Folder, P for Project,
R for Workspace Root

> should I expect the same behavior in other Eclipse versions?

I don't think that this is a published API or something. Although there
is no reason to change it now, there is no guarantee that it will
remain unchanged.

- Prakash

---
http://blog.eclipse-tips.com
Re: "L" at the beginning of a path [message #2804 is a reply to message #1594] Thu, 07 May 2009 20:26 Go to previous messageGo to next message
Tilaye is currently offline TilayeFriend
Messages: 2
Registered: July 2009
Junior Member
Thanks everyone. The following casting works,

ISelection -> IStructuredSelection -> IFile

I then do file.getProjectRelativePath().toOSString() which gives me the
full path of the file. Just what I needed.

Thank you all for the prompt response :)

Cheers,
Tilaye.

Prakash G.R. wrote:

> Tilaye wrote:
>>
>> just wondering what this letter stands for

> from Resource.getTypeString() - L for File, F for Folder, P for Project,
> R for Workspace Root

>> should I expect the same behavior in other Eclipse versions?

> I don't think that this is a published API or something. Although there
> is no reason to change it now, there is no guarantee that it will
> remain unchanged.

> - Prakash

> ---
> http://blog.eclipse-tips.com
Thanks everyone for your reply. The following casting works,

ISelection -> IStructuredSelection -> IFile

I then do file.getProjectRelativePath().toOSString() which gives me the
full path of the file. Just what I needed.

Thank you all for the prompt response :)

Cheers,
Tilaye.
Re: "L" at the beginning of a path [message #3032 is a reply to message #2804] Mon, 11 May 2009 16:57 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Tilaye wrote:
> Thanks everyone. The following casting works,
>
> ISelection -> IStructuredSelection -> IFile
>
> I then do file.getProjectRelativePath().toOSString() which gives me the
> full path of the file. Just what I needed.

Un-checked casting is dangerous because it assumes the selection is an
IFile. Better would be to use the Adatper framework. For example, a call
like this:
org.eclipse.core.runtime.Platform.getAdapterManager().getAda pter(mySelection,
IFile.class)

The selection can be a lot of different things that are not IFile
instances but that can be adapted to IFile. Using code like above, if
the selection is anything that can be adapted to an IFile, you're code
will work even if it is not actually an IFile. Using this technique will
make your code more robust and allow it to integrate with other plug-ins
or views that don't use IFile as the basis for defining the selection.

You can learn about adapters here:
http://www.eclipse.org/resources/?category=Adapters

Hope this helps,
Eric
Previous Topic:System.out.println into a TableViewer
Next Topic:Single Item Checkable CheckboxTableViewer
Goto Forum:
  


Current Time: Wed Jul 17 14:11:53 GMT 2024

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

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

Back to the top