001 /*
002 * Copyright 2002-2004 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.wizard;
017
018 import javax.swing.JComponent;
019
020 import org.springframework.richclient.form.Form;
021
022 /**
023 * An implementation of WizardPage that delegates to a FormPage for its control,
024 * pageComplete status and messages.
025 *
026 * @author Oliver Hutchison
027 */
028 public class FormBackedWizardPage extends AbstractWizardPage {
029 private Form backingForm;
030
031 /**
032 * Createa a new FormBackedWizardPage
033 *
034 * @param backingForm
035 * the named form page which will provide the control for this
036 * wizard page.
037 */
038 public FormBackedWizardPage(Form backingForm) {
039 this(backingForm, true);
040 }
041
042 public FormBackedWizardPage(Form backingForm, boolean autoConfigure) {
043 super(backingForm.getId(), autoConfigure);
044 this.backingForm = backingForm;
045 }
046
047 /**
048 * Creates a new FormBackedWizardPage.
049 *
050 * @param parentPageId
051 * the id of a containing parent page. This will be used to
052 * configure page titles/description
053 * @param backingForm
054 * the names form page which will provide the control for this
055 * wizard page.
056 */
057 public FormBackedWizardPage(String parentPageId, Form backingForm) {
058 super(parentPageId + (backingForm.getId() != null ? "." + backingForm.getId() : ""));
059 this.backingForm = backingForm;
060 }
061
062 protected Form getBackingForm() {
063 return backingForm;
064 }
065
066 public void onAboutToShow() {
067 setEnabled(!backingForm.hasErrors());
068 }
069
070 protected JComponent createControl() {
071 JComponent formControl = backingForm.getControl();
072 initPageValidationReporter();
073 return formControl;
074 }
075
076 protected void initPageValidationReporter() {
077 backingForm.newSingleLineResultsReporter(this);
078 backingForm.addGuarded(this);
079 }
080
081 public void setEnabled(boolean enabled) {
082 setPageComplete(enabled);
083 }
084 }