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 cancel button in the wizard. When pressed, it calls {@link IWizardStep#applyState()} on
023 * the active wizard step, and then {@link Wizard#onFinish()} on the wizard.
024 * 
025 * @author Eelco Hillenius
026 */
027public class FinishButton extends WizardButton
028{
029        private static final long serialVersionUID = 1L;
030
031        /**
032         * Construct.
033         * 
034         * @param id
035         *            The component id
036         * @param wizard
037         *            The wizard
038         */
039        public FinishButton(final String id, final IWizard wizard)
040        {
041                super(id, wizard, new ResourceModel("org.apache.wicket.extensions.wizard.finish"));
042        }
043
044        @Override
045        protected void onConfigure()
046        {
047                super.onConfigure();
048
049                setEnabled(getWizardModel().isFinishAvailable());
050        }
051
052        /**
053         * @see org.apache.wicket.extensions.wizard.WizardButton#onClick()
054         */
055        @Override
056        public void onClick()
057        {
058                IWizardModel wizardModel = getWizardModel();
059                IWizardStep step = wizardModel.getActiveStep();
060
061                // let the step apply any state
062                step.applyState();
063
064                // if the step completed after applying the state, notify the wizard
065                if (step.isComplete())
066                {
067                        getWizardModel().finish();
068                }
069                else
070                {
071                        error(getLocalizer().getString(
072                                "org.apache.wicket.extensions.wizard.FinishButton.step.did.not.complete", this));
073                }
074        }
075}