Source Code Cross Referenced for SimpleInMemoryEditableList.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » example » main » release » features » 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.release.features 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.araneaframework.example.main.release.features;
002:
003:        import java.util.ArrayList;
004:        import java.util.Arrays;
005:        import java.util.Iterator;
006:        import java.util.List;
007:        import java.util.Locale;
008:        import java.util.Random;
009:        import org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate;
010:        import org.apache.commons.collections.CollectionUtils;
011:        import org.araneaframework.example.main.TemplateBaseWidget;
012:        import org.araneaframework.uilib.form.BeanFormWidget;
013:        import org.araneaframework.uilib.form.FormElement;
014:        import org.araneaframework.uilib.form.FormWidget;
015:        import org.araneaframework.uilib.form.constraint.BaseFieldConstraint;
016:        import org.araneaframework.uilib.form.control.TextControl;
017:        import org.araneaframework.uilib.form.data.StringData;
018:        import org.araneaframework.uilib.form.formlist.BeanFormListWidget;
019:        import org.araneaframework.uilib.form.formlist.FormListUtil;
020:        import org.araneaframework.uilib.form.formlist.FormRow;
021:        import org.araneaframework.uilib.form.formlist.adapter.ValidOnlyIndividualFormRowHandler;
022:        import org.araneaframework.uilib.list.EditableBeanListWidget;
023:        import org.araneaframework.uilib.list.dataprovider.MemoryBasedListDataProvider;
024:        import org.araneaframework.uilib.list.util.FormUtil;
025:        import org.araneaframework.uilib.util.MessageUtil;
026:
027:        public class SimpleInMemoryEditableList extends TemplateBaseWidget {
028:            private static final long serialVersionUID = 1L;
029:            protected List friends = new ArrayList();
030:
031:            private MemoryBasedListDataProvider dataProvider = new DataProvider();
032:
033:            private BeanFormListWidget editableRows;
034:
035:            //Plays the role of a sequence
036:            private Long lastId = new Long(0);
037:
038:            {
039:                Random rn = new Random();
040:                List allSuggestions = new ArrayList();
041:
042:                for (Iterator i = Arrays.asList(Locale.getISOCountries())
043:                        .iterator(); i.hasNext();) {
044:                    allSuggestions.add(new Locale("en", (String) i.next())
045:                            .getDisplayCountry(Locale.ENGLISH));
046:                }
047:
048:                for (int i = 0; i < ExampleData.males.length; i++) {
049:                    ExampleData.Client friend = new ExampleData.Client();
050:                    friend.setForename(ExampleData.males[i]);
051:                    friend.setId(lastId);
052:                    friend.setSex("M");
053:                    friend.setSurname(ExampleData.fungi[rn
054:                            .nextInt(ExampleData.fungi.length)]);
055:                    friend.setCountry((String) allSuggestions.get(rn
056:                            .nextInt(allSuggestions.size())));
057:                    friends.add(friend);
058:                    lastId = new Long(lastId.longValue() + 1);
059:                }
060:
061:                for (int i = 0; i < ExampleData.females.length; i++) {
062:                    ExampleData.Client friend = new ExampleData.Client();
063:                    friend.setForename(ExampleData.females[i]);
064:                    friend.setSex("F");
065:                    friend.setSurname(ExampleData.fungi[rn
066:                            .nextInt(ExampleData.fungi.length)]);
067:                    friend.setCountry((String) allSuggestions.get(rn
068:                            .nextInt(allSuggestions.size())));
069:                    friends.add(friend);
070:                    lastId = new Long(lastId.longValue() + 1);
071:                }
072:            }
073:
074:            /* Editable list. */
075:            private EditableBeanListWidget list;
076:            /* Actual holder of editable list rows (resides inside EditableBeanListWidget).
077:               Look inside init() method to see where it comes from. */
078:            private BeanFormListWidget formList;
079:
080:            protected void init() throws Exception {
081:                setViewSelector("release/features/simpleEditableList/simpleInmemoryEditableList");
082:
083:                /* PersonMO class is already familiar from form examples. 
084:                FormRowHandler class that will handle the different row operations. */
085:                list = new EditableBeanListWidget(
086:                        new FriendEditableRowHandler(),
087:                        ExampleData.Client.class);
088:                this .formList = list.getFormList();
089:                addWidget("list", list);
090:                list.setOrderableByDefault(true);
091:                //list.addField("id", "#Id", false);
092:                /* Filtering by fields other than ID is enabled. */
093:                list.addField("sex", "sed.Sex").like();
094:                list.addField("forename", "sed.Forename").like();
095:                list.addField("surname", "sed.Surname").like();
096:                list.addField("country", "common.Country").like();
097:                list.addField("dummy", null, false);
098:
099:                list.setDataProvider(dataProvider);
100:            }
101:
102:            private class DataProvider extends MemoryBasedListDataProvider {
103:                private static final long serialVersionUID = 1L;
104:
105:                protected DataProvider() {
106:                    super (ExampleData.Client.class);
107:                }
108:
109:                public List loadData() throws Exception {
110:                    return friends;
111:                }
112:            }
113:
114:            private class FriendEditableRowHandler extends
115:                    ValidOnlyIndividualFormRowHandler {
116:                private static final long serialVersionUID = 1L;
117:
118:                public FriendEditableRowHandler() {
119:                }
120:
121:                public Object getRowKey(Object rowData) {
122:                    return ((ExampleData.Client) rowData).getId();
123:                }
124:
125:                public void saveValidRow(FormRow editableRow) throws Exception {
126:                    ExampleData.Client rowData = (ExampleData.Client) ((BeanFormWidget) editableRow
127:                            .getForm()).writeToBean(new ExampleData.Client());
128:                    rowData.setId((Long) editableRow.getKey());
129:
130:                    ExampleData.Client toModify = (ExampleData.Client) CollectionUtils
131:                            .find(friends,
132:                                    new BeanPropertyValueEqualsPredicate("id",
133:                                            editableRow.getKey()));
134:                    toModify.edit(rowData);
135:
136:                    editableRow.close();
137:                }
138:
139:                public void deleteRow(Object key) throws Exception {
140:                    Long id = (Long) key;
141:                    ExampleData.Client toRemove = (ExampleData.Client) CollectionUtils
142:                            .find(friends,
143:                                    new BeanPropertyValueEqualsPredicate("id",
144:                                            id));
145:                    friends.remove(toRemove);
146:
147:                    list.getDataProvider().refreshData();
148:                }
149:
150:                public void addValidRow(FormWidget addForm) throws Exception {
151:                    ExampleData.Client newFriend = (ExampleData.Client) (((BeanFormWidget) addForm)
152:                            .writeToBean(new ExampleData.Client()));
153:                    friends.add(newFriend);
154:                    list.getDataProvider().refreshData();
155:                    formList.resetAddForm();
156:                }
157:
158:                // Called to initialize each row in editable list.
159:                public void initFormRow(FormRow editableRow, Object rowData)
160:                        throws Exception {
161:                    editableRow.close();
162:
163:                    BeanFormWidget rowForm = (BeanFormWidget) editableRow
164:                            .getForm();
165:                    addCommonFormFields(rowForm);
166:                    FormListUtil.addEditSaveButtonToRowForm("#", formList,
167:                            rowForm, getRowKey(rowData));
168:                    FormListUtil.addDeleteButtonToRowForm("#", formList,
169:                            rowForm, getRowKey(rowData));
170:
171:                    rowForm.readFromBean(rowData);
172:                }
173:
174:                public void initAddForm(FormWidget addForm) throws Exception {
175:                    addCommonFormFields((BeanFormWidget) addForm);
176:                    FormListUtil.addAddButtonToAddForm("#", formList, addForm);
177:                }
178:
179:                private void addCommonFormFields(BeanFormWidget form)
180:                        throws Exception {
181:                    form.addElement("sex", buildSexElement());
182:                    form.addBeanElement("forename", "sed.Forename",
183:                            new TextControl(), true);
184:                    form.addBeanElement("surname", "sed.Surname",
185:                            new TextControl(), true);
186:                    form.addBeanElement("country", "common.Country",
187:                            new TextControl(), true);
188:                }
189:            }
190:
191:            private FormElement buildSexElement() {
192:                FormElement result = FormUtil.createElement("sed.Sex",
193:                        new TextControl(), new StringData(), true);
194:                result.setConstraint(new SexConstraint());
195:
196:                return result;
197:            }
198:
199:            private class SexConstraint extends BaseFieldConstraint {
200:                public SexConstraint() {
201:                }
202:
203:                protected void validateConstraint() throws Exception {
204:                    String value = (String) getValue();
205:                    if (!("m".equals(value.toLowerCase()) || "f".equals(value
206:                            .toLowerCase()))) {
207:                        addError(MessageUtil.localizeAndFormat(
208:                                "sed.sexcon.ermsg", t(getLabel()),
209:                                getEnvironment()));
210:                    }
211:                }
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.