[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.rcp] Overriding plugin.xml-supplied command handler

Hi everyone,

I'm trying to override a command handler declared on plugin.xml from inside a view. Is there a way to do it?

In plugin.xml, I declare a global handler for the "paste" command that looks like this:
<handler
class="lxx.actions.PasteItemsToClipboardHandler"
commandId="org.eclipse.ui.edit.paste">
<activeWhen>
<with variable="selection"> <test property="lxx.propertytesters.canPasteItems"></test> </with>
</activeWhen>
</handler>


(btw, this works and calls lxx.actions.PasteItemsToClipboardHandler whenever lxx.propertytesters.canPasteItems evaluates to True)

Now, in the view's CreatePartControl I have:

 public void createPartControl(Composite parent) {
      final IHandler myPasteHandler = new AbstractHandler() {
	 @Override
	 public Object execute(ExecutionEvent arg0) throws ExecutionException {
	   System.err.println("HELLO WORLD: MYPASTE");
	   return null;
        }
      };

IHandlerService service = (IHandlerService)getSite().
getService(IHandlerService.class);
service.activateHandler("org.eclipse.ui.edit.paste", myPasteHandler, Expression.TRUE);
// stuff... }


I would expect that myPastHandler would always override the handler declared inside the plugin.xml (note that we're passing Expression.TRUE to the activateHanlder) but unfortunately the converse seems to happen: the global handler gets called preferentially and myPastHandler only gets called whenever lxx.propertytesters.canPasteItems returns False. Is this the way it should work?

Any ideas on how to override a command handler declared on the plugin.xml?

thanks in advance,
p.