001: package com.gwtext.client.widgets.form;
002:
003: import com.google.gwt.core.client.JavaScriptObject;
004: import com.gwtext.client.core.Connection;
005: import com.gwtext.client.core.Function;
006: import com.gwtext.client.core.Position;
007: import com.gwtext.client.core.UrlParam;
008: import com.gwtext.client.data.Reader;
009: import com.gwtext.client.widgets.Panel;
010: import com.gwtext.client.widgets.QuickTips;
011: import com.gwtext.client.widgets.form.event.FormListener;
012: import com.gwtext.client.widgets.layout.ContainerLayout;
013:
014: /**
015: * FormPanel uses a {@link com.gwtext.client.widgets.layout.FormLayout} internally, and that is required for fields and labels
016: * to work correctly within the FormPanel's layout. To nest additional layout styles within a FormPanel, you should nest
017: * additional Panels or other containers that can provide additional layout functionality. <b>You should not override FormPanel's layout.</b>
018: */
019: public class FormPanel extends Panel {
020:
021: private static JavaScriptObject configPrototype;
022:
023: static {
024: init();
025: }
026:
027: private static void init() {
028: QuickTips.init();
029: Field.setMsgTarget("side");
030: doInit();
031: }
032:
033: private static native void doInit()/*-{
034: var c = new $wnd.Ext.form.FormPanel();
035: @com.gwtext.client.widgets.form.FormPanel::configPrototype = c.initialConfig;
036: }-*/;
037:
038: protected JavaScriptObject getConfigPrototype() {
039: return configPrototype;
040: }
041:
042: public String getXType() {
043: return "form";
044: }
045:
046: /**
047: * Create a new FormPanel.
048: */
049: public FormPanel() {
050: }
051:
052: /**
053: * Create a new FormPanel.
054: *
055: * @param labelAlign the label alignment
056: */
057: public FormPanel(Position labelAlign) {
058: setLabelAlign(labelAlign);
059: }
060:
061: public FormPanel(JavaScriptObject jsObj) {
062: super (jsObj);
063: }
064:
065: protected native JavaScriptObject create(JavaScriptObject config) /*-{
066: return new $wnd.Ext.form.FormPanel(config);
067: }-*/;
068:
069: /**
070: * Starts monitoring of the valid state of this form. Usually this is done by passing the config option
071: * "monitorValid"
072: */
073: public native void startMonitoring() /*-{
074: var formPanel = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
075: formPanel.startMonitoring();
076: }-*/;
077:
078: /**
079: * Stops monitoring of the valid state of this form.
080: */
081: public native void stopMonitoring() /*-{
082: var formPanel = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
083: formPanel.stopMonitoring();
084: }-*/;
085:
086: /**
087: * Provides access to the Form which this Panel contains. Note that this method must be called only after the FormPanel has been
088: * rendered. <b>Returns null if called before the FormPanel has been rendered.</b>. If you need to add a listener to he form prior to
089: * the FormPanel being rendered, call {@link #addFormListener(com.gwtext.client.widgets.form.event.FormListener)} instead.
090: *
091: * @return the underlying Form, or null if FormPanel not rendered
092: */
093: public native Form getForm() /*-{
094: var formPanel = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()();
095: var formJS = formPanel.getForm();
096: return @com.gwtext.client.widgets.form.Form::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(formJS);
097: }-*/;
098:
099: public void setLayout(ContainerLayout layout) {
100: throw new IllegalArgumentException(
101: "The layout of FormPanel should not be changed.");
102: }
103:
104: /**
105: * Add a Form listener. Although you can add this listener on the {@link com.gwtext.client.widgets.form.Form}
106: * directly, this method is useful to call when you would like to add a FormListener prior to the FormPaanel being rendered.
107: *
108: * @param listener the form listener
109: */
110: public void addFormListener(final FormListener listener) {
111: if (!isRendered()) {
112: addListener("render", new Function() {
113: public void execute() {
114: addFormListener(listener);
115: }
116: });
117: } else {
118: getForm().addListener(listener);
119: }
120: }
121:
122: // -- config properties ---
123:
124: //http://extjs.com/forum/showthread.php?t=4814&highlight=doAction
125: //acts like hidden form fields
126: /**
127: * Parameters to pass with all requests. This effectively acts like Form hidden fields.
128: *
129: * @param params the base params
130: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
131: */
132: public void setBaseParams(UrlParam[] params)
133: throws IllegalStateException {
134: JavaScriptObject paramObj = UrlParam.getJsObj(params);
135: setAttribute("baseParams", paramObj, true);
136: }
137:
138: /**
139: * Valid values are "left," "center" and "right" (defaults to "center").
140: *
141: * @param buttonAlign form button position
142: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
143: */
144: public void setButtonAlign(Position buttonAlign)
145: throws IllegalStateException {
146: setAttribute("buttonAlign", buttonAlign.getPosition(), true);
147: }
148:
149: /**
150: * A {@link com.gwtext.client.data.Reader} (e.g. {@link com.gwtext.client.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
151: * This is completely optional as there is built-in support for processing JSON.
152: *
153: * @param errorReader the error reader
154: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
155: */
156: public void setErrorReader(Reader errorReader)
157: throws IllegalStateException {
158: setAttribute("errorReader", errorReader.getJsObj(), true);
159: }
160:
161: /**
162: * Set true if this form is a file upload.
163: *
164: *
165: * @param fileUpload true if file upload
166: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
167: */
168: public void setFileUpload(boolean fileUpload)
169: throws IllegalStateException {
170: setAttribute("fileUpload", fileUpload, true);
171: }
172:
173: //http://extjs.com/forum/archive/index.php/t-7316.html
174: /**
175: * Set to true to hide all field labels.
176: *
177: * @param hideLabels true to hide field labels
178: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
179: */
180: public void setHideLabels(boolean hideLabels)
181: throws IllegalStateException {
182: setAttribute("hideLabels", hideLabels, true);
183: }
184:
185: /**
186: * A CSS class to apply to the x-form-item of fields. This property cascades to child containers.
187: *
188: * @param itemCls CSS class
189: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
190: */
191: public void setItemCls(String itemCls) throws IllegalStateException {
192: setAttribute("itemCls", itemCls, true);
193: }
194:
195: /**
196: * Valid values are "left," "top" and "right" (defaults to "left"). This property cascades to child containers if not set.
197: *
198: * @param labelAlign label alignment
199: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
200: */
201: public void setLabelAlign(Position labelAlign)
202: throws IllegalStateException {
203: setAttribute("labelAlign", labelAlign.getPosition(), true);
204: }
205:
206: /**
207: * The width of labels. This property cascades to child containers.
208: *
209: * @param labelWidth the label width
210: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
211: */
212: public void setLabelWidth(int labelWidth)
213: throws IllegalStateException {
214: setAttribute("labelWidth", labelWidth, true);
215: }
216:
217: /**
218: * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
219: *
220: * @param method the request method
221: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
222: */
223: public void setMethod(Connection.Method method)
224: throws IllegalStateException {
225: setAttribute("method", method.getMethod(), true);
226: }
227:
228: /**
229: * Minimum width of all buttons in pixels (defaults to 75).
230: *
231: * @param minButtonWidth min button width
232: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
233: */
234: public void setMinButtonWidth(int minButtonWidth)
235: throws IllegalStateException {
236: setAttribute("minButtonWidth", minButtonWidth, true);
237: }
238:
239: /**
240: * The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200).
241: *
242: * @param monitorPoll the monitor poll in milliseconds
243: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
244: */
245: public void setMonitorPoll(int monitorPoll)
246: throws IllegalStateException {
247: setAttribute("monitorPoll", monitorPoll, true);
248: }
249:
250: //http://extjs.com/forum/showthread.php?t=5108&highlight=formBind
251: /**
252: * If true the form monitors its valid state client-side and fires a looping event with that state. This is required
253: * to bind buttons to the valid state using the config value formBind:true on the button.
254: *
255: * @param monitorValid true to enable monitoring
256: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
257: */
258: public void setMonitorValid(boolean monitorValid)
259: throws IllegalStateException {
260: setAttribute("monitorValid", monitorValid, true);
261: }
262:
263: /**
264: * A {@link Reader} (e.g. {@link com.gwtext.client.data.XmlReader}) to be used to read data when executing "load" actions.
265: * This is optional as there is built-in support for processing JSON.
266: *
267: * @param reader the load Reader
268: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
269: */
270: public void setReader(Reader reader) throws IllegalStateException {
271: setAttribute("reader", reader.getJsObj(), true);
272: }
273:
274: /**
275: * Timeout for form actions in seconds (default is 30 seconds).
276: *
277: * @param timeout timeout in seconds
278: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
279: */
280: public void setTimeout(int timeout) throws IllegalStateException {
281: setAttribute("timeout", timeout, true);
282: }
283:
284: /**
285: * If set to true, form.reset() resets to the last loaded or setValues() data instead of when the form was first created.
286: *
287: * @param trackResetOnLoad true to track reset on load
288: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
289: */
290: public void setTrackResetOnLoad(boolean trackResetOnLoad)
291: throws IllegalStateException {
292: setAttribute("trackResetOnLoad", trackResetOnLoad, true);
293: }
294:
295: /**
296: * The URL to use for form actions if one isn't supplied in the action options.
297: *
298: * @param url the url
299: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
300: */
301: public void setUrl(String url) throws IllegalStateException {
302: setAttribute("url", url, true);
303: }
304:
305: /**
306: * By default wait messages are displayed with {@link com.gwtext.client.widgets.MessageBox#wait(long)}.
307: * You can target a specific element by passing its id.
308: *
309: * @param waitMsgTarget ID of the Element to mask
310: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
311: */
312: public void setWaitMsgTarget(String waitMsgTarget)
313: throws IllegalStateException {
314: setAttribute("waitMsgTarget", waitMsgTarget, true);
315: }
316:
317: /**
318: * By default wait messages are displayed with {@link com.gwtext.client.widgets.MessageBox#wait(long)}.
319: * You can mask the form itself by passing in true.
320: *
321: * @param waitMsgTarget true to mask the form
322: * @throws IllegalStateException this property cannot be changed after the Component has been rendered
323: */
324: public void setWaitMsgTarget(boolean waitMsgTarget)
325: throws IllegalStateException {
326: setAttribute("waitMsgTarget", waitMsgTarget, true);
327: }
328: }
|