Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » getting the selection from the viewer
getting the selection from the viewer [message #46863] Mon, 02 June 2003 16:11 Go to next message
Eclipse UserFriend
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 #46921 is a reply to message #46863] Mon, 02 June 2003 17:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NOSPAM.us.ibm.com

If you are talking about a specific viewer and you know the id for the
viewer, then use the plugin.xml to create a viewer contribution. Here's
an example from the help. For more details go to the popup menus
extension point in the help:

<extension point="org.eclipse.ui.popupMenus">
<viewerContribution
id="com.xyz.C4"
targetID="org.eclipse.ui.views.TaskList">
<visibility>
<and>
<pluginState id="com.xyz" value="activated"/>
<systemProperty name="ADVANCED_MODE" value="true"/>
</and>
</visibility>
<action
id="com.xyz.showXYZ"
label="&amp;Show XYZ"
style="push"
menubarPath="additions"
icon="icons/showXYZ.gif"
helpContextId="com.xyz.show_action_context"
class="com.xyz.actions.XYZShowActionDelegate">
</action>
</viewerContribution>
</extension>


This says that the action will be on popup menus within the viewer Tasklist.

AND implement an IViewActionDelegate. Then implement the
selectionChanged method from IActionDelegate. That will have the current
selection in the viewer that you specified in the targetID above in the xml.
Re: getting the selection from the viewer [message #46951 is a reply to message #46921] Mon, 02 June 2003 18:05 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, I should have been more specific. The action is going to work on
IProjects, and I want it to work across different views (i.e. the Java
perspective, the debug perspective, etc.), so the action is going to be
accessed from the menus and the toolbar.


"Richard L. Kulp" <richkulp@NOSPAM.us.ibm.com> wrote in message
news:bbggvq$ct1$1@rogue.oti.com...
> If you are talking about a specific viewer and you know the id for the
> viewer, then use the plugin.xml to create a viewer contribution. Here's
> an example from the help. For more details go to the popup menus
> extension point in the help:
>
> <extension point="org.eclipse.ui.popupMenus">
> <viewerContribution
> id="com.xyz.C4"
> targetID="org.eclipse.ui.views.TaskList">
> <visibility>
> <and>
> <pluginState id="com.xyz" value="activated"/>
> <systemProperty name="ADVANCED_MODE" value="true"/>
> </and>
> </visibility>
> <action
> id="com.xyz.showXYZ"
> label="&amp;Show XYZ"
> style="push"
> menubarPath="additions"
> icon="icons/showXYZ.gif"
> helpContextId="com.xyz.show_action_context"
> class="com.xyz.actions.XYZShowActionDelegate">
> </action>
> </viewerContribution>
> </extension>
>
>
> This says that the action will be on popup menus within the viewer
Tasklist.
>
> AND implement an IViewActionDelegate. Then implement the
> selectionChanged method from IActionDelegate. That will have the current
> selection in the viewer that you specified in the targetID above in the
xml.
>
Re: getting the selection from the viewer [message #47390 is a reply to message #46951] Tue, 03 June 2003 10:28 Go to previous messageGo to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Eclipse UserFriend
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 #47819 is a reply to message #47571] Tue, 03 June 2003 16:49 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: richkulp.NOSPAM.us.ibm.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
Re: getting the selection from the viewer [message #47879 is a reply to message #47819] Tue, 03 June 2003 17:54 Go to previous message
Eclipse UserFriend
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
>
Previous Topic:cvs checkout:malformed file transmission recieved
Next Topic:Dealing with SCCS directories in source tree
Goto Forum:
  


Current Time: Thu Jul 17 20:15:24 EDT 2025

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

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

Back to the top