Source Code Cross Referenced for AbstractHierarchyComponent.java in  » Web-Framework » ThinWire » thinwire » ui » 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 » ThinWire » thinwire.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:        #IFNDEF ALT_LICENSE
003:                                   ThinWire(R) RIA Ajax Framework
004:                         Copyright (C) 2003-2007 Custom Credit Systems
005:
006:          This library is free software; you can redistribute it and/or modify it under
007:          the terms of the GNU Lesser General Public License as published by the Free
008:          Software Foundation; either version 2.1 of the License, or (at your option) any
009:          later version.
010:
011:          This library is distributed in the hope that it will be useful, but WITHOUT ANY
012:          WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013:          PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015:          You should have received a copy of the GNU Lesser General Public License along
016:          with this library; if not, write to the Free Software Foundation, Inc., 59
017:          Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019:          Users who would rather have a commercial license, warranty or support should
020:          contact the following company who invented, built and supports the technology:
021:          
022:                        Custom Credit Systems, Richardson, TX 75081, USA.
023:           	            email: info@thinwire.com    ph: +1 (888) 644-6405
024:         	                        http://www.thinwire.com
025:        #ENDIF
026:         [ v1.2_RC2 ] 
027:         */
028:        package thinwire.ui;
029:
030:        import java.util.AbstractList;
031:        import java.util.ArrayList;
032:        import java.util.List;
033:
034:        import thinwire.ui.event.ActionEvent;
035:        import thinwire.ui.event.ActionListener;
036:        import thinwire.ui.event.ItemChangeListener;
037:        import thinwire.ui.event.ItemChangeEvent.Type;
038:        import thinwire.util.ImageInfo;
039:
040:        /**
041:         * @author Joshua J. Gertzen
042:         */
043:        abstract class AbstractHierarchyComponent<HI extends AbstractHierarchyComponent.Item>
044:                extends AbstractComponent implements  HierarchyComponent<HI> {
045:            private static class ChildList<I extends Item> extends
046:                    AbstractList<I> {
047:                private List<I> l = new ArrayList<I>(3);
048:                private Item parent;
049:
050:                private ChildList(Item parent) {
051:                    this .parent = parent;
052:                }
053:
054:                public void add(int index, I item) {
055:                    if (item.parent != null)
056:                        throw new IllegalStateException(
057:                                "item.getParent() != null");
058:                    l.add(index, item);
059:                    modCount++;
060:                    item.setParent(parent);
061:                    AbstractHierarchyComponent hier = parent.getHierarchy();
062:                    if (hier != null)
063:                        hier.icei.fireItemChange(parent, Type.ADD, index, null,
064:                                item);
065:                }
066:
067:                public I get(int index) {
068:                    return l.get(index);
069:                }
070:
071:                public I set(int index, I item) {
072:                    if (item.parent != null)
073:                        throw new IllegalStateException(
074:                                "item.getParent() != null");
075:                    AbstractHierarchyComponent hier = parent.getHierarchy();
076:                    I ret = l.get(index);
077:                    hier.removingItem(ret);
078:                    l.set(index, item);
079:                    ret.setParent(null);
080:                    item.setParent(parent);
081:                    if (hier != null)
082:                        hier.icei.fireItemChange(parent, Type.SET, index, ret,
083:                                item);
084:                    return ret;
085:                }
086:
087:                public I remove(int index) {
088:                    modCount++;
089:                    AbstractHierarchyComponent hier = parent.getHierarchy();
090:                    I item = l.get(index);
091:                    hier.removingItem(item);
092:                    l.remove(index);
093:                    item.setParent(null);
094:                    if (hier != null)
095:                        hier.icei.fireItemChange(parent, Type.REMOVE, index,
096:                                item, null);
097:                    return item;
098:                }
099:
100:                public int size() {
101:                    return l.size();
102:                }
103:            }
104:
105:            static abstract class Item<H extends AbstractHierarchyComponent, I extends AbstractHierarchyComponent.Item>
106:                    implements  HierarchyComponent.Item<H, I> {
107:                private String text = "";
108:                private ImageInfo imageInfo = new ImageInfo(null);
109:                private Object userObject;
110:                private Object parent;
111:                private List<I> children;
112:
113:                public String getText() {
114:                    return text;
115:                }
116:
117:                public void setText(String text) {
118:                    String oldText = this .text;
119:                    if (text == null)
120:                        text = "";
121:                    this .text = text;
122:                    H hier = getHierarchy();
123:                    if (hier != null)
124:                        hier.firePropertyChange(this , PROPERTY_ITEM_TEXT,
125:                                oldText, text);
126:                }
127:
128:                public String getImage() {
129:                    return imageInfo.getName();
130:                }
131:
132:                public void setImage(String image) {
133:                    String oldImage = this .imageInfo.getName();
134:                    imageInfo = new ImageInfo(image);
135:                    H hier = getHierarchy();
136:                    if (hier != null)
137:                        hier.firePropertyChange(this , PROPERTY_ITEM_IMAGE,
138:                                oldImage, this .imageInfo.getName());
139:                }
140:
141:                public ImageInfo getImageInfo() {
142:                    return imageInfo;
143:                }
144:
145:                public Object getUserObject() {
146:                    return userObject;
147:                }
148:
149:                public void setUserObject(Object value) {
150:                    Object oldValue = this .userObject;
151:                    this .userObject = value;
152:                    H hier = getHierarchy();
153:                    if (hier != null)
154:                        hier.firePropertyChange(this ,
155:                                PROPERTY_ITEM_USER_OBJECT, oldValue,
156:                                this .userObject);
157:                }
158:
159:                public int getIndex() {
160:                    if (parent == null)
161:                        throw new IllegalStateException("getParent() == null");
162:                    if (parent instanceof  HierarchyComponent)
163:                        throw new IllegalStateException(
164:                                "getParent() instanceof Hierarchy");
165:                    return ((Item) parent).getChildren().indexOf(this );
166:                }
167:
168:                public H getHierarchy() {
169:                    Object parent = this ;
170:
171:                    while (parent != null
172:                            && !(parent instanceof  AbstractHierarchyComponent))
173:                        parent = ((I) parent).getParent();
174:
175:                    return (H) parent;
176:                }
177:
178:                public Object getParent() {
179:                    return parent;
180:                }
181:
182:                private void setParent(Object parent) {
183:                    this .parent = parent;
184:                }
185:
186:                public boolean hasChildren() {
187:                    return children == null ? false : children.size() > 0;
188:                }
189:
190:                public List<I> getChildren() {
191:                    if (children == null)
192:                        children = new ChildList<I>(this );
193:                    return children;
194:                }
195:
196:                public String toString() {
197:                    return "text:"
198:                            + text
199:                            + ",image:"
200:                            + imageInfo.getName()
201:                            + ",children.size():"
202:                            + (children == null ? 0 : children.size())
203:                            + ",parent:"
204:                            + (parent == null ? null : parent.getClass()
205:                                    .getName()
206:                                    + "@" + System.identityHashCode(parent));
207:                }
208:            }
209:
210:            private HI rootItem;
211:            private EventListenerImpl<ItemChangeListener> icei;
212:
213:            AbstractHierarchyComponent(HI rootItem,
214:                    EventListenerImpl.SubTypeValidator actionValidator) {
215:                super (actionValidator);
216:                EventListenerImpl<ItemChangeListener> gicei = app == null ? null
217:                        : app.getGlobalListenerSet(ItemChangeListener.class,
218:                                false);
219:                icei = new EventListenerImpl<ItemChangeListener>(this ,
220:                        ItemChangeListener.class, null, gicei);
221:                this .rootItem = rootItem;
222:                rootItem.setParent(this );
223:            }
224:
225:            void removingItem(HI item) {
226:
227:            }
228:
229:            public HI getRootItem() {
230:                return rootItem;
231:            }
232:
233:            public void addItemChangeListener(ItemChangeListener listener) {
234:                icei.addListener(listener);
235:            }
236:
237:            public void removeItemChangeListener(ItemChangeListener listener) {
238:                icei.removeListener(listener);
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.