Skip to content

Commit 0e3584e

Browse files
committed
Refactor demo
1 parent 7ca3da4 commit 0e3584e

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

mvvm4fx-demo/src/main/java/com/techsenger/mvvm4fx/demo/PersonRegistryComponent.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ public ComponentName getName() {
3434
return DemoComponentNames.PERSON_REGISTRY;
3535
}
3636

37-
@Override
38-
protected void postInitialize() {
39-
super.postInitialize();
40-
getView().showStage();
41-
getView().getViewModel().refresh();
42-
}
43-
4437
@Override
4538
protected Mediator createMediator() {
4639
return new AbstractParentComponent.Mediator() { };

mvvm4fx-demo/src/main/java/com/techsenger/mvvm4fx/demo/PersonRegistryView.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public PersonRegistryView(Stage stage, PersonRegistryViewModel viewModel) {
5555
this.stage = stage;
5656
}
5757

58+
@Override
59+
protected void initialize() {
60+
super.initialize();
61+
stage.show();
62+
}
63+
5864
@Override
5965
protected void build() {
6066
super.build();
@@ -106,8 +112,4 @@ protected void addHandlers() {
106112
removeButton.setOnAction(e -> vm.remove());
107113
refreshButton.setOnAction(e -> vm.refresh());
108114
}
109-
110-
void showStage() {
111-
stage.show();
112-
}
113115
}

mvvm4fx-demo/src/main/java/com/techsenger/mvvm4fx/demo/PersonRegistryViewModel.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.techsenger.mvvm4fx.demo;
1818

1919
import com.techsenger.mvvm4fx.core.AbstractParentViewModel;
20+
import com.techsenger.mvvm4fx.core.ComponentState;
2021
import com.techsenger.mvvm4fx.core.ParentMediator;
2122
import com.techsenger.mvvm4fx.demo.model.Person;
2223
import com.techsenger.mvvm4fx.demo.model.PersonService;
@@ -64,6 +65,11 @@ protected void initialize() {
6465
// log message example with component meta
6566
logger.debug("{} Selected person property changed", getMediator().getLogPrefix());
6667
});
68+
getMediator().stateProperty().addListener((ov, oldV, newV) -> {
69+
if (newV == ComponentState.INITIALIZED) {
70+
refresh();
71+
}
72+
});
6773
}
6874

6975
ObservableList<Person> getPersons() {

0 commit comments

Comments
 (0)