How to trigger property invalidation?
lehmann at media-interactive.de
Sun Nov 4 10:43:44 PST 2012
Thanks to everyone who responded. Let me combine my rpelies in this
email to avoid spamming the list too much.
On 02.11.2012 17:30, Richard Bair wrote:
> In Region we have a custom property that we can use to force
invalidation. Is this sort of what you're looking for?
More or less. But this seems like a new implementation of a property
interface, with manual listener management etc. It is not a problem,
technically, but reinvents the wheel. The existing wheel already has a
markInvalid method, unfortunately it is private, not protected.
Everything else would be fine.
This reminds me of using POJOs for a TableView. It is easy to get the
data into the control using a PropertyValueFactory. But it is quite hard
to have the control update itself (or a cell) if I know that property X
of POJO Y has changed. Again, this could be solved simply by providing
an invalidate method on the TableView (or PropertyValueFactory). Without
this you need to write a lot of code to make this happen (basically
provide observable values wrapping each POJO bean in a generic way -
which is not trivial as recently discussed on this list, blackmagic etc).
On 02.11.2012 19:12, Martin Sladecek wrote:
> Hi Werner,
> maybe an ObjectProperty isn't really what you are looking for. If you
> have single bean with an non-observable property (BTW, how do you know
> it has changed?) and you want to convert it to an FX property, why not
> using a property of the same type as MyBean.myProperty and set FX
> property when myProperty changes?
Basically I made an FX custom control which serves as editor for a
domain bean (nothing too fancy).
To understand this better, assume the following example. Let the bean
represent an employee with first name, last name, address, etc
properties. The editor would look like a form with text fields for this
stuff. I figured it would be neat to have an observable "employee"
property on that editor control:
- set an employee value to initialize the editor control,
- get an employee to retrieve the currently edited employee state, and
- add a property listener to implement a dirty flag or somesuch.
Obviously the editor knows when the employee changes. But it cannot
simply invalidate the property when only the address changes (assuming
that address is another bean).
I am working around this by creating a whole new employee instance with
just a tiny change over the original employee so that I can assign this
to the property, thus forcing invalidation. To make things worse, in my
case I am using a slider to represent a zoom level - and that creates a
lot of noise (every move of the slider triggers a copy of the bean).
On 02.11.2012 19:46, Will Hoover wrote:
> ...or you could use a BeanPathAdapter that handles all your POJO field to
> JFX property conversions for you (http://wp.me/P2rLDc-1s) and listen for
> changes to the bean:
Will, I have seen your articles and really liked to read about this
because it seemed to solve a problem I had (see above about the
TableView problem). This may be something to revisit later for me. Right
now it seems a little bit over the top, plus I am not at liberty to
require J7+, unfortunately.
More information about the openjfx-dev