Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Eclipse 3.6: org.eclipse.ui.commands.IElementUpdater - How to update before beeing executed?
Eclipse 3.6: org.eclipse.ui.commands.IElementUpdater - How to update before beeing executed? [message #633656] Mon, 18 October 2010 17:28 Go to next message
Jan Kohnert is currently offline Jan KohnertFriend
Messages: 192
Registered: July 2009
Senior Member
Hello,

I've some commands that have org.eclipse.ui.handlers that implement their behavior. This handlers implement org.eclipse.ui.commands.IElementUpdater to update the label and description of the menu entries being used. I discovered that as long one command has not been executed, its handler stays uninitialized and thus the updateElement is not getting executed at all.
How can I make the handler to get created (I realy mean created, calling c'tor and stuff, not executed) before the command has been used? It's hard to explain when commands have proper labeling after being used, but not before... Smile

Thanks!
Re: Eclipse 3.6: org.eclipse.ui.commands.IElementUpdater - How to update before beeing executed? [message #633768 is a reply to message #633656] Tue, 19 October 2010 10:57 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
On 18/10/10 10:58 PM, Jan Kohnert wrote:
> I've some commands that have org.eclipse.ui.handlers that implement
> their behavior. This handlers implement
> org.eclipse.ui.commands.IElementUpdater to update the label and
> description of the menu entries being used. I discovered that as long
> one command has not been executed, its handler stays uninitialized and
> thus the updateElement is not getting executed at all. How can I make
> the handler to get created (I realy mean created, calling c'tor and
> stuff, not executed) before the command has been used? It's hard to
> explain when commands have proper labeling after being used, but not
> before... :)

Eclipse tries lazy loading of the plugins. So unless your plugin is
loaded, the updateElement of your handler won't be called. You can
probably extend org.eclipse.ui.startup to activate your plugin, which
should be done with care, as if affects the Eclipse startup performance.

What is your usecase?

- Prakash
Platform UI Team, IBM

www.eclipse-tips.com
Re: Eclipse 3.6: org.eclipse.ui.commands.IElementUpdater - How to update before beeing executed? [message #777563 is a reply to message #633656] Tue, 10 January 2012 17:49 Go to previous messageGo to next message
Robert Longo is currently offline Robert LongoFriend
Messages: 3
Registered: March 2011
Junior Member
I believe that this is a bug in Eclipse. Here's the work-around:

Initializing the Handler

It may happen that your radio menu contributions are not initialized the first time the menu is displayed. This is because at this time, your Handler might not yet have been instantiated (this is due to Eclipse's lazy loading policy). If this is the case, you can enforce the instantiation of your Handler within the Activator of your plug-in. Just add the following code to the start(BundleContext) method:

UIJob job = new UIJob("InitCommandsWorkaround") {
 
    public IStatus runInUIThread(@SuppressWarnings("unused") IProgressMonitor monitor) {
 
        ICommandService commandService = (ICommandService) PlatformUI
            .getWorkbench().getActiveWorkbenchWindow().getService(
                ICommandService.class);
        Command command = commandService.getCommand("z.ex.dropdown.radio");
        command.isEnabled();
        return new Status(IStatus.OK,
            "my.plugin.id",
            "Init commands workaround performed succesfully");
    }
 
};
job.schedule();
Re: Eclipse 3.6: org.eclipse.ui.commands.IElementUpdater - How to update before beeing executed? [message #778693 is a reply to message #777563] Fri, 13 January 2012 16:39 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

I'll just point out 2 things:

1) The pattern for creating radio menus or toggle menus/buttons using commands can be found at http://blog.eclipse-tips.com/2009/03/commands-part-6-toggle-radio-menu.html

2) It's perfectly acceptable to early-start your bundle in an RCP app. It's generally less acceptable in the community to early start a UI bundle, except in a few circumstances. The "correct enablement" of a menu item is not one of those circumstances.

PW


Previous Topic:Why JFace Text uses partitions?
Next Topic:Shared Workspace
Goto Forum:
  


Current Time: Fri Nov 28 21:08:09 GMT 2014

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

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