Skip to content

Commit 7563a0b

Browse files
committed
More refinemenets
1 parent 629199a commit 7563a0b

File tree

1 file changed

+48
-30
lines changed

1 file changed

+48
-30
lines changed

Diff for: user-interface/src/main/java/life/qbic/datamanager/views/general/dialog/stepper/StepperDialogFooter.java

+48-30
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55
import life.qbic.datamanager.views.general.dialog.ButtonFactory;
66

77
/**
8-
* <b><class short description - 1 Line!></b>
8+
* <b>Stepper Dialog Footer</b>
99
*
10-
* <p><More detailed description - When to use, what it solves, etc.></p>
10+
* <p>A more specialised footer compared to the
11+
* {@link life.qbic.datamanager.views.general.dialog.DialogFooter}</p>. This footer can be used in
12+
* the context of {@link StepperDialog} and implements the {@link NavigationListener} interface to
13+
* get notified about navigation changes in the stepper.
1114
*
12-
* @since <version tag>
15+
* @since 1.7.0
1316
*/
1417
public class StepperDialogFooter implements NavigationListener {
1518

19+
private static final String FLEX_HORIZONTAL = "flex-horizontal";
20+
private static final String GAP_04 = "gap-04";
21+
private static final String CANCEL = "Cancel";
22+
1623
private final StepperDialog dialog;
1724

1825
private final FooterFactory footerFactory = new FooterFactory();
@@ -23,6 +30,15 @@ private StepperDialogFooter(StepperDialog dialog) {
2330
onNavigationChange(dialog.currentNavigation()); // we want to init the footer properly.
2431
}
2532

33+
/**
34+
* Creates a {@link StepperDialogFooter} that wires to the provided {@link StepperDialog}. During
35+
* instantiation, the footer component of the {@link StepperDialog} is set automatically and also
36+
* the footer subscribes to navigation changes of the {@link StepperDialog}.
37+
*
38+
* @param dialog the stepper dialog to wire into
39+
* @return the fully set-up stepper dialog footer
40+
* @since 1.7.0
41+
*/
2642
public static StepperDialogFooter with(StepperDialog dialog) {
2743
return new StepperDialogFooter(Objects.requireNonNull(dialog));
2844
}
@@ -31,33 +47,33 @@ private static void updateFooter(StepperDialog dialog, Div footer) {
3147
dialog.setFooter(footer);
3248
}
3349

50+
private static boolean hasNextStep(int currentStep, int numberOfSteps) {
51+
return currentStep < numberOfSteps;
52+
}
53+
54+
private static boolean hasPreviousStep(int currentStep) {
55+
return currentStep > 1;
56+
}
57+
58+
private static boolean isIntermediateStep(int currentStep, int numberOfSteps) {
59+
return hasNextStep(currentStep, numberOfSteps) && hasPreviousStep(currentStep);
60+
}
61+
3462
@Override
3563
public void onNavigationChange(NavigationInformation navigationInformation) {
3664
int currentStep = navigationInformation.currentStep();
3765
int totalSteps = navigationInformation.totalSteps();
3866
if (isIntermediateStep(currentStep, totalSteps)) {
39-
updateFooter(dialog,footerFactory.createIntermediate(dialog));
67+
updateFooter(dialog, footerFactory.createIntermediate(dialog));
4068
return;
4169
}
4270
if (currentStep == totalSteps) {
43-
updateFooter(dialog,footerFactory.createLast(dialog));
71+
updateFooter(dialog, footerFactory.createLast(dialog));
4472
} else {
4573
updateFooter(dialog, footerFactory.createFirst(dialog));
4674
}
4775
}
4876

49-
private static boolean hasNextStep(int currentStep, int numberOfSteps) {
50-
return currentStep < numberOfSteps;
51-
}
52-
53-
private static boolean hasPreviousStep(int currentStep) {
54-
return currentStep > 1;
55-
}
56-
57-
private static boolean isIntermediateStep(int currentStep, int numberOfSteps) {
58-
return hasNextStep(currentStep, numberOfSteps) && hasPreviousStep(currentStep);
59-
}
60-
6177
private static class FooterFactory {
6278

6379

@@ -76,12 +92,14 @@ Div createLast(StepperDialog dialog) {
7692

7793
private static class FirstFooter extends Div {
7894

95+
96+
7997
FirstFooter(StepperDialog dialog) {
80-
addClassNames("flex-horizontal", "gap-04", "footer");
98+
addClassNames(FLEX_HORIZONTAL, GAP_04, "footer");
8199
var buttonFactory = new ButtonFactory();
82-
var cancelButton = buttonFactory.createCancelButton("Cancel");
100+
var cancelButton = buttonFactory.createCancelButton(CANCEL);
83101
var nextButton = buttonFactory.createNavigationButton("Next");
84-
cancelButton.addClickListener(listener-> dialog.cancel());
102+
cancelButton.addClickListener(listener -> dialog.cancel());
85103
nextButton.addClickListener(listener -> dialog.next());
86104
add(cancelButton, nextButton);
87105
}
@@ -90,16 +108,16 @@ private static class FirstFooter extends Div {
90108
private static class IntermediateFooter extends Div {
91109

92110
public IntermediateFooter(StepperDialog dialog) {
93-
addClassNames("flex-horizontal", "footer-intermediate");
111+
addClassNames(FLEX_HORIZONTAL, "footer-intermediate");
94112
var buttonFactory = new ButtonFactory();
95-
var cancelButton = buttonFactory.createCancelButton("Cancel");
113+
var cancelButton = buttonFactory.createCancelButton(StepperDialogFooter.CANCEL);
96114
var nextButton = buttonFactory.createNavigationButton("Next");
97115
var previousButton = buttonFactory.createNavigationButton("Previous");
98-
previousButton.addClickListener(listener-> dialog.previous());
99-
cancelButton.addClickListener(listener-> dialog.cancel());
116+
previousButton.addClickListener(listener -> dialog.previous());
117+
cancelButton.addClickListener(listener -> dialog.cancel());
100118
nextButton.addClickListener(listener -> dialog.next());
101119
var containerRight = new Div();
102-
containerRight.addClassNames("flex-horizontal", "gap-04");
120+
containerRight.addClassNames(FLEX_HORIZONTAL, GAP_04);
103121
containerRight.add(cancelButton, nextButton);
104122
add(previousButton, containerRight);
105123
}
@@ -108,16 +126,16 @@ public IntermediateFooter(StepperDialog dialog) {
108126
private static class LastFooter extends Div {
109127

110128
public LastFooter(StepperDialog dialog) {
111-
addClassNames("flex-horizontal", "footer-intermediate");
129+
addClassNames(FLEX_HORIZONTAL, "footer-intermediate");
112130
var buttonFactory = new ButtonFactory();
113-
var cancelButton = buttonFactory.createCancelButton("Cancel");
131+
var cancelButton = buttonFactory.createCancelButton(StepperDialogFooter.CANCEL);
114132
var confirmButton = buttonFactory.createConfirmButton("Submit");
115133
var previousButton = buttonFactory.createNavigationButton("Previous");
116-
previousButton.addClickListener(listener-> dialog.previous());
117-
cancelButton.addClickListener(listener-> dialog.cancel());
134+
previousButton.addClickListener(listener -> dialog.previous());
135+
cancelButton.addClickListener(listener -> dialog.cancel());
118136
confirmButton.addClickListener(listener -> dialog.confirm());
119137
var containerRight = new Div();
120-
containerRight.addClassNames("flex-horizontal", "gap-04");
138+
containerRight.addClassNames(FLEX_HORIZONTAL, GAP_04);
121139
containerRight.add(cancelButton, confirmButton);
122140
add(previousButton, containerRight);
123141
}

0 commit comments

Comments
 (0)