move the button enabling logic in view

pull/53/head
Zlatin Balevsky 2020-05-29 01:50:53 +01:00
parent c2044044c0
commit 8c4bafda82
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 5 additions and 9 deletions

View File

@ -17,19 +17,17 @@ class WizardController {
@ControllerAction @ControllerAction
void previous() { void previous() {
model.currentStep-- model.currentStep--
recalcButtons()
view.updateLayout() view.updateLayout()
} }
@ControllerAction @ControllerAction
void next() { void next() {
def errors = model.steps[model.currentStep].validate() def errors = model.steps[model.currentStep].validate()
if (errors) { if (errors != null && !errors.isEmpty()) {
String errorMessage = String.join("\n", errors) String errorMessage = String.join("\n", errors)
JOptionPane.showMessageDialog(model.parent, errorMessage, "Invalid Input", JOptionPane.ERROR_MESSAGE) JOptionPane.showMessageDialog(model.parent, errorMessage, "Invalid Input", JOptionPane.ERROR_MESSAGE)
} else { } else {
model.currentStep++ model.currentStep++
recalcButtons()
view.updateLayout() view.updateLayout()
} }
} }
@ -48,10 +46,4 @@ class WizardController {
model.finished['applied'] = false model.finished['applied'] = false
view.hide() view.hide()
} }
private void recalcButtons() {
model.previousButtonEnabled = model.currentStep > 0
model.nextButtonEnabled = model.steps.size() > (model.currentStep + 1)
model.finishButtonEnabled = model.steps.size() == (model.currentStep + 1)
}
} }

View File

@ -49,6 +49,10 @@ class WizardView {
} }
void updateLayout() { void updateLayout() {
model.previousButtonEnabled = model.currentStep > 0
model.nextButtonEnabled = model.steps.size() > (model.currentStep + 1)
model.finishButtonEnabled = model.steps.size() == (model.currentStep + 1)
String constraints = model.steps[model.currentStep].getConstraint() String constraints = model.steps[model.currentStep].getConstraint()
def cardsPanel = builder.getVariable("cards-panel") def cardsPanel = builder.getVariable("cards-panel")
cardsPanel.getLayout().show(cardsPanel, constraints) cardsPanel.getLayout().show(cardsPanel, constraints)