Thank you for the pointers Chris, that gave me some ideas. Actually, all
my domain objects extend a base class that implements
PropertyChangeSupport, so I might try to detect domain objects within
the focused component hieararchy and leave Pivot out of most of the
logic, that might be cleaner.
-- Edvin
Den 04.06.2011 06:58, skrev Chris Bartlett:
Edvin,
I am not aware of anything within Pivot that covers this sort of thing,
but you might find some of the Component Explorer tutorial source code
useful. Specifically the use of proxies for 'dynamic' notification &
filtering of events in the
org.apache.pivot.tutorials.explorer.tools.EventLogger class.
http://pivot.apache.org/demos/component-explorer.html
http://svn.apache.org/repos/asf/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/explorer/tools/EventLogger.java
A similar approach might work for you depending on your definition of
dirty. You would need Pivot to provide events that cover every possible
'mutation' of your data model (assuming that is what you mean by dirty).
If the events do not exist, I think you would have to create your own
event(s) for each Component, although I suppose you could wrap the
entire Component in a proxy and use that to intercept the calls to its
'mutating' methods.
While an event/notification based solution is probably cleaner, you
might also consider polling the target Components' state and comparing
to a known 'clean' state. Something like this might be workable if the
Components are only every manually changed (and therefore made dirty)
and you track and monitor the focused Component for changes (and/or
maybe track mouse position / mouseover)
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/ComponentClassListener.html#focusedComponentChanged(org.apache.pivot.wtk.Component)
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/wtk/Component.html#getComponentClassListeners()
Finally, BeanAdapter and BeanMonitor might also be useful at some point.
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/beans/BeanAdapter.html
http://pivot.apache.org/2.0/docs/api/org/apache/pivot/beans/BeanMonitor.html
Chris
On 4 June 2011 05:32, Edvin Syse <[email protected]
<mailto:[email protected]>> wrote:
I have a toolbar with a global Save-button that I would like to
enable only when I detect one or more components that are dirty
within the active "editor". The editor is just a component that
contains other components, mostly inside a Form.
I'm thinking about traversing the component hiararchy in my
"editor", and adding listeners for all components like for example
TextInputContentListener for TextInput fields and
ListButtonSelectionListener for ListButton etc.
Is there something in the framework I can use to achieve this?
-- Edvin