Source Code Cross Referenced for DemoComplexForm.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » example » main » web » demo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » aranea mvc 1.1.1 » org.araneaframework.example.main.web.demo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2006 Webmedia Group Ltd.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of 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,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         **/package org.araneaframework.example.main.web.demo;
016:
017:        import java.util.ArrayList;
018:        import java.util.Arrays;
019:        import java.util.Collection;
020:        import java.util.Iterator;
021:        import java.util.List;
022:        import org.araneaframework.example.main.TemplateBaseWidget;
023:        import org.araneaframework.uilib.event.OnChangeEventListener;
024:        import org.araneaframework.uilib.form.FormWidget;
025:        import org.araneaframework.uilib.form.control.DisplayControl;
026:        import org.araneaframework.uilib.form.control.MultiSelectControl;
027:        import org.araneaframework.uilib.form.control.SelectControl;
028:        import org.araneaframework.uilib.form.data.StringData;
029:        import org.araneaframework.uilib.form.data.StringListData;
030:        import org.araneaframework.uilib.support.DisplayItem;
031:
032:        /**
033:         * @author Taimo Peelo (taimo@araneaframework.org)
034:         */
035:        public class DemoComplexForm extends TemplateBaseWidget {
036:            private static final long serialVersionUID = 1L;
037:            /* Different controls and widgets we want to be accessible all the time are 
038:                 made instance variables by convention. */
039:            private FormWidget complexForm;
040:            /* SelectControl - control which provides various selections from which one must be picked. */
041:            private SelectControl beastSelectionControl;
042:            /* MultiSelectControl - provides various selections from which zero to many can be picked */
043:            private MultiSelectControl concreteBeastMultiSelectionControl;
044:
045:            protected void init() throws Exception {
046:                setViewSelector("demo/demoComplexForm");
047:                putViewData("formLabel", "Complex_Form");
048:
049:                beastSelectionControl = new SelectControl();
050:                /* SelectControls can be added DisplayItems, one by one ... */
051:                beastSelectionControl.addItem(new DisplayItem(null,
052:                        t("select.choose")));
053:                /* or whole collections of value objects, which must have getters for specified value
054:                 * and displayString fields (here, for sampleValue and sampleDisplayString). Note that 
055:                 * both value and displayString must be of String class */
056:                beastSelectionControl.addFromBeanCollection(getSelectItems(),
057:                        "sampleValue", "sampleDisplayString");
058:
059:                /* Adds the onChange event listener to selectControl */
060:                beastSelectionControl
061:                        .addOnChangeEventListener(new OnChangeEventListener() {
062:                            private static final long serialVersionUID = 1L;
063:
064:                            public void onChange() throws Exception {
065:                                /* Form must be converted before new values can be read from form.
066:                                   As we want to be sure that entered data is valid (no random strings
067:                                   where numbers are expected, length and content constraints are met)
068:                                   we usually also validate data before using it for anything. */
069:                                if (complexForm.convertAndValidate()) {
070:                                    // DemoComplexForm.this.getMessageCtx().showInfoMessage("Value in multiselect has changed to " + (String)beastSelectionControl.getRawValue() + ".");
071:                                    // get the value from control (aka what beast was selected).
072:                                    String selectedBeast = (String) beastSelectionControl
073:                                            .getRawValue();
074:
075:                                    // if no beast is selected in our select control, we remove the other 
076:                                    // elements from form that depend directly on selection being made - 
077:                                    // the controls providing possibily for more specific beast selection.
078:                                    if (selectedBeast == null) {
079:                                        complexForm
080:                                                .removeElement("concreteBeastControl");
081:                                        complexForm
082:                                                .removeElement("selectedBeastDesc");
083:                                        return;
084:                                    }
085:
086:                                    // create the multiselectcontrol allowing selection of some beasts of selected type.
087:                                    concreteBeastMultiSelectionControl = new MultiSelectControl();
088:                                    for (Iterator i = getMultiSelectItems(
089:                                            selectedBeast).iterator(); i
090:                                            .hasNext();) {
091:                                        String current = (String) i.next();
092:                                        concreteBeastMultiSelectionControl
093:                                                .addItem(new DisplayItem(
094:                                                        current, current));
095:                                    }
096:
097:                                    // finally add both beast group description and beast selection control to this widget.  
098:                                    complexForm.addElement(
099:                                            "concreteBeastControl", "#"
100:                                                    + t("common.Choose") + " "
101:                                                    + selectedBeast,
102:                                            concreteBeastMultiSelectionControl,
103:                                            new StringListData(), false);
104:                                    complexForm.addElement("selectedBeastDesc",
105:                                            "#" + t("common.Description"),
106:                                            new DisplayControl(),
107:                                            new StringData(), false);
108:                                    // if not dealing with beanforms, form element values are typically set this way
109:                                    complexForm.setValueByFullName(
110:                                            "selectedBeastDesc",
111:                                            new SelectItem(selectedBeast)
112:                                                    .getDescription());
113:                                }
114:                            }
115:                        });
116:
117:                complexForm = new FormWidget();
118:                complexForm.addElement("beastSelection", "natures.beasts",
119:                        beastSelectionControl, new StringData(), false);
120:
121:                addWidget("complexForm", complexForm);
122:            }
123:
124:            // HELPER METHODS AND CLASSES
125:            private Collection getSelectItems() {
126:                List list = new ArrayList();
127:                // note that SelectItem is just an inner class and not anything special
128:                list.add(new SelectItem("  Bird  "));
129:                list.add(new SelectItem(" Animal "));
130:                list.add(new SelectItem("  Fish  "));
131:                list.add(new SelectItem(" Dragon "));
132:                return list;
133:            }
134:
135:            private static final String[] birds = new String[] { "Chicken",
136:                    "Goose", "Duck", "Swan" };
137:            private static final String[] animals = new String[] { "Piglet",
138:                    "Pooh", "Tiger", "Cangaroo" };
139:            private static final String[] fishes = new String[] { "Willy",
140:                    "Nemo", "Dory", "Marlin" };
141:            private static final String[] dragons = new String[] { "Smaug",
142:                    "Chrysophylax", "Devon & Cornwall" };
143:
144:            private Collection getMultiSelectItems(String selectItem) {
145:                List result = new ArrayList();
146:                if (selectItem.equals("Bird")) {
147:                    result.addAll(Arrays.asList(birds));
148:                } else if (selectItem.equals("Animal")) {
149:                    result.addAll(Arrays.asList(animals));
150:                } else if (selectItem.equals("Fish")) {
151:                    result.addAll(Arrays.asList(fishes));
152:                } else if (selectItem.equals("Dragon")) {
153:                    result.addAll(Arrays.asList(dragons));
154:                }
155:
156:                return result;
157:            }
158:
159:            public static class SelectItem {
160:                public String sampleValue;
161:                public String sampleDisplayString;
162:
163:                public SelectItem(String value) {
164:                    this .sampleValue = value.trim();
165:                    this .sampleDisplayString = "> " + value + " <";
166:                }
167:
168:                public String getSampleDisplayString() {
169:                    return sampleDisplayString;
170:                }
171:
172:                public void setSampleDisplayString(String sampleDisplayString) {
173:                    this .sampleDisplayString = sampleDisplayString;
174:                }
175:
176:                public String getSampleValue() {
177:                    return sampleValue;
178:                }
179:
180:                public void setSampleValue(String sampleValue) {
181:                    this .sampleValue = sampleValue;
182:                }
183:
184:                public String getDescription() {
185:                    String result = "";
186:                    if (sampleValue.equals("Bird")) {
187:                        result = "Birds are bipedal, warm-blooded, oviparous vertebrates characterized primarily by feathers, forelimbs modified as wings, and hollow bones.";
188:                    } else if (sampleValue.equals("Animal")) {
189:                        result = "Animals are a major group of organisms, classified as the kingdom Animalia or Metazoa. In general they are multicellular, capable of locomotion and responsive to their environment, and feed by consuming other organisms. Their body plan becomes fixed as they develop, usually early on in their development as embryos, although some undergo a process of metamorphosis later on.";
190:                    } else if (sampleValue.equals("Fish")) {
191:                        result = "A fish is a poikilothermic (cold-blooded) water-dwelling vertebrate with gills.";
192:                    } else if (sampleValue.equals("Dragon")) {
193:                        result = "A dragon is a legendary creature, typically depicted as a large and powerful serpent or other reptile, with magical or spiritual qualities.";
194:                    }
195:                    return result;
196:                }
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.