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.dynamic;
018
019import org.apache.wicket.Component;
020import org.apache.wicket.extensions.wizard.IWizard;
021import org.apache.wicket.extensions.wizard.WizardStep;
022import org.apache.wicket.model.IModel;
023
024/**
025 * Default implementation of a {@link IDynamicWizardStep dynamic wizard step}.
026 * 
027 * @author eelcohillenius
028 */
029public abstract class DynamicWizardStep extends WizardStep implements IDynamicWizardStep
030{
031        private static final long serialVersionUID = 1L;
032
033        private final IDynamicWizardStep previousStep;
034
035        /**
036         * Construct without a title and a summary. Useful for when you provide a custom header by
037         * overriding {@link #getHeader(String, Component, IWizard)}.
038         * 
039         * @param previousStep
040         *            The previous step. May be null if this is the first step in the wizard
041         */
042        public DynamicWizardStep(final IDynamicWizardStep previousStep)
043        {
044                super();
045                this.previousStep = previousStep;
046        }
047
048        /**
049         * Creates a new step with the specified title and summary. The title and summary are displayed
050         * in the wizard title block while this step is active.
051         * 
052         * @param previousStep
053         *            The previous step. May be null if this is the first step in the wizard
054         * @param title
055         *            the title of this step.
056         * @param summary
057         *            a brief summary of this step or some usage guidelines.
058         */
059        public DynamicWizardStep(final IDynamicWizardStep previousStep, final IModel<String> title,
060                final IModel<String> summary)
061        {
062                super(title, summary);
063                this.previousStep = previousStep;
064        }
065
066        /**
067         * Creates a new step with the specified title and summary. The title and summary are displayed
068         * in the wizard title block while this step is active.
069         * 
070         * @param previousStep
071         *            The previous step. May be null if this is the first step in the wizard
072         * @param title
073         *            the title of this step.
074         * @param summary
075         *            a brief summary of this step or some usage guidelines.
076         * @param model
077         *            Any model which is to be used for this step
078         */
079        public DynamicWizardStep(final IDynamicWizardStep previousStep, final IModel<String> title,
080                final IModel<String> summary, final IModel<?> model)
081        {
082                super(title, summary, model);
083                this.previousStep = previousStep;
084        }
085
086        /**
087         * Creates a new step with the specified title and summary. The title and summary are displayed
088         * in the wizard title block while this step is active.
089         * 
090         * @param previousStep
091         *            The previous step. May be null if this is the first step in the wizard
092         * @param title
093         *            the title of this step.
094         * @param summary
095         *            a brief summary of this step or some usage guidelines.
096         */
097        public DynamicWizardStep(final IDynamicWizardStep previousStep, final String title,
098                final String summary)
099        {
100                super(title, summary);
101                this.previousStep = previousStep;
102        }
103
104        /**
105         * Creates a new step with the specified title and summary. The title and summary are displayed
106         * in the wizard title block while this step is active.
107         * 
108         * @param previousStep
109         *            The previous step. May be null if this is the first step in the wizard
110         * @param title
111         *            the title of this step.
112         * @param summary
113         *            a brief summary of this step or some usage guidelines.
114         * @param model
115         *            Any model which is to be used for this step
116         */
117        public DynamicWizardStep(final IDynamicWizardStep previousStep, final String title,
118                final String summary, final IModel<?> model)
119        {
120                super(title, summary, model);
121                this.previousStep = previousStep;
122        }
123
124        /**
125         * @see org.apache.wicket.extensions.wizard.dynamic.IDynamicWizardStep#isLastAvailable()
126         */
127        @Override
128        public boolean isLastAvailable()
129        {
130                return false;
131        }
132
133        /**
134         * @see org.apache.wicket.extensions.wizard.dynamic.IDynamicWizardStep#isNextAvailable()
135         */
136        @Override
137        public boolean isNextAvailable()
138        {
139                return !isLastStep();
140        }
141
142        /**
143         * @see org.apache.wicket.extensions.wizard.dynamic.IDynamicWizardStep#isPreviousAvailable()
144         */
145        @Override
146        public boolean isPreviousAvailable()
147        {
148                return (previousStep != null);
149        }
150
151        /**
152         * @see org.apache.wicket.extensions.wizard.dynamic.IDynamicWizardStep#last()
153         */
154        @Override
155        public IDynamicWizardStep last()
156        {
157                throw new IllegalStateException("if the last button is available, this step "
158                        + "has to override the last() method and let it return a step");
159        }
160
161        /**
162         * @see org.apache.wicket.extensions.wizard.dynamic.IDynamicWizardStep#previous()
163         */
164        @Override
165        public IDynamicWizardStep previous()
166        {
167                return previousStep;
168        }
169}