Source Code Cross Referenced for FriendlyUpdateDemoWidget.java in  » Web-Framework » aranea-mvc-1.1.1 » org » araneaframework » example » main » release » demos » 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.demos 
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.release.demos;
016:
017:        import java.io.Serializable;
018:        import java.math.BigDecimal;
019:        import java.util.ArrayList;
020:        import java.util.Arrays;
021:        import java.util.Date;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Locale;
026:        import java.util.Map;
027:        import java.util.Random;
028:        import org.apache.commons.lang.RandomStringUtils;
029:        import org.araneaframework.example.main.TemplateBaseWidget;
030:        import org.araneaframework.example.main.release.features.ExampleData;
031:        import org.araneaframework.framework.LocalizationContext.LocaleChangeListener;
032:        import org.araneaframework.uilib.form.BeanFormWidget;
033:        import org.araneaframework.uilib.form.FormElement;
034:        import org.araneaframework.uilib.form.control.DateControl;
035:        import org.araneaframework.uilib.form.control.FloatControl;
036:        import org.araneaframework.uilib.form.control.NumberControl;
037:        import org.araneaframework.uilib.form.control.SelectControl;
038:        import org.araneaframework.uilib.form.control.TextControl;
039:        import org.araneaframework.uilib.form.data.LongData;
040:        import org.araneaframework.uilib.support.DisplayItem;
041:
042:        /**
043:         * @author Taimo Peelo (taimo@araneaframework.org)
044:         */
045:        public class FriendlyUpdateDemoWidget extends TemplateBaseWidget
046:                implements  LocaleChangeListener {
047:            private BeanFormWidget companyForm;
048:            private BeanFormWidget invoiceForm;
049:            private FormElement firmElement;
050:
051:            static List allCountries = new ArrayList();
052:
053:            static {
054:                for (Iterator i = Arrays.asList(Locale.getISOCountries())
055:                        .iterator(); i.hasNext();) {
056:                    allCountries.add(new Locale("en", (String) i.next())
057:                            .getDisplayCountry(Locale.ENGLISH));
058:                }
059:            }
060:
061:            protected void init() throws Exception {
062:                setViewSelector("release/demos/friendlyUpdateDemo");
063:                getL10nCtx().addLocaleChangeListener(this );
064:
065:                companyForm = buildCompanyForm();
066:                invoiceForm = buildInvoiceForm();
067:
068:                addWidget("companyForm", companyForm);
069:                addWidget("invoiceForm", invoiceForm);
070:            }
071:
072:            private BeanFormWidget buildInvoiceForm() {
073:                BeanFormWidget result = new BeanFormWidget(Invoice.class);
074:                result.addBeanElement("id", "ufriendly.component.invoice.id",
075:                        new TextControl(new Long(10), new Long(10)), true);
076:                result.addBeanElement("date",
077:                        "ufriendly.component.invoice.date", new DateControl(),
078:                        true);
079:                result.addBeanElement("sum", "ufriendly.component.invoice.sum",
080:                        new FloatControl(), true);
081:
082:                return result;
083:            }
084:
085:            private BeanFormWidget buildCompanyForm() {
086:                BeanFormWidget result = new BeanFormWidget(Firm.class);
087:                result.addElement("arkNumber",
088:                        "ufriendly.component.centralfirmid",
089:                        new NumberControl(), new LongData(), true);
090:                result.addBeanElement("registryAddress",
091:                        "ufriendly.component.registryaddress",
092:                        new TextControl(), false);
093:                result.addBeanElement("postalAddress",
094:                        "ufriendly.component.postaladdress", new TextControl(),
095:                        false);
096:                result.addBeanElement("bankAccount",
097:                        "ufriendly.component.bankaccount", new TextControl(),
098:                        false);
099:                result.addBeanElement("vatNumber",
100:                        "ufriendly.component.vatidentifier",
101:                        new NumberControl(), false);
102:                firmElement = result.addBeanElement("firmType",
103:                        "ufriendly.component.firmtype", buildFirmTypeSelect(),
104:                        false);
105:
106:                return result;
107:            }
108:
109:            private Map firms = new HashMap();
110:
111:            private void handleEventFetchData() throws Exception {
112:                if (companyForm.convertAndValidate()) {
113:                    Thread.currentThread().sleep(6000);
114:                    Firm firm = new Firm();
115:                    firm = (Firm) companyForm.writeToBean(firm);
116:
117:                    // present ?
118:                    Firm present = (Firm) firms.get(firm.getArkNumber());
119:                    if (present == null) {
120:                        present = generateFirm(firm.getArkNumber());
121:                    }
122:
123:                    firms.put(present.getArkNumber(), present);
124:                    companyForm.readFromBean(present);
125:                }
126:            }
127:
128:            private void handleEventResetCompanyForm() throws Exception {
129:                companyForm.readFromBean(new Firm());
130:            }
131:
132:            private Firm generateFirm(Long arkNumber) {
133:                Firm result = new Firm();
134:                result.setArkNumber(arkNumber);
135:
136:                Random rnd = new Random();
137:
138:                result.setBankAccount(RandomStringUtils.randomNumeric(16));
139:
140:                String registryCountry = (String) allCountries.get(rnd
141:                        .nextInt(allCountries.size()));
142:                String postalCountry = (String) allCountries.get(rnd
143:                        .nextInt(allCountries.size()));
144:
145:                String registryStreet = ExampleData.fungi[rnd
146:                        .nextInt(ExampleData.fungi.length)];
147:                String postalStreet = ExampleData.fungi[rnd
148:                        .nextInt(ExampleData.fungi.length)];
149:
150:                String registryhouse = String.valueOf(rnd.nextInt(500));
151:                String postalhouse = String.valueOf(rnd.nextInt(200));
152:
153:                result.setRegistryAddress(registryStreet + "-" + registryhouse
154:                        + ", " + registryCountry);
155:                result.setPostalAddress(postalStreet + "-" + postalhouse + ", "
156:                        + postalCountry);
157:                result.setVatNumber(new Long(Math.abs(rnd.nextLong())));
158:                result.setFirmType(new Integer(rnd.nextInt(3) + 1));
159:
160:                return result;
161:            }
162:
163:            private SelectControl buildFirmTypeSelect() {
164:                SelectControl result = new SelectControl();
165:
166:                result.addItem(new DisplayItem("0", t("select.choose")));
167:                result.addItem(new DisplayItem("1",
168:                        t("ufriendly.public.limited")));
169:                result.addItem(new DisplayItem("2", t("ufriendly.npo")));
170:                result.addItem(new DisplayItem("3",
171:                        t("ufriendly.private.limited")));
172:
173:                return result;
174:            }
175:
176:            public void onLocaleChange(Locale oldLocale, Locale newLocale) {
177:                Object value = firmElement.getControl().getRawValue();
178:                SelectControl c = buildFirmTypeSelect();
179:                c.setRawValue(value);
180:                firmElement.setControl(c);
181:            }
182:
183:            public static class Firm implements  Serializable {
184:                private Long arkNumber;
185:                private String registryAddress;
186:                private String postalAddress;
187:                private String bankAccount;
188:                private Long vatNumber;
189:                private Integer firmType;
190:
191:                public Long getArkNumber() {
192:                    return arkNumber;
193:                }
194:
195:                public void setArkNumber(Long arkNumber) {
196:                    this .arkNumber = arkNumber;
197:                }
198:
199:                public String getRegistryAddress() {
200:                    return registryAddress;
201:                }
202:
203:                public void setRegistryAddress(String registryAddress) {
204:                    this .registryAddress = registryAddress;
205:                }
206:
207:                public String getPostalAddress() {
208:                    return postalAddress;
209:                }
210:
211:                public void setPostalAddress(String postalAddress) {
212:                    this .postalAddress = postalAddress;
213:                }
214:
215:                public String getBankAccount() {
216:                    return bankAccount;
217:                }
218:
219:                public void setBankAccount(String bankAccount) {
220:                    this .bankAccount = bankAccount;
221:                }
222:
223:                public Long getVatNumber() {
224:                    return vatNumber;
225:                }
226:
227:                public void setVatNumber(Long vatNumber) {
228:                    this .vatNumber = vatNumber;
229:                }
230:
231:                public Integer getFirmType() {
232:                    return firmType;
233:                }
234:
235:                public void setFirmType(Integer firmType) {
236:                    this .firmType = firmType;
237:                }
238:            }
239:
240:            public static class Invoice implements  Serializable {
241:                private String id;
242:                private Date date;
243:                private BigDecimal sum;
244:
245:                public String getId() {
246:                    return id;
247:                }
248:
249:                public void setId(String id) {
250:                    this .id = id;
251:                }
252:
253:                public Date getDate() {
254:                    return date;
255:                }
256:
257:                public void setDate(Date date) {
258:                    this .date = date;
259:                }
260:
261:                public BigDecimal getSum() {
262:                    return sum;
263:                }
264:
265:                public void setSum(BigDecimal sum) {
266:                    this.sum = sum;
267:                }
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.