Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Migrating action sets from JFace actions to handlers
Migrating action sets from JFace actions to handlers [message #325392] Sat, 16 February 2008 15:30 Go to next message
Eclipse UserFriend
Hi,
I do have some trouble in migrating an existing action set from JFace
actions to use handlers. Mainly I cannot figure out how why the visible menu
item within the main menu is not changing it's enabled state.

I'm starting from an existing action set definition contributing a new menu
to the Eclipse main menu bar. The menu is filled with a set of actions which
are associated with JFace actions via the "class" attribute of an action
definition. Each action definition is associated additionally with a
command. The commands are all definied via the org.eclipse.ui.commands
extension point. The enablement of the actions are a mixture of the
subelement "enablement" and selectionChanged implementations within the
JFace actions. So far, this had been and is working as expected.

Now I do want to migrate this to use handlers as it is desired that
extenders shall replace the action/handler to customize enablement and
execution logic.

- I do have a handler which is listening to the parts selection changed
events, passing them on to the old JFace action for evaluation (via
org.eclipse.jface.commands.ActionHandler) and firing an HandlerEvent for the
handler to tell when the enablement of the handler (== enablement of the old
JFace action) has changed.

- I removed the "class" attribute from the action sets action definition and
associated the handler as default handler to the command. That way the
handler does not even get instanciated (until Eclipse is shutting down which
is a bit wierd and to late). Isn't the default handler supposed to be used
if no other handler is registered for the command (and in this case there is
no other)?

- Ok. Default handler is not working, register the handler explicitly via
org.eclipse.ui.handlers. First hand without any other subelement, because I
explicitly wanted to have the handler active for everywhere for a start.
First I want to have it working, than I can worry about plugin activations.
Registering the handler that way is not instanciating the handler as well
until I put back in the class attribute to the action definition. Any
explanation?

- Ok. Taking out the class attribute again, add "activeWhen" subelement to
the handler and use the activePartId for activation. Now the handler gets
activated and behaves so far as desired, but the menu item within the menu
is always grayed out, even if the handler is enabled.

How can I update the menu item to change the enabled state together with the
handler? I've read all the nice wiki pages
(http://wiki.eclipse.org/Menu_Contributions and others) but still cannot
figure it out. I've tried implementing IElementUpdater and explicitly
triggering an refreshElement via the ICommandService, updateElement is never
called. Is there is any migration guide desribing how to go from the action
framework to the command/handler framework for common action contribution
types (popupMenus, viewActions, actionSets ...)?

Any help is appreciated.

Thanks, Regards,

--
Uwe Stieber
Re: Migrating action sets from JFace actions to handlers [message #325398 is a reply to message #325392] Sun, 17 February 2008 21:20 Go to previous messageGo to next message
Eclipse UserFriend
Which version of eclipse are you using? Due to bugs and the way the
features were implemented 3.3 and 3.4 are different.

Uwe Stieber wrote:
> Hi,
> I do have some trouble in migrating an existing action set from JFace
> actions to use handlers. Mainly I cannot figure out how why the visible menu
> item within the main menu is not changing it's enabled state.
>
> I'm starting from an existing action set definition contributing a new menu
> to the Eclipse main menu bar. The menu is filled with a set of actions which
> are associated with JFace actions via the "class" attribute of an action
> definition. Each action definition is associated additionally with a
> command. The commands are all definied via the org.eclipse.ui.commands
> extension point. The enablement of the actions are a mixture of the
> subelement "enablement" and selectionChanged implementations within the
> JFace actions. So far, this had been and is working as expected.
>
> Now I do want to migrate this to use handlers as it is desired that
> extenders shall replace the action/handler to customize enablement and
> execution logic.
>
> - I do have a handler which is listening to the parts selection changed
> events, passing them on to the old JFace action for evaluation (via
> org.eclipse.jface.commands.ActionHandler) and firing an HandlerEvent for the
> handler to tell when the enablement of the handler (== enablement of the old
> JFace action) has changed.
>
> - I removed the "class" attribute from the action sets action definition and
> associated the handler as default handler to the command. That way the
> handler does not even get instanciated (until Eclipse is shutting down which
> is a bit wierd and to late). Isn't the default handler supposed to be used
> if no other handler is registered for the command (and in this case there is
> no other)?
>
> - Ok. Default handler is not working, register the handler explicitly via
> org.eclipse.ui.handlers. First hand without any other subelement, because I
> explicitly wanted to have the handler active for everywhere for a start.
> First I want to have it working, than I can worry about plugin activations.
> Registering the handler that way is not instanciating the handler as well
> until I put back in the class attribute to the action definition. Any
> explanation?
>
> - Ok. Taking out the class attribute again, add "activeWhen" subelement to
> the handler and use the activePartId for activation. Now the handler gets
> activated and behaves so far as desired, but the menu item within the menu
> is always grayed out, even if the handler is enabled.
>
> How can I update the menu item to change the enabled state together with the
> handler? I've read all the nice wiki pages
> (http://wiki.eclipse.org/Menu_Contributions and others) but still cannot
> figure it out. I've tried implementing IElementUpdater and explicitly
> triggering an refreshElement via the ICommandService, updateElement is never
> called. Is there is any migration guide desribing how to go from the action
> framework to the command/handler framework for common action contribution
> types (popupMenus, viewActions, actionSets ...)?
>
> Any help is appreciated.
>
> Thanks, Regards,
>
Re: Migrating action sets from JFace actions to handlers [message #325439 is a reply to message #325392] Mon, 18 February 2008 16:29 Go to previous messageGo to next message
Eclipse UserFriend
I read through your message, and I think that trying to mix actions and
the command handlers is very complicated. I recommend stepping away
from actions entirely and just moving to commands/handlers. For your
menus, use the org.eclipse.ui.menus extension point to bind the commands
to the menus.

If you want to change handlers based on which part is active, you can do
something like this in your code:

IHandlerService handlerService = (IHandlerService)part.getSite()
.getService(IHandlerService.class);

handlerService.activateHandler(ID_COMMAND_COPY, new
AbstractHandler()
{
public Object execute(ExecutionEvent event)
throws ExecutionException
{
<do the work>
return null;
}
});

HTH,

Francis


Uwe Stieber wrote:
> Hi,
> I do have some trouble in migrating an existing action set from JFace
> actions to use handlers. Mainly I cannot figure out how why the visible menu
> item within the main menu is not changing it's enabled state.
>
> I'm starting from an existing action set definition contributing a new menu
> to the Eclipse main menu bar. The menu is filled with a set of actions which
> are associated with JFace actions via the "class" attribute of an action
> definition. Each action definition is associated additionally with a
> command. The commands are all definied via the org.eclipse.ui.commands
> extension point. The enablement of the actions are a mixture of the
> subelement "enablement" and selectionChanged implementations within the
> JFace actions. So far, this had been and is working as expected.
>
> Now I do want to migrate this to use handlers as it is desired that
> extenders shall replace the action/handler to customize enablement and
> execution logic.
>
> - I do have a handler which is listening to the parts selection changed
> events, passing them on to the old JFace action for evaluation (via
> org.eclipse.jface.commands.ActionHandler) and firing an HandlerEvent for the
> handler to tell when the enablement of the handler (== enablement of the old
> JFace action) has changed.
>
> - I removed the "class" attribute from the action sets action definition and
> associated the handler as default handler to the command. That way the
> handler does not even get instanciated (until Eclipse is shutting down which
> is a bit wierd and to late). Isn't the default handler supposed to be used
> if no other handler is registered for the command (and in this case there is
> no other)?
>
> - Ok. Default handler is not working, register the handler explicitly via
> org.eclipse.ui.handlers. First hand without any other subelement, because I
> explicitly wanted to have the handler active for everywhere for a start.
> First I want to have it working, than I can worry about plugin activations.
> Registering the handler that way is not instanciating the handler as well
> until I put back in the class attribute to the action definition. Any
> explanation?
>
> - Ok. Taking out the class attribute again, add "activeWhen" subelement to
> the handler and use the activePartId for activation. Now the handler gets
> activated and behaves so far as desired, but the menu item within the menu
> is always grayed out, even if the handler is enabled.
>
> How can I update the menu item to change the enabled state together with the
> handler? I've read all the nice wiki pages
> (http://wiki.eclipse.org/Menu_Contributions and others) but still cannot
> figure it out. I've tried implementing IElementUpdater and explicitly
> triggering an refreshElement via the ICommandService, updateElement is never
> called. Is there is any migration guide desribing how to go from the action
> framework to the command/handler framework for common action contribution
> types (popupMenus, viewActions, actionSets ...)?
>
> Any help is appreciated.
>
> Thanks, Regards,
>
Re: Migrating action sets from JFace actions to handlers [message #325450 is a reply to message #325439] Tue, 19 February 2008 05:21 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
Thanks for the replies. I'll look into using org.eclipse.ui.menus for
defining the global menu.
Thanks, Uwe :-)

>I read through your message, and I think that trying to mix actions and the
>command handlers is very complicated. I recommend stepping away from
>actions entirely and just moving to commands/handlers. For your menus, use
>the org.eclipse.ui.menus extension point to bind the commands to the menus.
>
> If you want to change handlers based on which part is active, you can do
> something like this in your code:
>
> IHandlerService handlerService = (IHandlerService)part.getSite()
> .getService(IHandlerService.class);
>
> handlerService.activateHandler(ID_COMMAND_COPY, new
> AbstractHandler()
> {
> public Object execute(ExecutionEvent event)
> throws ExecutionException
> {
> <do the work>
> return null;
> }
> });
>
> HTH,
>
> Francis
>
>
> Uwe Stieber wrote:
>> Hi,
>> I do have some trouble in migrating an existing action set from JFace
>> actions to use handlers. Mainly I cannot figure out how why the visible
>> menu item within the main menu is not changing it's enabled state.
>>
>> I'm starting from an existing action set definition contributing a new
>> menu to the Eclipse main menu bar. The menu is filled with a set of
>> actions which are associated with JFace actions via the "class" attribute
>> of an action definition. Each action definition is associated
>> additionally with a command. The commands are all definied via the
>> org.eclipse.ui.commands extension point. The enablement of the actions
>> are a mixture of the subelement "enablement" and selectionChanged
>> implementations within the JFace actions. So far, this had been and is
>> working as expected.
>>
>> Now I do want to migrate this to use handlers as it is desired that
>> extenders shall replace the action/handler to customize enablement and
>> execution logic.
>>
>> - I do have a handler which is listening to the parts selection changed
>> events, passing them on to the old JFace action for evaluation (via
>> org.eclipse.jface.commands.ActionHandler) and firing an HandlerEvent for
>> the handler to tell when the enablement of the handler (== enablement of
>> the old JFace action) has changed.
>>
>> - I removed the "class" attribute from the action sets action definition
>> and associated the handler as default handler to the command. That way
>> the handler does not even get instanciated (until Eclipse is shutting
>> down which is a bit wierd and to late). Isn't the default handler
>> supposed to be used if no other handler is registered for the command
>> (and in this case there is no other)?
>>
>> - Ok. Default handler is not working, register the handler explicitly via
>> org.eclipse.ui.handlers. First hand without any other subelement, because
>> I explicitly wanted to have the handler active for everywhere for a
>> start. First I want to have it working, than I can worry about plugin
>> activations. Registering the handler that way is not instanciating the
>> handler as well until I put back in the class attribute to the action
>> definition. Any explanation?
>>
>> - Ok. Taking out the class attribute again, add "activeWhen" subelement
>> to the handler and use the activePartId for activation. Now the handler
>> gets activated and behaves so far as desired, but the menu item within
>> the menu is always grayed out, even if the handler is enabled.
>>
>> How can I update the menu item to change the enabled state together with
>> the handler? I've read all the nice wiki pages
>> (http://wiki.eclipse.org/Menu_Contributions and others) but still cannot
>> figure it out. I've tried implementing IElementUpdater and explicitly
>> triggering an refreshElement via the ICommandService, updateElement is
>> never called. Is there is any migration guide desribing how to go from
>> the action framework to the command/handler framework for common action
>> contribution types (popupMenus, viewActions, actionSets ...)?
>>
>> Any help is appreciated.
>>
>> Thanks, Regards,
>>
Re: Migrating action sets from JFace actions to handlers [message #325463 is a reply to message #325450] Tue, 19 February 2008 10:05 Go to previous message
Eclipse UserFriend
Hi Uwe,

In http://wiki.eclipse.org/Menu_Contributions it should describe how to
match an actionSet to the new org.eclipse.ui.menus contribution as a
command with a visibleWhen clause.

You can remove all of the "action" elements from your actionSet and use
the default handler for your command ... that should work fine. Your
selection/enablement statements from your action should become
enabledWhen clauses (you'll need to change from old expression to core
expression) when specifying the default handler (you just need to use
org.eclipse.ui.handlers and not the defaultHandler attribute of the
command).

Later,
PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse. platform.doc.isv/guide/workbench.htm
Previous Topic:Could I return some value when I use Command?
Next Topic:Why it is disabled ??
Goto Forum:
  


Current Time: Sun Jun 01 07:42:19 EDT 2025

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

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

Back to the top