From b639b3b471054f38218b909a3a6e9843e0ebba12 Mon Sep 17 00:00:00 2001 From: Frederik Kammel Date: Tue, 7 Nov 2023 11:12:03 +0100 Subject: [PATCH] PropertyEditors now subscribe to the item's ObservableValue even if the editor is read-only (#1512) --- .../editor/AbstractPropertyEditor.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/controlsfx/src/main/java/org/controlsfx/property/editor/AbstractPropertyEditor.java b/controlsfx/src/main/java/org/controlsfx/property/editor/AbstractPropertyEditor.java index 5a3cc8020..9268611fa 100644 --- a/controlsfx/src/main/java/org/controlsfx/property/editor/AbstractPropertyEditor.java +++ b/controlsfx/src/main/java/org/controlsfx/property/editor/AbstractPropertyEditor.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2013, ControlsFX + * Copyright (c) 2013, 2023, ControlsFX * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,6 +79,15 @@ public AbstractPropertyEditor(Item property, C control) { public AbstractPropertyEditor(Item property, C control, boolean readonly) { this.control = control; this.property = property; + + property.getObservableValue().ifPresent(obs -> obs.addListener((ObservableValue o, Object oldValue, Object newValue) -> { + if (!suspendUpdate) { + suspendUpdate = true; + AbstractPropertyEditor.this.setValue((T) property.getValue()); + suspendUpdate = false; + } + })); + if (! readonly) { getObservableValue().addListener((ObservableValue o, Object oldValue, Object newValue) -> { if (! suspendUpdate) { @@ -87,17 +96,6 @@ public AbstractPropertyEditor(Item property, C control, boolean readonly) { suspendUpdate = false; } }); - - if (property.getObservableValue().isPresent()) { - property.getObservableValue().get().addListener((ObservableValue o, Object oldValue, Object newValue) -> { - if (! suspendUpdate) { - suspendUpdate = true; - AbstractPropertyEditor.this.setValue((T) property.getValue()); - suspendUpdate = false; - } - }); - } - } }