Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to retrieve the selected filename
How to retrieve the selected filename [message #321153] Wed, 10 October 2007 13:52 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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.
Re: How to retrieve the selected filename [message #321158 is a reply to message #321153] Wed, 10 October 2007 14:31 Go to previous message
Eclipse UserFriend
Originally posted by: alexjaquet.gmail.com

founded, simply by using

this.selection = selection;
File obj = (File) selection.getFirstElement();
Previous Topic:Welcome screen vs. PDF links
Next Topic:Branding Problem under Linux :: The About box is too small
Goto Forum:
  


Current Time: Fri Apr 26 08:17:29 GMT 2024

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

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

Back to the top