001 /*
002 * Copyright 2002-2006 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 */
017
018 package org.springframework.richclient.form;
019
020 import javax.swing.JComponent;
021
022 import org.springframework.beans.factory.InitializingBean;
023 import org.springframework.util.Assert;
024 import org.springframework.binding.form.FormModel;
025 import org.springframework.binding.form.HierarchicalFormModel;
026 import org.springframework.binding.form.ValidatingFormModel;
027 import org.springframework.binding.value.ValueModel;
028
029 /**
030 * Convenience class for producing a Spring Rich {@link Form} based on a
031 * pre-generated form UI (typically, a form that has been created in a form
032 * designer such as Matisse or JFormDesigner). This implementation handles
033 * the most common case where a developer designs a form and wants to display
034 * it without any custom functionality beyond what Spring Rich already
035 * provides.
036 * <p/>
037 * In order to better facilitate the common usage scenarios and to avoid
038 * developers having to subclass <code>GeneratedForm</code>, many convenience
039 * constructors are provided, along with making the
040 * {@link #setFormModel(ValidatingFormModel)} and {@link #setId(String)}
041 * methods public.
042 *
043 * @author Andy DePue
044 * @author Peter De Bruycker
045 */
046 public class GeneratedForm extends AbstractForm implements InitializingBean {
047 private FormUIProvider formUIProvider;
048
049 public GeneratedForm() {
050 super();
051 }
052
053 public GeneratedForm(String formId) {
054 super(formId);
055 }
056
057 public GeneratedForm(Object formObject) {
058 super(formObject);
059 }
060
061 public GeneratedForm(FormModel pageFormModel) {
062 super(pageFormModel);
063 }
064
065 public GeneratedForm(FormModel formModel, String formId) {
066 super(formModel, formId);
067 }
068
069 public GeneratedForm(HierarchicalFormModel parentFormModel, String formId, String childFormObjectPropertyPath) {
070 super(parentFormModel, formId, childFormObjectPropertyPath);
071 }
072
073 public GeneratedForm(HierarchicalFormModel parentFormModel, String formId, ValueModel childFormObjectHolder) {
074 super(parentFormModel, formId, childFormObjectHolder);
075 }
076
077 public GeneratedForm(final FormUIProvider formUIProvider) {
078 this.formUIProvider = formUIProvider;
079 }
080
081 public GeneratedForm(String formId, final FormUIProvider formUIProvider) {
082 super(formId);
083 this.formUIProvider = formUIProvider;
084 }
085
086 public GeneratedForm(Object formObject, final FormUIProvider formUIProvider) {
087 super(formObject);
088 this.formUIProvider = formUIProvider;
089 }
090
091 public GeneratedForm(Object formObject, String formId, final FormUIProvider formUIProvider) {
092 super(formObject);
093 setId(formId);
094 this.formUIProvider = formUIProvider;
095 }
096
097 public GeneratedForm(FormModel pageFormModel, final FormUIProvider formUIProvider) {
098 super(pageFormModel);
099 this.formUIProvider = formUIProvider;
100 }
101
102 public GeneratedForm(FormModel formModel, String formId, final FormUIProvider formUIProvider) {
103 super(formModel, formId);
104 this.formUIProvider = formUIProvider;
105 }
106
107 public GeneratedForm(HierarchicalFormModel parentFormModel, String formId, String childFormObjectPropertyPath, final FormUIProvider formUIProvider) {
108 super(parentFormModel, formId, childFormObjectPropertyPath);
109 this.formUIProvider = formUIProvider;
110 }
111
112 public GeneratedForm(HierarchicalFormModel parentFormModel, String formId, ValueModel childFormObjectHolder, final FormUIProvider formUIProvider) {
113 super(parentFormModel, formId, childFormObjectHolder);
114 this.formUIProvider = formUIProvider;
115 }
116
117
118 //
119 // METHODS FROM CLASS AbstractForm
120 //
121
122 protected JComponent createFormControl() {
123 this.formUIProvider.bind(getBindingFactory(), this);
124 return this.formUIProvider.getControl();
125 }
126
127 /**
128 * Provides public access to this method as a convenience.
129 *
130 * @param formModel
131 */
132 public void setFormModel(ValidatingFormModel formModel) {
133 super.setFormModel(formModel);
134 }
135
136
137 /**
138 * Provides public access to this method as a convenience.
139 *
140 * @param formId
141 */
142 public void setId(String formId) {
143 super.setId(formId);
144 }
145
146
147
148
149
150
151 //
152 // METHODS FROM INTERFACE InitializingBean
153 //
154
155 public void afterPropertiesSet() throws Exception {
156 Assert.notNull(this.formUIProvider, "formUIProvider must be set");
157 }
158
159
160
161
162 //
163 // SIMPLE PROPERTY ACCESSORS
164 //
165
166 public FormUIProvider getFormUIProvider() {
167 return formUIProvider;
168 }
169
170 public void setFormUIProvider(final FormUIProvider formUIProvider) {
171 this.formUIProvider = formUIProvider;
172 }
173 }