Source Code Cross Referenced for DefaultProperty.java in  » Swing-Library » l2fprod-common » com » l2fprod » common » propertysheet » 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 » Swing Library » l2fprod common » com.l2fprod.common.propertysheet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * L2FProd.com Common Components 7.3 License.
003:         *
004:         * Copyright 2005-2007 L2FProd.com
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         *
010:         *     http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */package com.l2fprod.common.propertysheet;
018:
019:        import com.l2fprod.common.beans.BeanUtils;
020:
021:        import java.lang.reflect.Method;
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.Collection;
025:        import java.util.Iterator;
026:        import java.util.List;
027:
028:        /**
029:         * DefaultProperty. <br>
030:         *  
031:         */
032:        public class DefaultProperty extends AbstractProperty {
033:
034:            private String name;
035:            private String displayName;
036:            private String shortDescription;
037:            private Class type;
038:            private boolean editable = true;
039:            private String category;
040:            private Property parent;
041:            private List subProperties = new ArrayList();
042:
043:            public String getName() {
044:                return name;
045:            }
046:
047:            public void setName(String name) {
048:                this .name = name;
049:            }
050:
051:            public String getDisplayName() {
052:                return displayName;
053:            }
054:
055:            public void setDisplayName(String displayName) {
056:                this .displayName = displayName;
057:            }
058:
059:            public String getShortDescription() {
060:                return shortDescription;
061:            }
062:
063:            public void setShortDescription(String shortDescription) {
064:                this .shortDescription = shortDescription;
065:            }
066:
067:            public Class getType() {
068:                return type;
069:            }
070:
071:            public void setType(Class type) {
072:                this .type = type;
073:            }
074:
075:            public boolean isEditable() {
076:                return editable;
077:            }
078:
079:            public void setEditable(boolean editable) {
080:                this .editable = editable;
081:            }
082:
083:            public String getCategory() {
084:                return category;
085:            }
086:
087:            public void setCategory(String category) {
088:                this .category = category;
089:            }
090:
091:            /**
092:             * Reads the value of this Property from the given object. It uses reflection
093:             * and looks for a method starting with "is" or "get" followed by the
094:             * capitalized Property name.
095:             */
096:            public void readFromObject(Object object) {
097:                try {
098:                    Method method = BeanUtils.getReadMethod(object.getClass(),
099:                            getName());
100:                    if (method != null) {
101:                        Object value = method.invoke(object, null);
102:                        initializeValue(value); // avoid updating parent or firing property change
103:                        if (value != null) {
104:                            for (Iterator iter = subProperties.iterator(); iter
105:                                    .hasNext();) {
106:                                Property subProperty = (Property) iter.next();
107:                                subProperty.readFromObject(value);
108:                            }
109:                        }
110:                    }
111:                } catch (Exception e) {
112:                    throw new RuntimeException(e);
113:                }
114:            }
115:
116:            /**
117:             * Writes the value of the Property to the given object. It uses reflection
118:             * and looks for a method starting with "set" followed by the capitalized
119:             * Property name and with one parameter with the same type as the Property.
120:             */
121:            public void writeToObject(Object object) {
122:                try {
123:                    Method method = BeanUtils.getWriteMethod(object.getClass(),
124:                            getName(), getType());
125:                    if (method != null) {
126:                        method.invoke(object, new Object[] { getValue() });
127:                    }
128:                } catch (Exception e) {
129:                    throw new RuntimeException(e);
130:                }
131:            }
132:
133:            /* (non-Javadoc)
134:             * @see com.l2fprod.common.propertysheet.Property#setValue(java.lang.Object)
135:             */
136:            public void setValue(Object value) {
137:                super .setValue(value);
138:                if (parent != null) {
139:                    Object parentValue = parent.getValue();
140:                    if (parentValue != null) {
141:                        writeToObject(parentValue);
142:                        parent.setValue(parentValue);
143:                    }
144:                }
145:                if (value != null) {
146:                    for (Iterator iter = subProperties.iterator(); iter
147:                            .hasNext();) {
148:                        Property subProperty = (Property) iter.next();
149:                        subProperty.readFromObject(value);
150:                    }
151:                }
152:            }
153:
154:            public int hashCode() {
155:                return 28
156:                        + ((name != null) ? name.hashCode() : 3)
157:                        + ((displayName != null) ? displayName.hashCode() : 94)
158:                        + ((shortDescription != null) ? shortDescription
159:                                .hashCode() : 394)
160:                        + ((category != null) ? category.hashCode() : 34)
161:                        + ((type != null) ? type.hashCode() : 39)
162:                        + Boolean.valueOf(editable).hashCode();
163:            }
164:
165:            /**
166:             * Compares two DefaultProperty objects. Two DefaultProperty objects are equal
167:             * if they are the same object or if their name, display name, short
168:             * description, category, type and editable property are the same. Note the
169:             * property value is not considered in the implementation.
170:             */
171:            public boolean equals(Object other) {
172:                if (other == null || getClass() != other.getClass()) {
173:                    return false;
174:                }
175:
176:                if (other == this ) {
177:                    return true;
178:                }
179:
180:                DefaultProperty dp = (DefaultProperty) other;
181:
182:                return compare(name, dp.name)
183:                        && compare(displayName, dp.displayName)
184:                        && compare(shortDescription, dp.shortDescription)
185:                        && compare(category, dp.category)
186:                        && compare(type, dp.type) && editable == dp.editable;
187:            }
188:
189:            private boolean compare(Object o1, Object o2) {
190:                return (o1 != null) ? o1.equals(o2) : o2 == null;
191:            }
192:
193:            public String toString() {
194:                return "name=" + getName() + ", displayName="
195:                        + getDisplayName() + ", type=" + getType()
196:                        + ", category=" + getCategory() + ", editable="
197:                        + isEditable() + ", value=" + getValue();
198:            }
199:
200:            public Property getParentProperty() {
201:                return parent;
202:            }
203:
204:            public void setParentProperty(Property parent) {
205:                this .parent = parent;
206:            }
207:
208:            public Property[] getSubProperties() {
209:                return (Property[]) subProperties
210:                        .toArray(new Property[subProperties.size()]);
211:            }
212:
213:            public void clearSubProperties() {
214:                for (Iterator iter = this .subProperties.iterator(); iter
215:                        .hasNext();) {
216:                    Property subProp = (Property) iter.next();
217:                    if (subProp instanceof  DefaultProperty)
218:                        ((DefaultProperty) subProp).setParentProperty(null);
219:                }
220:                this .subProperties.clear();
221:            }
222:
223:            public void addSubProperties(Collection subProperties) {
224:                this .subProperties.addAll(subProperties);
225:                for (Iterator iter = this .subProperties.iterator(); iter
226:                        .hasNext();) {
227:                    Property subProp = (Property) iter.next();
228:                    if (subProp instanceof  DefaultProperty)
229:                        ((DefaultProperty) subProp).setParentProperty(this );
230:                }
231:            }
232:
233:            public void addSubProperties(Property[] subProperties) {
234:                this .addSubProperties(Arrays.asList(subProperties));
235:            }
236:
237:            public void addSubProperty(Property subProperty) {
238:                this .subProperties.add(subProperty);
239:                if (subProperty instanceof  DefaultProperty)
240:                    ((DefaultProperty) subProperty).setParentProperty(this);
241:            }
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.