Skip to content

Commit

Permalink
39: Add strong reference to "inner" listener.
Browse files Browse the repository at this point in the history
Also updates TestFX.
  • Loading branch information
Robert Lichtenberger committed Apr 29, 2024
1 parent 4b01343 commit 2d0b142
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ repositories {
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testImplementation "org.testfx:testfx-junit5:4.0.16-alpha"
testImplementation "org.testfx:openjfx-monocle:jdk-12.0.1+2"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testImplementation "org.testfx:testfx-junit5:4.0.18"
testImplementation "org.testfx:openjfx-monocle:jdk-12.0.1+2"
testImplementation "org.hamcrest:hamcrest:2.1"

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/net/synedra/validatorfx/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class Check {
private List<Decoration> decorations = new ArrayList<>();
private Function<ValidationMessage, Decoration> decorationFactory;
private ChangeListener<? super Object> immediateListener;
private ChangeListener<? super Object> immediateWeakListener;
private ChangeListener<? super Object> immediateClearListener;
private ChangeListener<? super Object> immediateClearWeakListener;

public class Context {

Expand Down Expand Up @@ -97,9 +99,10 @@ public Check decoratingWith(Function<ValidationMessage, Decoration> decorationFa
*/
public Check immediate() {
removeAllListeners();
immediateListener = new WeakChangeListener<>((obs, oldv, newv) -> recheck());
immediateListener = (obs, oldv, newv) -> recheck();
immediateWeakListener = new WeakChangeListener<>(immediateListener);
for (ObservableValue<? extends Object> dependency : dependencies.values()) {
dependency.addListener(immediateListener);
dependency.addListener(immediateWeakListener);
}
Platform.runLater(this::recheck); // to circumvent problems with decoration pane vs. dialog
return this;
Expand All @@ -111,9 +114,10 @@ public Check immediate() {
*/
public Check immediateClear() {
removeAllListeners();
immediateClearListener = new WeakChangeListener<>((obs, oldv, newv) -> clear());
immediateClearListener = (obs, oldv, newv) -> clear();
immediateClearWeakListener = new WeakChangeListener<>(immediateClearListener);
for (ObservableValue<? extends Object> dependency : dependencies.values()) {
dependency.addListener(immediateClearListener);
dependency.addListener(immediateClearWeakListener);
}
return this;
}
Expand All @@ -128,8 +132,8 @@ public Check explicit() {
}

private void removeAllListeners() {
removeListener(immediateListener);
removeListener(immediateClearListener);
removeListener(immediateWeakListener);
removeListener(immediateClearWeakListener);
}

private void removeListener(ChangeListener<? super Object> listener) {
Expand Down

0 comments on commit 2d0b142

Please sign in to comment.