Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » When is SapphireCondition.evaluate() executed?
When is SapphireCondition.evaluate() executed? [message #781649] Sat, 21 January 2012 22:49 Go to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Hi,
When defining general actions in sapphire-extention.xml,
does an action handler's condition class evaluate() the handler's applicability every time the menu is opened or once per node?
I'm trying to dynamically play around with the actions' enablement and I'm seeing some non consistent behavior.
Thought I'd make sure my original assumption is correct.
Thanks,
Roded
Re: When is SapphireCondition.evaluate() executed? [message #781667 is a reply to message #781649] Sun, 22 January 2012 00:03 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The applicability condition is only checked the first time part's (node in this case) actions are requested, but once your action handler is initialized, you can control its enablement dynamically. Just listen on whatever influences your enablement statement and call setEnabled() method on the action handler. The menu items will reflect the updated enablement state.

- Konstantin

Re: When is SapphireCondition.evaluate() executed? [message #781785 is a reply to message #781667] Sun, 22 January 2012 08:58 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
My enablement also depends on the selected node in the outline tree.
Is there a recommended location to add a listener on the tree's selection changed event?
Re: When is SapphireCondition.evaluate() executed? [message #782404 is a reply to message #781785] Mon, 23 January 2012 16:56 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
You shouldn't need to track selection. A separate instance of an action handler is created for each node and it knows the part/node that it belongs to. You can access the part via getPart() API on the action handler.

- Konstantin
Re: When is SapphireCondition.evaluate() executed? [message #782410 is a reply to message #781785] Mon, 23 January 2012 16:56 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 14
Registered: July 2009
Junior Member
You shouldn't need to track selection. A separate instance of an action handler is created for each node and it knows the part/node that it belongs to. You can access the part via getPart() API on the action handler.

- Konstantin
Re: When is SapphireCondition.evaluate() executed? [message #782416 is a reply to message #781785] Mon, 23 January 2012 16:56 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 14
Registered: July 2009
Junior Member
You shouldn't need to track selection. A separate instance of an action handler is created for each node and it knows the part/node that it belongs to. You can access the part via getPart() API on the action handler.

- Konstantin
Re: When is SapphireCondition.evaluate() executed? [message #782426 is a reply to message #781785] Mon, 23 January 2012 16:56 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 14
Registered: July 2009
Junior Member
You shouldn't need to track selection. A separate instance of an action handler is created for each node and it knows the part/node that it belongs to. You can access the part via getPart() API on the action handler.

- Konstantin
Re: When is SapphireCondition.evaluate() executed? [message #782444 is a reply to message #782410] Mon, 23 January 2012 17:57 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Good points, thanks.
That saved me quite a bit of code and a performance hit.
So as I understand it, there's no way to compute validation on a node's handler once the right click menu is opened.
It has to be done for all relevant handlers when the condition is changed.
I resorted to saving references to all my handlers and computing their enablement when the condition that affects it changes.
Re: When is SapphireCondition.evaluate() executed? [message #782472 is a reply to message #782444] Mon, 23 January 2012 19:26 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
There is no "menu opened" callback. Sapphire architecture generally favors pushing of updates and letting the system react as opposed to pulling to see if anything has changed. If you have a way to tell when your input data is changing, the simplest thing to do is to make your handler listen on that change event and then update itself. Just remember to remove the listener when handler is disposed. I would try to avoid saving references to all the handlers as that can cause you lifecycle complications.

- Konstantin
Re: When is SapphireCondition.evaluate() executed? [message #782473 is a reply to message #782472] Mon, 23 January 2012 19:27 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Thanks Konstantin.
Re: When is SapphireCondition.evaluate() executed? [message #782720 is a reply to message #782473] Tue, 24 January 2012 09:47 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
SapphireActionSystemPart's dispose() is final.
How should I remove the listener on dispose of the handler? Am I missing something?
As a workaround, I added a listener to each handler to catch the DisposeEvent and remove the listener.
Thanks
Re: When is SapphireCondition.evaluate() executed? [message #783252 is a reply to message #782720] Wed, 25 January 2012 11:05 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Listening on the dispose event is the correct solution for handling on dispose cleanup.

- Konstantin
Previous Topic:Connection Bindings
Next Topic:Eclipse Magazin article (german) about Sapphire
Goto Forum:
  


Current Time: Sun Nov 27 20:26:18 GMT 2022

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

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

Back to the top