UI updates

What is the best mechanism to signal the UI that a model has changed or vice versa? For example, if I select an item in a tree, and a button has to change from disabled to enabled, what events do I fire? Do I go the old-skool way of adding TreeSelectionListeners and keeping a EventListenersList, or do I use the MessageBus features? Or is there something else?

2 comments
Comment actions Permalink

For future readers, the update() method of AnAction is called automatically if the parent where the UI element lives receives some MouseEvent or KeyboardEvent, so no need to call that yourself. In update(), you can call e.getPresentation() to modify the state.

0
Comment actions Permalink

Actually, the update() method of AnAction is called every 500ms in case of buttons in toolbar to avoid any extra listeners, subscriptions and leaks. So, implement your update() method to be as quick as possible. Otherwise you may freeze UI.

0

Please sign in to leave a comment.