"L" at the beginning of a path [message #1547] |
Wed, 06 May 2009 19:27  |
Eclipse User |
|
|
|
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] |
Wed, 06 May 2009 22:09   |
Eclipse User |
|
|
|
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 #3032 is a reply to message #2804] |
Mon, 11 May 2009 12:57  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04081 seconds