Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to define commands from code
How to define commands from code [message #326299] Fri, 14 March 2008 07:24 Go to next message
Eclipse UserFriend
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 12:42 Go to previous message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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


Previous Topic:deployed my gmf plug-in
Next Topic:Feature as "Jar"
Goto Forum:
  


Current Time: Thu Jun 27 20:04:51 GMT 2024

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

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

Back to the top