getting the selection from the viewer [message #46863] |
Mon, 02 June 2003 16:11  |
Eclipse User |
|
|
|
Hi,
I need to add an action to a plug-in that will run depending on what is
selected in the viewer. The unfortunate thing is, I can't seem to get the
selection in the viewer. I have tried to implement my action as an
IWorkbenchWindowActionDelegate and an ISelectionListener, and use
window.getSelectionService().addSelectionListener(this);
in the init() method (which I know is being called). But the selection
listener doesn't seem to catch changes that happen in the ViewPart (which
uses as its viewer a TreeViewer).
Can anyone help me out? Thanks.
Del
|
|
|
|
|
Re: getting the selection from the viewer [message #47390 is a reply to message #46951] |
Tue, 03 June 2003 10:28   |
Eclipse User |
|
|
|
Originally posted by: richkulp.NOSPAM.us.ibm.com
If it needs to be on the menu bar and toolbar and not be on the popup
menu, and not related to any particular view or editor, then it needs to
be in an ActionSet.
An ActionSet action is an IWorkbenchWindowActionDelegate. Just like in
my previous append, you will be notified with selectionChanged whenever
the selection is changed. You should save the selection that comes in
and use it on the run(). On selectionChanged you should also determine
if the current selection meets your criteria and it should set the
enable state on the IAction passed accordingly.
Also, make sure that in your plugin.xml, you have an <enablement> clause
so that it is enabled on IProject only, and whether you can handle more
than one selection at a time.
Note the selection is always from the current active workbench part,
whatever it may be, an editor or a viewer.
Read the help section on Action Sets extension point.
Also, are you sure you need it on the menu bar and toolbar? It would
actually be simpler in some ways if it was on the popup menu instead.
Then it wouldn't be taking up space on the toolbar when not needed. But
that is your call, this is just a thought.
By the way I just realized we are in the jdt newsgroup. For future
information this kind of question belongs on eclipse.tools.platform.
Rich
|
|
|
Re: getting the selection from the viewer [message #47571 is a reply to message #47390] |
Tue, 03 June 2003 12:29   |
Eclipse User |
|
|
|
I am going to post my reply here for now because I can't seem to find the
eclipse.tools.platform newsgroup.
I do have the action as an ActionSet implemented as an
IWorkbenchWindowActionDelegate. I've been doing some tests, and I found that
it is only in one view (a view that was mad previously for other purposes)
that I don't get the selectionChanged event. Could it be that I don't have
the selection service set up properly?
Del
"Richard L. Kulp" <richkulp@NOSPAM.us.ibm.com> wrote in message
news:bbibbu$ne3$1@rogue.oti.com...
> If it needs to be on the menu bar and toolbar and not be on the popup
> menu, and not related to any particular view or editor, then it needs to
> be in an ActionSet.
>
> An ActionSet action is an IWorkbenchWindowActionDelegate. Just like in
> my previous append, you will be notified with selectionChanged whenever
> the selection is changed. You should save the selection that comes in
> and use it on the run(). On selectionChanged you should also determine
> if the current selection meets your criteria and it should set the
> enable state on the IAction passed accordingly.
>
> Also, make sure that in your plugin.xml, you have an <enablement> clause
> so that it is enabled on IProject only, and whether you can handle more
> than one selection at a time.
>
> Note the selection is always from the current active workbench part,
> whatever it may be, an editor or a viewer.
>
> Read the help section on Action Sets extension point.
>
> Also, are you sure you need it on the menu bar and toolbar? It would
> actually be simpler in some ways if it was on the popup menu instead.
> Then it wouldn't be taking up space on the toolbar when not needed. But
> that is your call, this is just a thought.
>
> By the way I just realized we are in the jdt newsgroup. For future
> information this kind of question belongs on eclipse.tools.platform.
>
> Rich
>
|
|
|
|
Re: getting the selection from the viewer [message #47879 is a reply to message #47819] |
Tue, 03 June 2003 17:54  |
Eclipse User |
|
|
|
Thanks for your help, I got it working
"Richard L. Kulp" <richkulp@NOSPAM.us.ibm.com> wrote in message
news:bbj1ms$cs0$1@rogue.oti.com...
> Opps, it eclipse.platform (no .tools.).
>
> That would indicate that the view in question either did not give up a
> selection provider to the workbench page to use, or it is not signaling
> selections.
>
> For a standard view, it needs to, at some point, do:
>
> getSite().setSelectonProvider(ISelectionProvider) with the selection
> provider.
>
> Now that selection provider in that view is the one that signals out
> selections from that view. If both of these are done, then the viewer
> should be signaling selections correctly.
>
> Rich
>
|
|
|
Powered by
FUDForum. Page generated in 0.47163 seconds