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 cancel button in the wizard. When pressed, it calls
21: * {@link IWizardStep#applyState()} on the active wizard step, and then
22: * {@link Wizard#onFinish()} on the wizard.
23: *
24: * @author Eelco Hillenius
25: */
26: public final class FinishButton extends WizardButton {
27: private static final long serialVersionUID = 1L;
28:
29: /**
30: * Construct.
31: *
32: * @param id
33: * The component id
34: * @param wizard
35: * The wizard
36: */
37: public FinishButton(String id, IWizard wizard) {
38: super (id, wizard, "org.apache.wicket.extensions.wizard.finish");
39: }
40:
41: /**
42: * @see org.apache.wicket.Component#isEnabled()
43: */
44: public final boolean isEnabled() {
45: IWizardStep activeStep = getWizardModel().getActiveStep();
46: return (activeStep != null && getWizardModel().isLastStep(
47: activeStep));
48: }
49:
50: /**
51: * @see org.apache.wicket.extensions.wizard.WizardButton#onClick()
52: */
53: public final void onClick() {
54: IWizardModel wizardModel = getWizardModel();
55: IWizardStep step = wizardModel.getActiveStep();
56:
57: // let the step apply any state
58: step.applyState();
59:
60: // if the step completed after applying the state, notify the wizard
61: if (step.isComplete()) {
62: getWizardModel().finish();
63: } else {
64: error(getLocalizer()
65: .getString(
66: "org.apache.wicket.extensions.wizard.FinishButton.step.did.not.complete",
67: this));
68: }
69: }
70: }
|