| 
| How to define commands from code [message #326299] | Fri, 14 March 2008 03:24  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: newsgroups.atante.pl 
 Hi,
 am I able to define command + handler + key from the code?
 For now I do it by implementing extensions in plugin.xml:
 1) set command id,
 2) set handler for this command id,
 3) set default key with the scheme to add it to.
 
 In my application I build menu from database and want to create
 commands on the fly, set handlers for them and define default key shortcuts,
 with assigned scheme (I've created one) depending on what I've read from
 database.
 
 Is it possible? If yes, give me some example, please...
 
 --
 Piotr Górny, Atante
 http://www.atante.pl
 |  |  |  | 
| 
| Re: How to define commands from code [message #326311 is a reply to message #326299] | Fri, 14 March 2008 08:42  |  | 
| Eclipse User  |  |  |  |  | Piotr Górny wrote: > Hi,
 > am I able to define command + handler + key from the code?
 > For now I do it by implementing extensions in plugin.xml:
 > 1) set command id,
 > 2) set handler for this command id,
 > 3) set default key with the scheme to add it to.
 >
 > In my application I build menu from database and want to create
 > commands on the fly, set handlers for them and define default key
 > shortcuts,
 > with assigned scheme (I've created one) depending on what I've read from
 > database.
 
 This is possible with some hand waving ... but not recommended.  Many of
 the systems involved aren't overly dynamic.  You can create and define a
 command using ICommandService, and then activate the handler using the
 IHandlerService.  To add a bunch of keybindings you'll have to create
 KeyBinding objects with type of Binding.USER, add them to the existing
 bindings, and then set them on the IBindingService.  Check out how the
 NewKeysPreferencePage deals with the IBindingService and BindingManager.
 
 
 
 How can you dynamically provide a command and its handler without a
 plugin (handler being code)?  And if you're already providing the
 handler, would you also be providing the pre-canned command IDs that go
 with them?
 
 One thing to consider ... you can create a data-plugin somewhere with a
 boilerplate MANIFEST.MF and a generated plugin.xml, and then tell OSGi
 to load it using BundleContext and the PackageAdmin service.  See
 org.eclipse.ui.tests.dynamicplugins.DynamicUtils in org.eclipse.ui.tests
 for an example.
 
 --
 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
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.03933 seconds