Source Code Cross Referenced for ListViewer.java in  » Ajax » MyGWT » net » mygwt » ui » client » viewer » 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 » Ajax » MyGWT » net.mygwt.ui.client.viewer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *     Darrell Meyer <darrell@mygwt.net> - derived implementation
011:         *******************************************************************************/package net.mygwt.ui.client.viewer;
012:
013:        import java.util.ArrayList;
014:        import java.util.Iterator;
015:
016:        import net.mygwt.ui.client.Events;
017:        import net.mygwt.ui.client.event.BaseEvent;
018:        import net.mygwt.ui.client.event.Listener;
019:        import net.mygwt.ui.client.widget.Component;
020:        import net.mygwt.ui.client.widget.List;
021:        import net.mygwt.ui.client.widget.ListItem;
022:
023:        import com.google.gwt.user.client.ui.Widget;
024:
025:        /**
026:         * A concrete viewer based for a <code>List</code>.
027:         * 
028:         * @see List
029:         */
030:        public class ListViewer extends Viewer implements  ICheckable {
031:
032:            private List list;
033:            private ArrayList checkChangeListener;
034:
035:            /**
036:             * Creates a new list intance.
037:             * 
038:             * @param list the list
039:             */
040:            public ListViewer(List list) {
041:                this .list = list;
042:                list.getElement();
043:                hookWidget(list);
044:            }
045:
046:            public void add(Object elem) {
047:                renderItem(elem, list.getWidgetCount());
048:            }
049:
050:            public void addCheckStateListener(ICheckStateListener listener) {
051:                if (checkChangeListener == null) {
052:                    checkChangeListener = new ArrayList();
053:                }
054:                if (!checkChangeListener.contains(listener)) {
055:                    checkChangeListener.add(listener);
056:                }
057:            }
058:
059:            public Widget findItem(Object elem) {
060:                int size = list.getWidgetCount();
061:                for (int i = 0; i < size; i++) {
062:                    ListItem item = list.getItem(i);
063:                    Object data = item.getData();
064:                    if (getComparer() != null) {
065:                        if (getComparer().equals(elem, data)) {
066:                            return item;
067:                        } else {
068:                            continue;
069:                        }
070:                    }
071:                    if (elem == data || (elem != null && elem.equals(data))) {
072:                        return item;
073:                    }
074:                }
075:                return null;
076:            }
077:
078:            public Object[] getActiveElements() {
079:                ArrayList temp = new ArrayList();
080:                int count = list.getItemCount();
081:                for (int i = 0; i < count; i++) {
082:                    ListItem item = list.getItem(i);
083:                    if (item.isVisible()) {
084:                        temp.add(item.getData());
085:                    }
086:                }
087:                return temp.toArray();
088:            }
089:
090:            public boolean getChecked(Object element) {
091:                ListItem item = (ListItem) findItem(element);
092:                if (item != null) {
093:                    return item.isChecked();
094:                }
095:                return false;
096:            }
097:
098:            /**
099:             * Returns the current checked selection.
100:             * 
101:             * @return the checked elements
102:             */
103:            public ISelection getCheckedSelection() {
104:                ListItem[] items = list.getChecked();
105:                if (items.length == 0) {
106:                    return DefaultSelection.EMPTY;
107:                }
108:                ArrayList checked = new ArrayList();
109:                for (int i = 0; i < items.length; i++) {
110:                    checked.add(items[i].getData());
111:                }
112:                return new DefaultSelection(checked);
113:            }
114:
115:            /**
116:             * Returns the viewer's list widget.
117:             * 
118:             * @return the list
119:             */
120:            public List getList() {
121:                return list;
122:            }
123:
124:            public Widget getWidget() {
125:                return list;
126:            }
127:
128:            public void insert(Object elem, int index) {
129:                renderItem(elem, index);
130:            }
131:
132:            public void remove(Object elem) {
133:                ListItem item = (ListItem) findItem(elem);
134:                if (item != null) {
135:                    removeElement(elem);
136:                    item.setData(null);
137:                }
138:            }
139:
140:            public void removeCheckStateListener(ICheckStateListener listener) {
141:                if (checkChangeListener != null) {
142:                    checkChangeListener.remove(listener);
143:                }
144:            }
145:
146:            public boolean setChecked(Object element, boolean state) {
147:                ListItem item = (ListItem) findItem(element);
148:                if (item != null) {
149:                    item.setChecked(state);
150:                    return true;
151:                }
152:                return false;
153:            }
154:
155:            public void setSelection(ISelection selection, boolean reveal) {
156:                java.util.List selected = selection.toList();
157:                int ct = list.getWidgetCount();
158:                for (int i = 0; i < ct; i++) {
159:                    ListItem item = list.getItem(i);
160:                    Object elem = item.getData();
161:                    if (selected.contains(elem)) {
162:                        list.select(i);
163:                    } else {
164:                        list.deselect(i);
165:                    }
166:                }
167:            }
168:
169:            public void update() {
170:                int ct = list.getWidgetCount();
171:                for (int i = 0; i < ct; i++) {
172:                    updateInternal(list.getItem(i));
173:                }
174:            }
175:
176:            public void update(Object elem) {
177:                ListItem item = (ListItem) findItem(elem);
178:                if (item != null) {
179:                    item.setData(elem);
180:                    updateInternal(item);
181:                }
182:
183:            }
184:
185:            protected java.util.List getSelectedFromWidget() {
186:                ArrayList elems = new ArrayList();
187:                for (int i = 0; i < list.getSelection().length; i++) {
188:                    ListItem item = (ListItem) list.getSelection()[i];
189:                    elems.add(item.getData());
190:                }
191:                return elems;
192:            }
193:
194:            protected void hookWidget(Component widget) {
195:                super .hookWidget(widget);
196:                widget.addListener(Events.CheckChange, new Listener() {
197:                    public void handleEvent(BaseEvent be) {
198:                        fireCheckStateChanged(be);
199:                    }
200:                });
201:            }
202:
203:            protected void onInputReceived(Object input) {
204:                renderList();
205:            }
206:
207:            protected void renderItem(Object elem, int position) {
208:                LabelProvider lp = (LabelProvider) getLabelProvider();
209:                ListItem item = new ListItem();
210:                item.setData(elem);
211:                item.setText(lp.getText(elem));
212:                String style = lp.getIconStyle(elem);
213:                if (style != null) {
214:                    item.setIconStyle(lp.getIconStyle(elem));
215:                }
216:                list.insert(item, position);
217:            }
218:
219:            protected void renderList() {
220:                list.removeAll();
221:                Object[] elems = filter(elements);
222:                elems = sortElements(elems);
223:                for (int i = 0; i < elems.length; i++) {
224:                    Object element = elems[i];
225:                    renderItem(element, i);
226:                }
227:            }
228:
229:            private void fireCheckStateChanged(BaseEvent be) {
230:                if (checkChangeListener != null) {
231:                    ListItem item = (ListItem) be.item;
232:                    CheckStateChangedEvent evt = new CheckStateChangedEvent(
233:                            this , item.getData(), item.isChecked());
234:                    Iterator it = checkChangeListener.iterator();
235:                    while (it.hasNext()) {
236:                        ((ICheckStateListener) it.next())
237:                                .checkStateChanged(evt);
238:                    }
239:                }
240:            }
241:
242:            private void updateInternal(ListItem item) {
243:                LabelProvider lp = (LabelProvider) getLabelProvider();
244:                Object elem = item.getData();
245:                item.setText(lp.getText(elem));
246:                String style = lp.getIconStyle(elem);
247:                if (style != null) {
248:                    item.setIconStyle(lp.getIconStyle(elem));
249:                }
250:            }
251:
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.