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.markup.html.form.Button;
020import org.apache.wicket.model.IModel;
021
022/**
023 * Base class for buttons that work with {@link IWizard the wizard component}. It uses resource
024 * bundles to display the button label.
025 * <p>
026 * When wizard buttons are presses (and they pass validation if that is relevant), they pass control
027 * to {@link #onClick() their action method}, which should do the real work.
028 * </p>
029 * 
030 * @author Eelco Hillenius
031 */
032public abstract class WizardButton extends Button
033{
034        private static final long serialVersionUID = 1L;
035
036        /**
037         * The enclosing wizard.
038         */
039        private final IWizard wizard;
040
041        /**
042         * Construct.
043         * 
044         * @param id
045         *            The component id
046         * @param wizard
047         *            The wizard
048         * @param label
049         *            The button's label
050         */
051        public WizardButton(final String id, final IWizard wizard, final IModel<String> label)
052        {
053                super(id, label);
054                this.wizard = wizard;
055        }
056
057        /**
058         * Gets the {@link IWizard}.
059         * 
060         * @return The wizard
061         */
062        protected final IWizard getWizard()
063        {
064                return wizard;
065        }
066
067        /**
068         * Gets the {@link IWizardModel wizard model}.
069         * 
070         * @return The wizard model
071         */
072        protected final IWizardModel getWizardModel()
073        {
074                return getWizard().getWizardModel();
075        }
076
077        /**
078         * Called when this button is clicked.
079         */
080        protected abstract void onClick();
081
082        /**
083         * @see org.apache.wicket.markup.html.form.Button#onSubmit()
084         */
085        @Override
086        public final void onSubmit()
087        {
088                onClick();
089        }
090}