Source Code Cross Referenced for DemoContextMenuWidget.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 2007 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.util.ArrayList;
018:        import java.util.Arrays;
019:        import java.util.Iterator;
020:        import java.util.List;
021:        import java.util.Locale;
022:        import java.util.Random;
023:        import org.apache.commons.beanutils.BeanPropertyValueEqualsPredicate;
024:        import org.apache.commons.collections.CollectionUtils;
025:        import org.araneaframework.example.main.TemplateBaseWidget;
026:        import org.araneaframework.example.main.release.features.ExampleData;
027:        import org.araneaframework.example.main.release.features.ExampleData.Client;
028:        import org.araneaframework.framework.LocalizationContext.LocaleChangeListener;
029:        import org.araneaframework.http.UpdateRegionContext;
030:        import org.araneaframework.uilib.form.formlist.BeanFormListWidget;
031:        import org.araneaframework.uilib.list.BeanListWidget;
032:        import org.araneaframework.uilib.list.dataprovider.MemoryBasedListDataProvider;
033:        import org.araneaframework.uilib.menu.ContextMenuItem;
034:        import org.araneaframework.uilib.menu.ContextMenuWidget;
035:        import org.araneaframework.uilib.menu.ContextMenuItem.ContextMenuEventEntry;
036:
037:        /**
038:         * @author Taimo Peelo (taimo@araneaframework.org)
039:         */
040:        public class DemoContextMenuWidget extends TemplateBaseWidget implements 
041:                LocaleChangeListener {
042:            protected List friends = new ArrayList();
043:
044:            private MemoryBasedListDataProvider dataProvider = new DataProvider();
045:
046:            //Plays the role of a sequence
047:            private Long lastId = new Long(0);
048:
049:            {
050:                Random rn = new Random();
051:                List allSuggestions = new ArrayList();
052:
053:                for (Iterator i = Arrays.asList(Locale.getISOCountries())
054:                        .iterator(); i.hasNext();) {
055:                    allSuggestions.add(new Locale("en", (String) i.next())
056:                            .getDisplayCountry(Locale.ENGLISH));
057:                }
058:
059:                for (int i = 0; i < ExampleData.males.length; i++) {
060:                    ExampleData.Client friend = new ExampleData.Client();
061:                    friend.setForename(ExampleData.males[i]);
062:                    friend.setId(lastId);
063:                    friend.setSex("M");
064:                    friend.setSurname(ExampleData.fungi[rn
065:                            .nextInt(ExampleData.fungi.length)]);
066:                    friend.setCountry((String) allSuggestions.get(rn
067:                            .nextInt(allSuggestions.size())));
068:                    friends.add(friend);
069:                    lastId = new Long(lastId.longValue() + 1);
070:                }
071:
072:                for (int i = 0; i < ExampleData.females.length; i++) {
073:                    ExampleData.Client friend = new ExampleData.Client();
074:                    friend.setForename(ExampleData.females[i]);
075:                    friend.setSex("F");
076:                    friend.setSurname(ExampleData.fungi[rn
077:                            .nextInt(ExampleData.fungi.length)]);
078:                    friend.setCountry((String) allSuggestions.get(rn
079:                            .nextInt(allSuggestions.size())));
080:                    friends.add(friend);
081:                    lastId = new Long(lastId.longValue() + 1);
082:                }
083:            }
084:
085:            /* Editable list. */
086:            private BeanListWidget list;
087:            /* Actual holder of editable list rows (resides inside EditableBeanListWidget).
088:             Look inside init() method to see where it comes from. */
089:            private BeanFormListWidget formList;
090:
091:            protected void init() throws Exception {
092:                setViewSelector("release/demos/contextMenuDemo");
093:
094:                getL10nCtx().addLocaleChangeListener(this );
095:
096:                createList();
097:                attachContextMenu();
098:            }
099:
100:            private void createList() {
101:                list = new BeanListWidget(ExampleData.Client.class);
102:                addWidget("list", list);
103:                list.setOrderableByDefault(true);
104:                list.addField("sex", "sed.Sex").like();
105:                list.addField("forename", "sed.Forename").like();
106:                list.addField("surname", "sed.Surname").like();
107:                list.addField("country", "common.Country").like();
108:                list.addField("dummy", null, false);
109:
110:                list.setDataProvider(dataProvider);
111:            }
112:
113:            private class DataProvider extends MemoryBasedListDataProvider {
114:                private static final long serialVersionUID = 1L;
115:
116:                protected DataProvider() {
117:                    super (ExampleData.Client.class);
118:                }
119:
120:                public List loadData() throws Exception {
121:                    return friends;
122:                }
123:            }
124:
125:            private ContextMenuWidget createListContextMenu() {
126:                ContextMenuItem menu = new ContextMenuItem();
127:                menu.addMenuItem(new ContextMenuItem(getL10nCtx().localize(
128:                        "common.View"), new ContextMenuEventEntry("viewRecord",
129:                        this , "cMenuparameterSupplier")));
130:                menu.addMenuItem(new ContextMenuItem(getL10nCtx().localize(
131:                        "context.menu.ChangeSex"), new ContextMenuEventEntry(
132:                        "changeSex", this , "cMenuparameterSupplier")));
133:                menu.addMenuItem(new ContextMenuItem(getL10nCtx().localize(
134:                        "common.Remove"), new ContextMenuEventEntry(
135:                        "deleteRecord", this , "cMenuparameterSupplier")));
136:
137:                ContextMenuWidget contextMenuWidget = new ContextMenuWidget(
138:                        menu);
139:
140:                return contextMenuWidget;
141:            }
142:
143:            public void onLocaleChange(Locale oldLocale, Locale newLocale) {
144:                attachContextMenu();
145:            }
146:
147:            private void attachContextMenu() {
148:                list.addWidget("contextmenu", createListContextMenu());
149:            }
150:
151:            private void handleEventViewRecord(String param) {
152:                Client c = (Client) list.getRowFromRequestId(param);
153:                getFlowCtx().start(new ClientViewWidget(c));
154:                // XXX: this is a hack to work around the shortcoming of partial rendering -- namely when flow is switched,
155:                // the regions that are supposed to be updated are of course lost and old flow remains on end-user screen
156:                ((UpdateRegionContext) getEnvironment().getEntry(
157:                        UpdateRegionContext.class)).disableOnce();
158:            }
159:
160:            private void handleEventChangeSex(String param) {
161:                Client c = (Client) list.getRowFromRequestId(param);
162:                if (c.getSex().equals("M"))
163:                    c.setSex("F");
164:                else
165:                    c.setSex("M");
166:            }
167:
168:            private void handleEventDeleteRecord(String param) {
169:                final Client c = (Client) list.getRowFromRequestId(param);
170:                friends.remove(CollectionUtils.find(friends,
171:                        new BeanPropertyValueEqualsPredicate("id", c.getId())));
172:                list.refresh();
173:            }
174:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.