Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » objectContribution action -> command
objectContribution action -> command [message #289502] Fri, 05 August 2005 20:24 Go to next message
Eclipse UserFriend
Originally posted by: chrismo.clabs.org

I have something like the following in my plugin.xml. The key binding
appears on my popup menu contribution just fine -- but typing the key
binding yields nothing at all. It seems this is all I need to do to hook
my action to the command -- but all of the Help on this topic seems to
talk about action /Sets/, not just any ol' action, so I'm wondering if
that's my problem here, that my action is relegated to a popupMenu
extension, and the keystroke can't cross the divide to get to it. The
frustrating thing is that I see the key binding text on my popupMenu
contribution at runtime -- what am I missing?

<extension point="org.eclipse.ui.popupMenus">
....
<objectContribution
objectClass="org.eclipse.jdt.core.IJavaElement"
id="com.einstruction.eclipse.plugin.cpsassist.contribution2 ">
<action
class="com.einstruction.eclipse.plugin.cpsassist.RunThing"

definitionId="com.einstruction.eclipse.plugin.cpsassist.command.RunThing "
enablesFor="1"
id="com.einstruction.eclipse.plugin.cpsassist.runthing"
label="Run Thing"
menubarPath="com.einstruction.eclipse.plugin.menu/group1"/ >
<visibility>
<or>
<objectClass name="org.eclipse.jdt.core.IMember" />
<objectClass name="org.eclipse.jdt.core.ICompilationUnit" />
</or>
</visibility>
</objectContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<category
id="com.einstruction.eclipse.plugin.cpsassist.category"
name="CPS Assistant"/>
<command
categoryId="com.einstruction.eclipse.plugin.cpsassist.category "
id="com.einstruction.eclipse.plugin.cpsassist.command.RunThing "
name="Run Thing">
</command>
</extension>
<extension
point="org.eclipse.ui.bindings">
<key

commandId="com.einstruction.eclipse.plugin.cpsassist.command.RunThing "
platform="win32"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="ALT+SHIFT+E T"/>
</extension>


--
Chris
http://clabs.org
Re: objectContribution action -> command [message #289602 is a reply to message #289502] Mon, 08 August 2005 17:28 Go to previous message
Eclipse UserFriend
Originally posted by: douglas.pollock.magma.ca

Chris Morris wrote:
> frustrating thing is that I see the key binding text on my popupMenu
> contribution at runtime -- what am I missing?

One of the unfortunate things about how the key binding architecture
currently works is that objectContributions do not automatically handle
commands.

So, let's take a look at an example. If you make an action set, and set the
definition id, then the action becomes the handler for the command ... for
free. You don't have to do anymore work.

If you have an object contribution, it knows that it is associated with the
command ... but it doesn't go that extra step and become the handler. The
handler is what actually carries out some behaviour when a key is pressed.

I didn't write the original code, so I'm not entirely sure why this omission
was made. I can only imagine that it has something to do with performance.


So, what do you do? Well one option is to make your command as follows:

<command
categoryId="com.einstruction.eclipse.plugin.cpsassist.category "
id="com.einstruction.eclipse.plugin.cpsassist.command.RunThing "
name="Run Thing"
defaultHandler="MyHandler" />

And then get the handler and the object contribution delegate to communicate
through a singelton somewhere:

public class MyHandler extends AbstractHandler {
behaviour = MyBehaviour.singleton();
public Object execute(ExecutionEvent e) {
return behaviour.execute(e);
}
}

public class RunThing ... {
behaviour = MyBehaviour.singleton();
...
}

This way the handler and the action don't know about each other directly,
but yet share the same underlying state and behaviour. This way,
interaction with the command through the menu and through a key binding
will have the same effect.



d.
Previous Topic:Eclipse crashes when linking my project
Next Topic:MacOS X bundle export jar file name
Goto Forum:
  


Current Time: Thu Apr 25 15:20:10 GMT 2024

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

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

Back to the top