Skip to content

Commit 20767a5

Browse files
committed
Refactor presenters and views for state management
1 parent a47dc62 commit 20767a5

112 files changed

Lines changed: 1107 additions & 863 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CLAUDE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ selectionsByType`, `getSelectionsByType()`/`setSelectionsByType(...)`), not `<ke
129129
`typeSelections`). The `by`-form reads directly as "which value, keyed by which type of key" at the
130130
declaration site, without having to look at the generic type arguments to tell which side is the key.
131131

132+
`View` methods follow a naming convention that distinguishes two kinds of methods:
133+
134+
1. State methods — methods that mirror state owned by the `Presenter`. The `Presenter` has the corresponding
135+
state and a `getX`/`isX` and/or `setX` accessor for it. The corresponding `View` method always starts with
136+
`update`, e.g. `updateTitle`, `updateModal`, `updateDensity`.
137+
2. Command methods — all other methods that perform an action rather than mirror `Presenter` state. They use an
138+
appropriate action verb, such as `showX`, `hideX`, `scrollToFile`, `selectFile`, `clearX`, or `refreshMenu`.
139+
132140
## Javadoc
133141

134142
Document the contract — what the member does and why a caller would use it — never how it's implemented.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,14 @@ Examples of `Composer` methods using `open*` and `close*`:
617617
| Page | `openPage(params)` | `closePage(page)` | `addPage(page)` | `removePage(page)` |
618618
| Area | `openArea(params)` | `closeArea(area)` | `addArea(area)` | `removeArea(area)` |
619619

620+
`View` methods also follow a naming convention that distinguishes two kinds of methods:
621+
622+
1. State methods — methods that mirror state owned by the `Presenter`. The `Presenter` has the corresponding state and
623+
a `getX`/`isX` and/or `setX` accessor for it. The corresponding `View` method always starts with `update`, e.g.
624+
`updateTitle`, `updateModal`, `updateDensity`.
625+
2. Command methods — all other methods that perform an action rather than mirror `Presenter` state. They use an
626+
appropriate action verb, such as `showX`, `hideX`, `scrollToFile`, `selectFile`, `clearX`, or `refreshMenu`.
627+
620628
## Quick Start <a name="quick-start"></a>
621629

622630
To get started with ShellFX, it is recommended to follow these steps:

shellfx-core/src/main/java/com/techsenger/shellfx/core/dialog/AbstractDialogFxView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@ public abstract class AbstractDialogFxView<P extends AbstractDialogPresenter<?>>
6161
() -> getDescriptor().getLogPrefix());
6262

6363
@Override
64-
public void setLeftButtons(ResultButtonName... names) {
64+
public void updateLeftButtons(ResultButtonName... names) {
6565
removeButtons(leftBottomBox);
6666
addButtons(leftBottomBox, names);
6767
}
6868

6969
@Override
70-
public void setRightButtons(ResultButtonName... names) {
70+
public void updateRightButtons(ResultButtonName... names) {
7171
removeButtons(rightBottomBox);
7272
addButtons(rightBottomBox, names);
7373
}
7474

7575
@Override
76-
public void setButtonDisabled(ResultButtonName name, boolean value) {
76+
public void updateButtonDisabled(ResultButtonName name, boolean value) {
7777
var button = this.buttonsByName.get(name);
7878
if (button != null) {
7979
button.setDisable(value);
8080
}
8181
}
8282

8383
@Override
84-
public void setButtonDefault(ResultButtonName name, boolean value) {
84+
public void updateButtonDefault(ResultButtonName name, boolean value) {
8585
var button = this.buttonsByName.get(name);
8686
if (button != null) {
8787
button.setDefaultButton(value);

shellfx-core/src/main/java/com/techsenger/shellfx/core/dialog/AbstractDialogPresenter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void setLeftButtons(ResultButtonName... names) {
9090
foundNames.add(name);
9191
}
9292
}
93-
getView().setLeftButtons(foundNames.toArray(ResultButtonName[]::new));
93+
getView().updateLeftButtons(foundNames.toArray(ResultButtonName[]::new));
9494
}
9595

9696
@Override
@@ -104,24 +104,24 @@ public void setRightButtons(ResultButtonName... names) {
104104
foundNames.add(name);
105105
}
106106
}
107-
getView().setRightButtons(foundNames.toArray(ResultButtonName[]::new));
107+
getView().updateRightButtons(foundNames.toArray(ResultButtonName[]::new));
108108
}
109109

110110
@Override
111111
public void setButtonDisabled(ResultButtonName name, boolean value) {
112112
var button = this.buttonsByName.get(name);
113-
if (button != null) {
113+
if (button != null && button.isDisabled() != value) {
114114
button.setDisabled(value);
115-
getView().setButtonDisabled(name, value);
115+
getView().updateButtonDisabled(name, value);
116116
}
117117
}
118118

119119
@Override
120120
public void setButtonDefault(ResultButtonName name, boolean value) {
121121
var button = this.buttonsByName.get(name);
122-
if (button != null) {
122+
if (button != null && button.isDefault() != value) {
123123
button.setDefault(value);
124-
getView().setButtonDefault(name, value);
124+
getView().updateButtonDefault(name, value);
125125
}
126126
}
127127

shellfx-core/src/main/java/com/techsenger/shellfx/core/dialog/DialogPort.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Pavel Castornii
2929
*/
30-
public interface DialogPort extends DialogShared, WindowPort {
30+
public interface DialogPort extends WindowPort {
3131

3232
/**
3333
* Returns the action to be executed when a result button is clicked.
@@ -83,4 +83,37 @@ public interface DialogPort extends DialogShared, WindowPort {
8383
* or empty if the button does not exist
8484
*/
8585
Optional<Boolean> getButtonDefault(ResultButtonName name);
86+
87+
/**
88+
* Specifies the result buttons in the left side of the dialog's button bar or removes all of them.
89+
*
90+
* @param names the names of the result buttons to add; pass no arguments to remove all buttons.
91+
*/
92+
void setLeftButtons(ResultButtonName... names);
93+
94+
/**
95+
* Specifies the result buttons in the right side of the dialog's button bar or removes all of them.
96+
*
97+
* @param names the names of the result buttons to add; pass no arguments to remove all buttons.
98+
*/
99+
void setRightButtons(ResultButtonName... names);
100+
101+
/**
102+
* Sets the disabled state of the specified result button.
103+
*
104+
* @param name the name of the result button
105+
* @param value {@code true} to disable the button, {@code false} to enable it
106+
*/
107+
void setButtonDisabled(ResultButtonName name, boolean value);
108+
109+
/**
110+
* Sets whether the specified result button is the default button for the dialog.
111+
* <p>
112+
* The default button is typically activated when the user presses Enter. Only one button should be marked
113+
* as default at a time.
114+
*
115+
* @param name the name of the result button
116+
* @param value {@code true} to make this button the default, {@code false} otherwise
117+
*/
118+
void setButtonDefault(ResultButtonName name, boolean value);
86119
}

shellfx-core/src/main/java/com/techsenger/shellfx/core/dialog/DialogShared.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

shellfx-core/src/main/java/com/techsenger/shellfx/core/dialog/DialogView.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
package com.techsenger.shellfx.core.dialog;
1818

1919
import com.techsenger.shellfx.core.window.WindowView;
20+
import com.techsenger.shellfx.material.button.ResultButtonName;
2021

2122
/**
2223
*
2324
* @author Pavel Castornii
2425
*/
25-
public interface DialogView extends WindowView, DialogShared {
26+
public interface DialogView extends WindowView {
2627

28+
void updateLeftButtons(ResultButtonName... names);
29+
30+
void updateRightButtons(ResultButtonName... names);
31+
32+
void updateButtonDisabled(ResultButtonName name, boolean value);
33+
34+
void updateButtonDefault(ResultButtonName name, boolean value);
2735
}

shellfx-core/src/main/java/com/techsenger/shellfx/core/popup/AbstractPopupFxView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,17 @@ public Pane getNode() {
7575
}
7676

7777
@Override
78-
public void setPrefWidth(double value) {
78+
public void updatePrefWidth(double value) {
7979
stackPane.setPrefWidth(value);
8080
}
8181

8282
@Override
83-
public void setPrefHeight(double value) {
83+
public void updatePrefHeight(double value) {
8484
stackPane.setPrefHeight(value);
8585
}
8686

8787
@Override
88-
public void setWaiting(boolean waiting) {
88+
public void updateWaiting(boolean waiting) {
8989
if (waiting) {
9090
stackPane.getChildren().add(waitingPane);
9191
} else {

shellfx-core/src/main/java/com/techsenger/shellfx/core/popup/AbstractPopupPresenter.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,20 @@ public double getPrefHeight() {
6767

6868
@Override
6969
public void setPrefWidth(double prefWidth) {
70+
if (this.prefWidth == prefWidth) {
71+
return;
72+
}
7073
this.prefWidth = prefWidth;
71-
getView().setPrefWidth(prefWidth);
74+
getView().updatePrefWidth(prefWidth);
7275
}
7376

7477
@Override
7578
public void setPrefHeight(double prefHeight) {
79+
if (this.prefHeight == prefHeight) {
80+
return;
81+
}
7682
this.prefHeight = prefHeight;
77-
getView().setPrefHeight(prefHeight);
83+
getView().updatePrefHeight(prefHeight);
7884
}
7985

8086
@Override
@@ -88,7 +94,7 @@ public void setWaiting(boolean waiting) {
8894
return;
8995
}
9096
this.waiting = waiting;
91-
getView().setWaiting(waiting);
97+
getView().updateWaiting(waiting);
9298
}
9399

94100
@Override

shellfx-core/src/main/java/com/techsenger/shellfx/core/popup/PopupPort.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Pavel Castornii
2626
*/
27-
public interface PopupPort extends AreaPort, PopupShared, CloseAwarePort, Waitable {
27+
public interface PopupPort extends AreaPort, CloseAwarePort, Waitable {
2828

2929
/**
3030
* Returns {@code true} if the popup blocks interaction with underlying content (modal) and {@code false} otherwise.
@@ -36,4 +36,8 @@ public interface PopupPort extends AreaPort, PopupShared, CloseAwarePort, Waitab
3636
double getPrefWidth();
3737

3838
double getPrefHeight();
39+
40+
void setPrefWidth(double value);
41+
42+
void setPrefHeight(double value);
3943
}

0 commit comments

Comments
 (0)