Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Wrong handler activation
Wrong handler activation [message #946444] Tue, 16 October 2012 07:54 Go to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi all,

I discovered a strange behavior with handler activation.

I have a command
<command categoryId="myCategory" id="myCommand"></command>

two handlers for that command
<handler class="EditorHandler" commandId="myCommand">
    <activeWhen>
        <reference definitionId="myReference"></reference>
    </activeWhen>
</handler>
<handler class="SelectionHandler" commandId="myCommand">
    <activeWhen>
        <iterate ifEmpty="false" operator="and">
            <instanceof value="SelectableObject"></instanceof>
         </iterate>
    </activeWhen>
</handler>

and a core expression definition
<definition id="myReference">
    <with variable="activeEditorId">
        <equals value="editorWithSelectedObjectId"></equals>
    </with>
</definition>

The SelectionHandler should be active only when the workbench selection contains instances of a SelectableObject.
The EditorHandler should be active only when a specific editor is active.

There are two editors, the first one is the one with editorWithSelectedObjectId id. It has no selection provider registered with its site.
The second one is an editor containing a table of SelectableObjects, so it has registered a selection provider with its site.

I put the command in main toolbar and open the editor with a table of SelectableObjects.
The SelectionHandler becomes active (ok). Now I open the second editor and the SelectionHandler is still active (bad)!! When I try it next time (the application must be restarted), the EditorHandler becomes active as it should (ok). This happens randomly. It looks like the sequence of handler activation matters or something.

Sometimes the SelectionHandler stay active forever. No matter what editor or view is active.

Does anybody have an idea what's going here? Thanks
Re: Wrong handler activation [message #946755 is a reply to message #946444] Tue, 16 October 2012 13:22 Go to previous message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
I got it. I have another handler
<handler class="deleteHandler" commandId="deleteCommandId">
    <activeWhen>
        <iterate operator="and">
            <instanceof value="SelectableObject"></instanceof>
         </iterate>
    </activeWhen>
</handler>

Note that it does't have defined ifEmpty parameter and also note that it has the same expressions as SelectionHandler above.

When platform starts it reads all contributed handlers. For all handlers with the same expression it evaluate this expression only once - from the first one contribution that is read.
Then it uses this cached evaluation result for all other handlers with that expression. See (HandlerAuthority.calss, EvaluationResultCache.class and IterateExpression.class).

So when the first loaded handler was the deleteHandler, it evaluates its expression as true, because the default context variable is a collection (empty during startup) and the IterateExpression evaluate itself against empty collection without ifEmpty as true.

This also activated the SelectionHandler, because it has the same expression, so it uses the cached version.
Previous Topic:SWT Browser Compatibility
Next Topic:[CNF] Tooltips on CommonViewer
Goto Forum:
  


Current Time: Thu Mar 28 15:32:46 GMT 2024

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

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

Back to the top