5
5
import life .qbic .datamanager .views .general .dialog .ButtonFactory ;
6
6
7
7
/**
8
- * <b><class short description - 1 Line!> </b>
8
+ * <b>Stepper Dialog Footer </b>
9
9
*
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.
11
14
*
12
- * @since <version tag>
15
+ * @since 1.7.0
13
16
*/
14
17
public class StepperDialogFooter implements NavigationListener {
15
18
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
+
16
23
private final StepperDialog dialog ;
17
24
18
25
private final FooterFactory footerFactory = new FooterFactory ();
@@ -23,6 +30,15 @@ private StepperDialogFooter(StepperDialog dialog) {
23
30
onNavigationChange (dialog .currentNavigation ()); // we want to init the footer properly.
24
31
}
25
32
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
+ */
26
42
public static StepperDialogFooter with (StepperDialog dialog ) {
27
43
return new StepperDialogFooter (Objects .requireNonNull (dialog ));
28
44
}
@@ -31,33 +47,33 @@ private static void updateFooter(StepperDialog dialog, Div footer) {
31
47
dialog .setFooter (footer );
32
48
}
33
49
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
+
34
62
@ Override
35
63
public void onNavigationChange (NavigationInformation navigationInformation ) {
36
64
int currentStep = navigationInformation .currentStep ();
37
65
int totalSteps = navigationInformation .totalSteps ();
38
66
if (isIntermediateStep (currentStep , totalSteps )) {
39
- updateFooter (dialog ,footerFactory .createIntermediate (dialog ));
67
+ updateFooter (dialog , footerFactory .createIntermediate (dialog ));
40
68
return ;
41
69
}
42
70
if (currentStep == totalSteps ) {
43
- updateFooter (dialog ,footerFactory .createLast (dialog ));
71
+ updateFooter (dialog , footerFactory .createLast (dialog ));
44
72
} else {
45
73
updateFooter (dialog , footerFactory .createFirst (dialog ));
46
74
}
47
75
}
48
76
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
-
61
77
private static class FooterFactory {
62
78
63
79
@@ -76,12 +92,14 @@ Div createLast(StepperDialog dialog) {
76
92
77
93
private static class FirstFooter extends Div {
78
94
95
+
96
+
79
97
FirstFooter (StepperDialog dialog ) {
80
- addClassNames ("flex-horizontal" , "gap-04" , "footer" );
98
+ addClassNames (FLEX_HORIZONTAL , GAP_04 , "footer" );
81
99
var buttonFactory = new ButtonFactory ();
82
- var cancelButton = buttonFactory .createCancelButton ("Cancel" );
100
+ var cancelButton = buttonFactory .createCancelButton (CANCEL );
83
101
var nextButton = buttonFactory .createNavigationButton ("Next" );
84
- cancelButton .addClickListener (listener -> dialog .cancel ());
102
+ cancelButton .addClickListener (listener -> dialog .cancel ());
85
103
nextButton .addClickListener (listener -> dialog .next ());
86
104
add (cancelButton , nextButton );
87
105
}
@@ -90,16 +108,16 @@ private static class FirstFooter extends Div {
90
108
private static class IntermediateFooter extends Div {
91
109
92
110
public IntermediateFooter (StepperDialog dialog ) {
93
- addClassNames ("flex-horizontal" , "footer-intermediate" );
111
+ addClassNames (FLEX_HORIZONTAL , "footer-intermediate" );
94
112
var buttonFactory = new ButtonFactory ();
95
- var cancelButton = buttonFactory .createCancelButton ("Cancel" );
113
+ var cancelButton = buttonFactory .createCancelButton (StepperDialogFooter . CANCEL );
96
114
var nextButton = buttonFactory .createNavigationButton ("Next" );
97
115
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 ());
100
118
nextButton .addClickListener (listener -> dialog .next ());
101
119
var containerRight = new Div ();
102
- containerRight .addClassNames ("flex-horizontal" , "gap-04" );
120
+ containerRight .addClassNames (FLEX_HORIZONTAL , GAP_04 );
103
121
containerRight .add (cancelButton , nextButton );
104
122
add (previousButton , containerRight );
105
123
}
@@ -108,16 +126,16 @@ public IntermediateFooter(StepperDialog dialog) {
108
126
private static class LastFooter extends Div {
109
127
110
128
public LastFooter (StepperDialog dialog ) {
111
- addClassNames ("flex-horizontal" , "footer-intermediate" );
129
+ addClassNames (FLEX_HORIZONTAL , "footer-intermediate" );
112
130
var buttonFactory = new ButtonFactory ();
113
- var cancelButton = buttonFactory .createCancelButton ("Cancel" );
131
+ var cancelButton = buttonFactory .createCancelButton (StepperDialogFooter . CANCEL );
114
132
var confirmButton = buttonFactory .createConfirmButton ("Submit" );
115
133
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 ());
118
136
confirmButton .addClickListener (listener -> dialog .confirm ());
119
137
var containerRight = new Div ();
120
- containerRight .addClassNames ("flex-horizontal" , "gap-04" );
138
+ containerRight .addClassNames (FLEX_HORIZONTAL , GAP_04 );
121
139
containerRight .add (cancelButton , confirmButton );
122
140
add (previousButton , containerRight );
123
141
}
0 commit comments