Package org.olat.test.guidemo

Source Code of org.olat.test.guidemo.GuiDemoForm

/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <p>
*/

package org.olat.test.guidemo;

import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.olat.core.gui.components.form.Form;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.gui.formelements.LinkElement;
import org.olat.core.gui.formelements.PopupData;
import org.olat.core.gui.formelements.RadioButtonGroupElement;
import org.olat.core.gui.formelements.SpacerElement;
import org.olat.core.gui.formelements.StaticMultipleSelectionElement;
import org.olat.core.gui.formelements.StaticSingleSelectionElement;
import org.olat.core.gui.formelements.TextAreaElement;
import org.olat.core.gui.formelements.TextElement;
import org.olat.core.gui.formelements.TitleElement;
import org.olat.core.gui.formelements.WikiMarkupTextAreaElement;
import org.olat.core.gui.translator.Translator;

public class GuiDemoForm extends Form {

  TitleElement title;
  SpacerElement spacer;
  LinkElement link;
  TextElement text, readonly, date;
  TextAreaElement textarea;
 
  public GuiDemoForm(String name, Translator translator, WindowControl wControl) {
    super(name, translator);
   
    // title
    title = new TitleElement("guidemo.form.title");
    addFormElement("title", title);
   
    // text
    text = new TextElement("guidemo.form.text", 50);
    text.setMandatory(true);
    text.setExample("You may give examples for any form field, whcih is shown below the field.");
    text.setPopupData(new PopupData("textarea", "popup", "guidemo.gorm.popup", 100, 100));
    addFormElement("text", text);
   
    // readonly
    readonly = new TextElement("guidemo.form.readonly", 10);
    readonly.setValue("readonly");
    readonly.setReadOnly(true);
    addFormElement("readonly", readonly);

    // date chooser
    date = new TextElement("guidemo.form.date", 10);
    date.setDateChooserDateFormat("%d.%m.%Y");
    date.setUseDateChooser(true);
    date.setExample("Format: dd.mm.yyyy [e.g. 17.04.2007]");
    addFormElement("date", date);
   
    link = new LinkElement("guidemo.form.link", "http://www.google.com/", "Link to google.com");
    addFormElement("link", link);
   
    // radio
    String[] keys = new String[] { "1", "2", "3", "4" };
    String[] lables = new String[] { "red", "green", "blue", "yellow" };
    StaticSingleSelectionElement pulldown = new StaticSingleSelectionElement("guidemo.form.pulldown", keys, lables);
    addFormElement("pulldown", pulldown);

    keys = new String[] { "1", "2" };
    lables = new String[] { "yes", "no" };
    RadioButtonGroupElement radio = new RadioButtonGroupElement(true, "guidemo.form.radio1", keys, lables);
    radio.select("1", true);
    addFormElement("radio1", radio);
   
    keys = new String[] { "1", "2" };
    lables = new String[] { "yes", "no" };
    radio = new RadioButtonGroupElement(false, "guidemo.form.radio2", keys, lables);
    radio.select("2", true);
    addFormElement("radio2", radio);

    // checkbox
    keys = new String[] { "1", "2", "3", "4" };
    lables = new String[] { "square", "circle", "rectangle", "triangle" };
    StaticMultipleSelectionElement checkbox = new StaticMultipleSelectionElement("guidemo.form.checkbox", keys, lables, true);
    addFormElement("checkbox", checkbox);
   
    spacer = new SpacerElement();
    addFormElement("spacer", spacer);
   
    textarea = new TextAreaElement("guidemo.form.textarea", 10, 50);
    addFormElement("textarea", textarea);

    WikiMarkupTextAreaElement wiki = new WikiMarkupTextAreaElement("guidemo.form.wiki", 10, 50);
    addFormElement("wiki", wiki);

    // submit / cancel keys
    addSubmitKey("submit");
    setCancelButton();
  }

  public boolean validate() {
    boolean valid = true;
    valid = valid && !text.isEmpty("guidemo.form.error.notempty");
    valid = valid && date.matches("\\d{2}\\.\\d{2}\\.\\d{4}", "guidemo.form.error.date");
    Date d = new SimpleDateFormat("dd.MM.yyyy").parse(date.getValue(), new ParsePosition(0));
    if (d == null) {
      date.setErrorKey("guidemo.form.error.date");
      return false;
    }
    return valid;
  }

}
TOP

Related Classes of org.olat.test.guidemo.GuiDemoForm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.