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
void previous() {
model.currentStep--
recalcButtons()
view.updateLayout()
}
@ControllerAction
void next() {
def errors = model.steps[model.currentStep].validate()
if (errors) {
if (errors != null && !errors.isEmpty()) {
String errorMessage = String.join("\n", errors)
JOptionPane.showMessageDialog(model.parent, errorMessage, "Invalid Input", JOptionPane.ERROR_MESSAGE)
} else {
model.currentStep++
recalcButtons()
view.updateLayout()
}
}
@ -48,10 +46,4 @@ class WizardController {
model.finished['applied'] = false
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() {
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()
def cardsPanel = builder.getVariable("cards-panel")
cardsPanel.getLayout().show(cardsPanel, constraints)