Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to find the selection of an action
How to find the selection of an action [message #123034] Fri, 05 September 2003 09:59 Go to next message
Eclipse UserFriend
Originally posted by: ian.brown.printsoft.de

I have an action that I would like to perform on selected files.
I have added an action to the popup menu of the navigator, and made it only
enabled for classes of org.eclipse.core.resources.IFile with a particular
extension.
This works fine, and my ObjectActionDelegate gets called as expected.

Now, I basically want to call an external program and pass the name of the
selected resource as the argument. My problem is that I cannot see how to
find the name of the selected IFile resource from within the action. Surely
it must be simple. All the examples that I can find for this type of thing
(mainly from Contributing Actions to the eclipse workbench) just pop up a
message box ... which isn't a great deal of help. I mean if you are going to
specify that an action is only enabled for certain types of file and also
conditionally based upon how many are selected ... surely most actions will
need to find out what the selected resources are.

Can anyone give me any pointers please.

Thanks,

Ian
Re: How to find the selection of an action [message #123076 is a reply to message #123034] Fri, 05 September 2003 10:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: simon.ibm.oti.lab

Your object action delegate will have its selectionChanged method called
when the selection changes. You can hang onto the selection. Or...

When your IObjectActionDelegate.setActivePart is called, hang on to the
part. Then call part.getSite().getSelectionProvider().getSelection() (note,
getSelectionProvider() can return null which I'm not checking for in this
snippet to keep things simple).

You can then check if the selection is an IStructuredSelection, and if so,
cast it to it. Then check each element if its an IFile and cast to it

Voila!

Simon :-)

"Ian Brown" <ian.brown@printsoft.de> wrote in message
news:bja4mp$h6i$1@eclipse.org...
> I have an action that I would like to perform on selected files.
> I have added an action to the popup menu of the navigator, and made it
only
> enabled for classes of org.eclipse.core.resources.IFile with a particular
> extension.
> This works fine, and my ObjectActionDelegate gets called as expected.
>
> Now, I basically want to call an external program and pass the name of the
> selected resource as the argument. My problem is that I cannot see how to
> find the name of the selected IFile resource from within the action.
Surely
> it must be simple. All the examples that I can find for this type of thing
> (mainly from Contributing Actions to the eclipse workbench) just pop up a
> message box ... which isn't a great deal of help. I mean if you are going
to
> specify that an action is only enabled for certain types of file and also
> conditionally based upon how many are selected ... surely most actions
will
> need to find out what the selected resources are.
>
> Can anyone give me any pointers please.
>
> Thanks,
>
> Ian
>
>
Re: How to find the selection of an action [message #123134 is a reply to message #123076] Fri, 05 September 2003 11:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ian.brown.printsoft.de

Thanks, that should work for single selection. How would I do it for
multi-selection?

Ian

ps: I think subject is an omission from the otherwise excellent article
"Contributing actions to the Eclipse Workbench". Maybe the article could be
updated (?)
Re: How to find the selection of an action [message #123170 is a reply to message #123134] Fri, 05 September 2003 11:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: simon.ibm.oti.lab

An IStructuredSelection can hold 0 - n elements.

Please feel free to update the article yourself (it's just HTML) and then
post your changes to the platform-ui-dev@eclipse.org or
platform-doc-dev@eclipse.org mailing list.

Simon :-)

"Ian Brown" <ian.brown@printsoft.de> wrote in message
news:bja98s$m5c$1@eclipse.org...
> Thanks, that should work for single selection. How would I do it for
> multi-selection?
>
> Ian
>
> ps: I think subject is an omission from the otherwise excellent article
> "Contributing actions to the Eclipse Workbench". Maybe the article could
be
> updated (?)
>
>
Re: How to find the selection of an action [message #124005 is a reply to message #123170] Mon, 08 September 2003 03:11 Go to previous message
Eclipse UserFriend
Originally posted by: ian.brown.printsoft.de

> An IStructuredSelection can hold 0 - n elements.

Doh! Sorry about that .... I should have realised. It was Friday afternoon
and my brain must have switched off for the weekend :-(
When I get it working, I'll try and set aside half a day to update the
article.

Thanks for you help,

Ian
Previous Topic:Clarification needed - Copy menu item and tool bar button - Global Actions
Next Topic:Classpath in Run-time workbench
Goto Forum:
  


Current Time: Tue Jul 22 21:28:41 EDT 2025

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

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

Back to the top