state)
173 | {
174 | return this.binder.isValid() && this.configComponents.stream().allMatch(SpecificConfigComponent::isValid);
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/buttonbar/AbstractWizardButtonBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.buttonbar;
17 |
18 | import java.util.Objects;
19 | import java.util.function.Consumer;
20 | import java.util.function.Function;
21 | import java.util.stream.Stream;
22 |
23 | import com.vaadin.flow.component.Composite;
24 | import com.vaadin.flow.component.HasSize;
25 | import com.vaadin.flow.component.HasStyle;
26 | import com.vaadin.flow.component.button.Button;
27 | import com.vaadin.flow.component.button.ButtonVariant;
28 | import com.vaadin.flow.component.dependency.CssImport;
29 | import com.vaadin.flow.component.orderedlayout.FlexComponent;
30 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
31 | import com.vaadin.flow.shared.Registration;
32 |
33 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardStyles;
34 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanelActions;
35 | import software.xdev.vaadin.grid_exporter.components.wizard.step.WizardStepState;
36 |
37 |
38 | @CssImport(WizardStyles.LOCATION)
39 | public abstract class AbstractWizardButtonBar> extends Composite
40 | implements HasSize, HasStyle
41 | {
42 | protected final Button btnCancel = new Button("Cancel");
43 | protected final Button btnPrevious = new Button("Back");
44 | protected final Button btnNext = new Button("Next");
45 | protected final Button btnDone = new Button("Done");
46 |
47 | protected final HorizontalLayout hlEndButtons = new HorizontalLayout();
48 |
49 | protected void init(final WizardPanelActions panel)
50 | {
51 | Objects.requireNonNull(panel);
52 |
53 | this.initUI();
54 | this.registerListeners(panel);
55 |
56 | // Set initial state
57 | this.updateFromStepState(new WizardStepState(0, 0));
58 | }
59 |
60 | protected void initUI()
61 | {
62 | this.btnCancel.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_CANCEL);
63 | this.btnPrevious.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_PREVIOUS);
64 | this.btnNext.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_NEXT);
65 | this.btnDone.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_DONE);
66 |
67 | Stream.of(this.btnCancel, this.btnPrevious, this.btnNext, this.btnDone)
68 | .forEach(btn -> btn.setDisableOnClick(true));
69 |
70 | Stream.of(this.btnNext, this.btnDone)
71 | .forEach(btn -> btn.addThemeVariants(ButtonVariant.LUMO_PRIMARY));
72 |
73 | this.hlEndButtons.setPadding(false);
74 | this.hlEndButtons.add(this.btnPrevious, this.btnNext, this.btnDone);
75 |
76 | this.getContent().addClassName(WizardStyles.WIZARD_BUTTON_BAR);
77 | this.getContent().setPadding(false);
78 | this.getContent().setWidthFull();
79 | this.getContent().setJustifyContentMode(FlexComponent.JustifyContentMode.BETWEEN);
80 | this.getContent().add(this.btnCancel, this.hlEndButtons);
81 | }
82 |
83 | protected void registerListeners(final WizardPanelActions panel)
84 | {
85 | this.addButtonClickEvent(this.getBtnPrevious(), panel::showPreviousStep);
86 | this.addButtonClickEvent(this.getBtnNext(), panel::showNextStep);
87 |
88 | panel.addStepStateChangedListener(this::updateFromStepState);
89 | }
90 |
91 | protected Registration addButtonClickEvent(final Button button, final Consumer isFromClientConsumer)
92 | {
93 | return button.addClickListener(ev ->
94 | {
95 | isFromClientConsumer.accept(ev.isFromClient());
96 | ev.getSource().setEnabled(true);
97 | });
98 | }
99 |
100 | protected void updateFromStepState(final WizardStepState stepState)
101 | {
102 | this.getBtnPrevious().setEnabled(!stepState.isFirstStep());
103 |
104 | this.getBtnNext().setVisible(!stepState.isLastStep());
105 | this.getBtnDone().setVisible(stepState.isLastStep());
106 | }
107 |
108 | // region Getter for Buttons
109 |
110 | public Button getBtnCancel()
111 | {
112 | return this.btnCancel;
113 | }
114 |
115 | public Button getBtnPrevious()
116 | {
117 | return this.btnPrevious;
118 | }
119 |
120 | public Button getBtnNext()
121 | {
122 | return this.btnNext;
123 | }
124 |
125 | public Button getBtnDone()
126 | {
127 | return this.btnDone;
128 | }
129 |
130 | // endregion
131 |
132 | public P configureButton(
133 | final Function selfButtonSupplier,
134 | final Consumer