Skip to content

Commit

Permalink
PropertyEditors now subscribe to the item's ObservableValue even if t…
Browse files Browse the repository at this point in the history
…he editor is read-only (#1512)
  • Loading branch information
vatbub committed Nov 7, 2023
1 parent bf04d27 commit b639b3b
Showing 1 changed file with 10 additions and 12 deletions.
@@ -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
Expand Down Expand Up @@ -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<? extends Object> o, Object oldValue, Object newValue) -> {
if (! suspendUpdate) {
Expand All @@ -87,17 +96,6 @@ public AbstractPropertyEditor(Item property, C control, boolean readonly) {
suspendUpdate = false;
}
});

if (property.getObservableValue().isPresent()) {
property.getObservableValue().get().addListener((ObservableValue<? extends Object> o, Object oldValue, Object newValue) -> {
if (! suspendUpdate) {
suspendUpdate = true;
AbstractPropertyEditor.this.setValue((T) property.getValue());
suspendUpdate = false;
}
});
}

}
}

Expand Down

0 comments on commit b639b3b

Please sign in to comment.