01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.extensions.wizard;
18:
19: /**
20: * Models a next button in the wizard. When pressed, it calls
21: * {@link IWizardStep#applyState()} on the active wizard step, and then moves
22: * the wizard state to the next step of the model by calling
23: * {@link IWizardModel#next() next} on the wizard's model.
24: *
25: * @author Eelco Hillenius
26: */
27: public final class NextButton extends WizardButton {
28: private static final long serialVersionUID = 1L;
29:
30: /**
31: * Construct.
32: *
33: * @param id
34: * @param wizard
35: */
36: public NextButton(String id, IWizard wizard) {
37: super (id, wizard, "org.apache.wicket.extensions.wizard.next");
38: }
39:
40: /**
41: * @see org.apache.wicket.Component#isEnabled()
42: */
43: public final boolean isEnabled() {
44: return getWizardModel().isNextAvailable();
45: }
46:
47: /**
48: * @see org.apache.wicket.extensions.wizard.WizardButton#onClick()
49: */
50: public final void onClick() {
51: IWizardModel wizardModel = getWizardModel();
52: IWizardStep step = wizardModel.getActiveStep();
53:
54: // let the step apply any state
55: step.applyState();
56:
57: // if the step completed after applying the state, move the
58: // model onward
59: if (step.isComplete()) {
60: wizardModel.next();
61: } else {
62: error(getLocalizer()
63: .getString(
64: "org.apache.wicket.extensions.wizard.NextButton.step.did.not.complete",
65: this ));
66: }
67: }
68:
69: /**
70: * @see org.apache.wicket.Component#onBeforeRender()
71: */
72: protected final void onBeforeRender() {
73: super.onBeforeRender();
74: getForm().setDefaultButton(this);
75: }
76: }
|