How to override a standard command handler? [message #498009] |
Fri, 13 November 2009 16:52 |
Yves Monier Messages: 9 Registered: November 2009 |
Junior Member |
|
|
I develop on top of the WTP plugins, especially the XML editor. In some cases I'd like the "Add Block Comment" (Remove Block Comment as well) command to behave differently.
I think this is not a WTP-specific question but more a command-handler framework question.
What I did:
1) searched in WTP sources how the Add Block Comment command was implemented: I found the plugin.xml that declares various menuContributions and the <extension
point="org.eclipse.ui.handlers"> that defines this handler:
<handler
class=" org.eclipse.wst.xml.ui.internal.handlers.AddBlockCommentHand ler "
commandId="org.eclipse.wst.sse.ui.add.block.comment">
<activeWhen>
<reference definitionId="org.eclipse.wst.xml.ui.comments"/>
</activeWhen>
<enabledWhen>
<reference definitionId="org.eclipse.wst.xml.ui.comments"/>
</enabledWhen>
</handler>
2) in my plugin.xml, I added a similar definition, just replacing the class and hoping this would be enough to override the standard WTP's AddBlockCommentHandler. Of course ... this didn't work...
3) I used the following debug.options:
org.eclipse.ui/debug=true
org.eclipse.ui/trace/keyBindings=true
org.eclipse.ui/trace/keyBindings.verbose=true
org.eclipse.ui/trace/sources=true
org.eclipse.ui/trace/handlers=true
org.eclipse.ui/trace/handlers.verbose=true
#org.eclipse.ui/trace/handlers.verbose.commandId=org.eclipse .ui.edit.copy
org.eclipse.ui/trace/handlers.verbose.commandId=org.eclipse. wst.sse.ui.add.block.comment
org.eclipse.ui/trace/contexts=true
org.eclipse.ui/trace/contexts.verbose=true
this told me that I had an unresolved conflict between the two handlers. Seems that in such case the command is disabled, right?
4) in case of conflict Eclipse keeps the handler with the highest priority, priorities depending on activeWhen conditions. Therefore I added an extra condition to my handler:
<activeWhen>
<and>
<reference definitionId="org.eclipse.wst.xml.ui.comments"/>
<with variable="activeEditorId">
<iterate operator="or">
<equals value="com.temis.scs.editors.SCStructuredTextEditor.scp"/>
<equals value="com.temis.scs.editors.SCStructuredTextEditor.sct"/>
<equals value="com.temis.scs.editors.SCStructuredTextEditor.tsl"/>
</iterate>
</with>
</and>
</activeWhen>
I added breakpoints in HandlerAuthority, HandlerActivation and some ExpressionXXXX classes, and noticed that my handler actually had a higher priority than the standard one: fine! Still, the default handler was called later at runtime
5) it happens that, at startup, both handled are not active, probably due to their common condition (<reference definitionId="org.eclipse.wst.xml.ui.comments"/>). In such case (only inactive handlers) it seems that HandlerAuthority.resolveConflicts keeps the last one, without considering the priority. In my case the last one is the WTP handler...
boolean conflict = false;
while (activationItr.hasNext()) {
currentActivation = (IHandlerActivation) activationItr.next();
if (!evaluate(currentActivation)) {
continue; // only consider potentially active handlers
}
[......]
if (bestActivation == null) {
bestActivation = currentActivation;
conflict = false;
continue;
}
[......]
}
I may post this question to the WTP forum too, with more focus on my specific need (the AddBlockComment of the XML editor)...
But, more generally, my question is: how to override a standard/existing Eclipse handler, using state-of-the-art techniques?
Hope my problem description is clear enough!
Thanks in advance for any help...
Best regards,
Yves Monier
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04035 seconds