More Action Enablement [message #78049] |
Wed, 18 June 2003 15:15  |
Eclipse User |
|
|
|
Originally posted by: luis_benitez.us.ibm.com
Hi all,
I'm new to eclipse and I'm trying to figure out action enablement. I'm
contributing an action via the plug-in.xml as part of an ActionSet. The
class is set to be a implementation of IWorkbenchWindowActionDelegate. I
want to set the action enablement through code. I thought the best way to
do this was through IWorkbenchWindowActionDelegate.selectionChanged(IAction,
ISelection). When is that method called? What kind of selections trigger
this event? How can I trigger this event?
Ideally that method will look like:
public void selectionChanged(IAction, ISelection) {
if ( action.getId().equals("com.ibm.myaction") )
{
if ( ISelection instanceof IStructuredSelection )
{
if ( selection.isEmpty() )
{
action.setEnabled(false);
}
else
{
action.setEnabled(true);
}
}
}
}
In my case, I have a perspective that has a tree viewer. I want the action
enablement to be based on a selection of the tree viewer. How do I do this?
Do I have to register the action delegate as TreeSelectionChangedListener???
I've looked through the articles and the newsgroups and I haven't been able
to find any relevant info. Sorry if this is a duplicate.
-Luis
PS. I'm using Eclipse 2.1
|
|
|
|
Re: More Action Enablement [message #78108 is a reply to message #78095] |
Wed, 18 June 2003 18:15   |
Eclipse User |
|
|
|
Originally posted by: luis_benitez.us.ibm.com
Hi Rich, thanks for the quick response.
When I added ' enablesFor="1" ' to my plugin.xml, the action is always
disabled. Here's the definition:
<action
label="%menu.selected.addEvent"
icon="icons/Toolbar/Enabled/AddEvent.bmp"
tooltip="%tooltip.addEvent"
class="com.myplugin.actions.SelectedActions"
menubarPath="selectedMenu/addEvent"
toolbarPath="addEvent"
disabledIcon="icons/Toolbar/Disabled/AddEvent.bmp"
id="com.myplugin.actions.AddEventAction"
enablesFor="1">
<selection class="org.eclipse.jface.viewers.IStructuredSelection"/>
</action>
</actionSet>
No matter what I select in my tree viewer, the action is always disabled.
Any ideas ?
-Luis
"Richard L. Kulp" <richkulp@NOSPAM.us.ibm.com> wrote in message
news:bcqn39$jpg$1@rogue.oti.com...
>
> >
> > public void selectionChanged(IAction, ISelection) {
> > if ( action.getId().equals("com.ibm.myaction") )
> --- Don't do getID test. It is not necessary. It will be for your
action.
>
> > {
> > if ( ISelection instanceof IStructuredSelection )
> > {
> > if ( selection.isEmpty() )
> > {
> > action.setEnabled(false);
> > }
> > else
> > {
> > action.setEnabled(true);
> > }
> > }
> > }
> > }
> >
>
> First look up the help on ActionSet. It is better to try to do as much
> of the enablement testing through the plugin.xml as possible. That way
> your plugin won't get activated unless it actually needs to.
>
> Look in Help->Platform Plugin Developer's Guide->Reference->Extension
> Points->Workbench->org.eclipse.ui.actionSets
>
> For example, the above test you wrote can be done in the plugin.xml by
> using enablesFor="+" which means enable for one or more selected items.
> Also important is <selection> element. This is used to determine whether
> to be enabled for what kinds of selections. For example, if you only
> want to be enabled when IProject's are selected, you would use
>
> <action
> ...
> <selection class="org.eclipse.core.resources.IProject"/>
> </action>
>
>
> You would use element <enablement> if it is more complicated than just
> the type of the selection and the number selected.
>
> However, after it loads your delegate once, then whenever is selection
> is changed you will receive the selectionChanged notification and you
> must set the enablement there if it is more complicated then what the
> plugin.xml can give you.
>
> However don't test the action.getId(). It will be for your action, that
> is guarenteed.
>
> --
> Thanks, Rich Kulp
>
>
|
|
|
Re: More Action Enablement [message #78784 is a reply to message #78108] |
Thu, 19 June 2003 18:16  |
Eclipse User |
|
|
|
Originally posted by: knut_radloff.oti.com
"Luis Benitez" <luis_benitez@us.ibm.com> wrote in message news:bcqoc8$kjv$1@rogue.oti.com...
> Hi Rich, thanks for the quick response.
>
> When I added ' enablesFor="1" ' to my plugin.xml, the action is always
> disabled. Here's the definition:
[...]
> enablesFor="1">
> <selection class="org.eclipse.jface.viewers.IStructuredSelection"/>
selection class has to be an element class. E.g., IFile, IProject.
Or you can omit it if you don't care about the kind of selected element and just specify enablesFor.
Knut
|
|
|
Powered by
FUDForum. Page generated in 0.03580 seconds