001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.extensions.wizard;
018
019import org.apache.wicket.model.ResourceModel;
020
021/**
022 * Models a next button in the wizard. When pressed, it calls {@link IWizardStep#applyState()} on
023 * the active wizard step, and then moves the wizard state to the next step of the model by calling
024 * {@link IWizardModel#next() next} on the wizard's model.
025 * 
026 * @author Eelco Hillenius
027 */
028public class NextButton extends WizardButton
029{
030        private static final long serialVersionUID = 1L;
031
032        /**
033         * Construct.
034         * 
035         * @param id
036         * @param wizard
037         */
038        public NextButton(final String id, final IWizard wizard)
039        {
040                super(id, wizard, new ResourceModel("org.apache.wicket.extensions.wizard.next"));
041        }
042
043        @Override
044        protected void onConfigure()
045        {
046                super.onConfigure();
047
048                setEnabled(getWizardModel().isNextAvailable());
049        }
050
051        /**
052         * @see org.apache.wicket.extensions.wizard.WizardButton#onClick()
053         */
054        @Override
055        public void onClick()
056        {
057                IWizardModel wizardModel = getWizardModel();
058                IWizardStep step = wizardModel.getActiveStep();
059
060                // let the step apply any state
061                step.applyState();
062
063                // if the step completed after applying the state, move the
064                // model onward
065                if (step.isComplete())
066                {
067                        wizardModel.next();
068                }
069                else
070                {
071                        error(getLocalizer().getString(
072                                "org.apache.wicket.extensions.wizard.NextButton.step.did.not.complete", this));
073                }
074        }
075
076        /**
077         * @see org.apache.wicket.Component#onBeforeRender()
078         */
079        @Override
080        protected void onBeforeRender()
081        {
082                getForm().setDefaultButton(this);
083                super.onBeforeRender();
084        }
085}