scalut.wizard.views.WizardViewBaseImpl.scala Maven / Gradle / Ivy
package scalut.wizard.views
import scalut.collections.CollectionHelper
import scalut.wizard.{WizardAction, WizardEvent, WizardEventInfo}
trait WizardViewBaseImpl[TPage <: WizardPageView] extends WizardView {
override type Page <: TPage
//type Model <: WizardModel[_, Page]
override protected def notification(sender: Model, arg: WizardEventInfo[Page]): Unit = {
arg.action match {
case WizardEvent.PageChanged | WizardEvent.PagesCleared => setPage(getModel.getCurrentPage)
case WizardEvent.PageActivated => updateActions()
case WizardEvent.PageInserted => arg.page.wizard = this.asInstanceOf[arg.page.Wizard]
case _ =>
}
}
override def addPages(pages: Page*): Unit = {
if (!CollectionHelper.isEmpty(pages))
getModel.addPages(pages)
}
override def addPages(index: Int, pages: Page*): Unit = {
if (!CollectionHelper.isEmpty(pages))
getModel.addPages(index, pages)
}
override def next(): Boolean = {
if (isActionEnabled(WizardAction.Next))
getModel.next()
else
false
}
override def back(): Boolean = {
if (isActionEnabled(WizardAction.Back))
getModel.back()
else
false
}
override def finish(): Boolean = {
if (isActionEnabled(WizardAction.Finish))
getModel.finish()
else
false
}
override def updateNavigatorActions(): Unit = {
setActionEnabled(WizardAction.Back, !getModel.isCurrentPageIsFirst &&
getModel.isCanGoToPage(getModel.getPrevPageIndex)._1)
setActionEnabled(WizardAction.Next, !getModel.isCurrentPageIsLast &&
getModel.isCanGoToPage(getModel.getNextPageIndex)._1)
}
override def updateFinishAction(): Unit = {
setActionEnabled(WizardAction.Finish, getModel.isCanFinish)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy