How to retrieve the selected filename [message #321153] |
Wed, 10 October 2007 13:52 |
Eclipse User |
|
|
|
Originally posted by: alexjaquet.gmail.com
Hi,
I need to know how can I get the name of the file I select in the
project explorer (for an exporter wizard)
Thanks for your suggestion
Regards,
Alexandre
|
|
|
Re: How to retrieve the selected filename [message #321156 is a reply to message #321153] |
Wed, 10 October 2007 14:22 |
Eclipse User |
|
|
|
Originally posted by: monikakrug.expires-2007-09-30.arcornews.de
Alexandre Jaquet schrieb:
> I need to know how can I get the name of the file I select in the
> project explorer (for an exporter wizard)
>
> Thanks for your suggestion
Let's say you defined an Action that shows up in the context menu when
you right-click on a Java file (ICompilationUnit) in the package explorer:
public class SomeAction implements IObjectActionDelegate
{
public void run(IAction action)
{
ICompilationUnit javaFile = (ICompilationUnit) ((TreeSelection)
selection).getFirstElement();
IPath p = javaFile.getCorrespondingResource().getFullPath();
}
ISelection selection;
public void selectionChanged(IAction action, ISelection selection)
{
this.selection = selection;
}
public void setActivePart(IAction action, IWorkbenchPart targetPart)
{
}
}
When it is not a Java file in the package explorer view, but any file in
the navigator, then don't cast to ICompilationUnit, but to IFile or
whatever you restricted your Action to.
Monika.
--
All wars are civil wars, because all men are brothers ... Each one owes
infinitely more to the human race than to the particular country in
which he was born. - Francois Fenelon, theologian and writer (1651-1715)
E-mail address is valid until 4 weeks after the expiration date. Use
@arcor.de instead.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03457 seconds