001: package org.araneaframework.example.main.release.demos;
002:
003: import java.util.Calendar;
004: import java.util.Date;
005: import org.apache.commons.lang.time.DateUtils;
006: import org.araneaframework.example.main.TemplateBaseWidget;
007: import org.araneaframework.example.main.web.OverlayRootWidget;
008: import org.araneaframework.framework.OverlayContext;
009: import org.araneaframework.framework.container.StandardFlowContainerWidget;
010: import org.araneaframework.uilib.event.ProxyOnClickEventListener;
011: import org.araneaframework.uilib.form.FormElement;
012: import org.araneaframework.uilib.form.FormWidget;
013: import org.araneaframework.uilib.form.constraint.NotEmptyConstraint;
014: import org.araneaframework.uilib.form.control.ButtonControl;
015: import org.araneaframework.uilib.form.control.CheckboxControl;
016: import org.araneaframework.uilib.form.control.DateControl;
017: import org.araneaframework.uilib.form.control.DateTimeControl;
018: import org.araneaframework.uilib.form.control.FloatControl;
019: import org.araneaframework.uilib.form.control.TextControl;
020: import org.araneaframework.uilib.form.control.TimeControl;
021: import org.araneaframework.uilib.form.data.BigDecimalData;
022: import org.araneaframework.uilib.form.data.BooleanData;
023: import org.araneaframework.uilib.form.data.DateData;
024: import org.araneaframework.uilib.form.data.StringData;
025:
026: /**
027: * @author Taimo Peelo (taimo@araneaframework.org)
028: */
029: public class ModalDialogDemoWidget extends TemplateBaseWidget {
030: private static final long serialVersionUID = 1L;
031: private FormWidget form;
032: private boolean nested = false;
033:
034: public ModalDialogDemoWidget() {
035: }
036:
037: private ModalDialogDemoWidget(boolean isNested) {
038: this .nested = isNested;
039: }
040:
041: /**
042: * Builds the form.
043: */
044: protected void init() throws Exception {
045: setViewSelector("release/demos/modalDialog");
046:
047: form = new FormWidget();
048:
049: FormElement el = form.createElement("common.Textbox",
050: new TextControl(), new StringData(), false);
051: form.addElement("textbox1", el);
052:
053: form.addElement("checkbox1", "Checkbox", new CheckboxControl(),
054: new BooleanData(), false);
055: form.addElement("dateTime", "common.datetime",
056: new DateTimeControl(), new DateData(), false);
057: form.addElement("time", "common.time", new TimeControl(),
058: new DateData(), false);
059: form.addElement("date", "common.date", new DateControl(),
060: new DateData(), false);
061: form.addElement("number", "common.float", new FloatControl(),
062: new BigDecimalData(), false);
063: // require the number input field to be filled. It could have been achieved already
064: // on formelement creation by setting mandatory attribute to true
065: form.getElement("number").setConstraint(
066: new NotEmptyConstraint());
067: // sets initial value of form element
068:
069: form.setValueByFullName("dateTime", DateUtils.truncate(
070: new Date(), Calendar.MINUTE));
071:
072: // now we construct a button, that is also Control. Reason why we cannot just add it
073: // to form is obvious, we want to add a specific listener to button before.
074: ButtonControl button = new ButtonControl();
075: button.addOnClickEventListener(new ProxyOnClickEventListener(
076: this , "testSimpleForm"));
077: // add the button to form. As the button does not hold any value, Data will be null.
078: form.addElement("button", "common.Submit", button, null, false);
079:
080: // the usual, add the created widget to main widget.
081: addWidget("form", form);
082: }
083:
084: public void handleEventTestSimpleForm() throws Exception {
085: form.convertAndValidate();
086: }
087:
088: public void handleEventNextFlowOverlay() throws Exception {
089: getOverlayCtx().start(
090: new OverlayRootWidget(new StandardFlowContainerWidget(
091: new ModalDialogDemoWidget(true))));
092: }
093:
094: public void handleEventNextFlow() throws Exception {
095: getFlowCtx().start(new ModalDialogDemoWidget(true));
096: }
097:
098: public void handleEventReturn() throws Exception {
099: if (isNested())
100: getFlowCtx().cancel();
101: }
102:
103: public boolean isNested() {
104: return nested;
105: }
106:
107: public OverlayContext getOverlayCtx() {
108: return (OverlayContext) getEnvironment().requireEntry(
109: OverlayContext.class);
110: }
111: }
|