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


001:        /*
002:         * MyGWT Widget Library
003:         * Copyright(c) 2007, MyGWT.
004:         * licensing@mygwt.net
005:         * 
006:         * http://mygwt.net/license
007:         */
008:        package net.mygwt.ui.client.widget.tree;
009:
010:        import java.util.ArrayList;
011:        import java.util.List;
012:
013:        import net.mygwt.ui.client.Events;
014:        import net.mygwt.ui.client.MyGWT;
015:        import net.mygwt.ui.client.event.BaseEvent;
016:        import net.mygwt.ui.client.util.Util;
017:
018:        import com.google.gwt.user.client.Command;
019:        import com.google.gwt.user.client.DeferredCommand;
020:
021:        /**
022:         * A multi-select tree selection model.
023:         * 
024:         * <dl>
025:         * <dt><b>Events:</b></dt>
026:         * 
027:         * <dd><b>SelectionChange</b> : (source this, widget, item, items)<br>
028:         * <div>Fires after the selection has changed.</div>
029:         * <ul>
030:         * <li>source : this</li>
031:         * <li>widget : the table</li>
032:         * <li>item : single selection or null</li>
033:         * <li>items : multi selection or null</li>
034:         * </ul>
035:         * </dd>
036:         * </dl>
037:         */
038:        public class MultiSelectionModel extends TreeSelectionModel {
039:
040:            private List selItems;
041:
042:            /**
043:             * Creates a new multi select selection model.
044:             */
045:            public MultiSelectionModel() {
046:                selItems = new ArrayList();
047:            }
048:
049:            public void deselectAll() {
050:                if (selItems.size() > 0) {
051:                    while (selItems.size() > 0) {
052:                        TreeItem item = (TreeItem) selItems.remove(0);
053:                        item.getUI().onSelectedChange(false);
054:                    }
055:                    BaseEvent be = new BaseEvent();
056:                    be.widget = tree;
057:                    be.items = Util.createArray(selItems);
058:                    fireEvent(Events.SelectionChange, be);
059:                    tree.fireEvent(Events.SelectionChange, be);
060:                }
061:            }
062:
063:            /**
064:             * Returns a list of selected items.
065:             * 
066:             * @return the selected items
067:             */
068:            public TreeItem[] getSelection() {
069:                return (TreeItem[]) selItems.toArray(new TreeItem[0]);
070:            }
071:
072:            public boolean isSelected(TreeItem item) {
073:                return selItems.contains(item);
074:            }
075:
076:            public void select(TreeItem item) {
077:                select(item, false);
078:            }
079:
080:            /**
081:             * Selects a item.
082:             * 
083:             * @param item the item to be selected
084:             * @param keepSelected <code>true</code> to preserve selections
085:             */
086:            public void select(final TreeItem item, boolean keepSelected) {
087:                if (!keepSelected) {
088:                    deselectAll();
089:                }
090:                if (isSelected(item)) {
091:                    lastSelItem = item;
092:                    return;
093:                }
094:                selItems.add(item);
095:                lastSelItem = item;
096:                selItem = item;
097:                item.getUI().onSelectedChange(true);
098:                BaseEvent be = new BaseEvent();
099:                be.widget = tree;
100:                be.items = Util.createArray(selItems);
101:                fireEvent(Events.SelectionChange, be);
102:                tree.fireEvent(Events.SelectionChange, be);
103:                if (MyGWT.isSafari) {
104:                    DeferredCommand.addCommand(new Command() {
105:                        public void execute() {
106:                            tree.focus();
107:                        }
108:                    });
109:                }
110:            }
111:
112:            /**
113:             * Selects a list of item's.
114:             * 
115:             * @param items the items to be selected
116:             */
117:            public void selectItems(List items) {
118:                for (int i = 0; i < items.size(); i++) {
119:                    TreeItem item = (TreeItem) items.get(i);
120:                    select(item);
121:                }
122:            }
123:
124:            /**
125:             * Deslects a list of items.
126:             * 
127:             * @param items the items to be deselected
128:             */
129:            public void deselect(List items) {
130:                for (int i = 0; i < items.size(); i++) {
131:                    TreeItem item = (TreeItem) items.get(i);
132:                    deselect(item);
133:                }
134:            }
135:
136:            public void deselect(TreeItem item) {
137:                if (selItems.contains(item)) {
138:                    item.getUI().onSelectedChange(false);
139:                    selItems.remove(item);
140:                    BaseEvent be = new BaseEvent();
141:                    be.widget = tree;
142:                    be.items = Util.createArray(selItems);
143:                    fireEvent(Events.SelectionChange, be);
144:                    tree.fireEvent(Events.SelectionChange, be);
145:                }
146:            }
147:
148:            protected void onItemClick(TreeItem item, BaseEvent be) {
149:                if (be.isRightClick()) {
150:                    return;
151:                }
152:                if (!be.within(item.getUI().getJointEl())) {
153:                    if (isSelected(item) && be.isControlKey()) {
154:                        deselect(item);
155:                    } else {
156:                        select(item, be.isControlKey());
157:                    }
158:                }
159:            }
160:
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.