KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > contrib > dbroggisch > examples > model > forms > ExampleFormMap


1 /*
2  * Copyright (C) 2003 Diez B. Roggisch [deets@web.de]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: ExampleFormMap.java,v 1.2 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.contrib.dbroggisch.examples.model.forms;
21
22 import org.enhydra.barracuda.contrib.dbroggisch.repopulation.*;
23 import org.enhydra.barracuda.core.forms.*;
24 import org.enhydra.barracuda.core.comp.*;
25 import org.enhydra.barracuda.core.forms.validators.*;
26
27 public class ExampleFormMap extends RepopulationFormMap {
28
29     public final static String JavaDoc MODEL_NAME = "ExampleModel";
30     public final static String JavaDoc GROUP = "GROUP";
31     public final static String JavaDoc CHECKBOX = "CHECKBOX";
32     public final static String JavaDoc SELECT = "SELECT";
33     public final static String JavaDoc TEXTAREA = "TEXTAREA";
34     public final static String JavaDoc SIMPLECHECKBOX = "SIMPLECHECKBOX";
35     public ExampleFormMap() {
36         setName(MODEL_NAME);
37         // This element will create its own child templatemodel with the name
38
// MODEL_NAME + "_" + GROUP
39
// The choices will be represented by radiobuttons due to the allowMultipleValues property
40
// beeing set to false.
41
defineElement(new GroupFormElement(
42                                            new TestList(),
43                                            GROUP,
44                                            FormType.INTEGER,
45                                            null,
46                                            new And(new SelectFormValidator(), new NotNullValidator()),
47                                            false));
48
49         // This element is similar to the preceeding one, with the exception that it will be rendered
50
// useing CheckBoxes - it allows for multiple values.
51
defineElement(new GroupFormElement(
52                                            new TestList(),
53                                            CHECKBOX,
54                                            FormType.INTEGER,
55                                            null,
56                                            new And(new SelectFormValidator(), new NotNullValidator()),
57                                            true));
58
59         defineElement(new SelectFormElement(
60                                             new TestList(),
61                                             SELECT,
62                                             FormType.INTEGER,
63                                             null,
64                                             new SelectFormValidator("Element no. " + 0, "You're not allowed to select the first element!"),
65                                             false));
66
67         defineElement(new TextAreaFormElement(
68                                               TEXTAREA,
69                                               null,
70                                               null));
71
72         defineElement(new CheckboxFormElement(SIMPLECHECKBOX,
73                                               FormType.BOOLEAN));
74
75     }
76
77     public static class TestList extends DefaultListModel {
78
79         public TestList() {
80             for(int i = 0; i < 5; i++) {
81                 add(new DefaultItemMap("" + i, "Element no. " + i));
82             }
83         }
84     }
85 }
86
Popular Tags