Source Code Cross Referenced for XTableModelHelper.java in  » XML-UI » xui32 » com » xoetrope » swing » table » 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 » XML UI » xui32 » com.xoetrope.swing.table 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.swing.table;
002:
003:        import net.xoetrope.xui.data.XBaseModel;
004:        import net.xoetrope.xui.data.XModel;
005:        import net.xoetrope.xui.XProjectManager;
006:        import net.xoetrope.xui.helper.*;
007:
008:        /**
009:         * <p>Title: </p>
010:         * <p>Description: </p>
011:         *
012:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
013:         * the GNU Public License (GPL), please see license.txt for more details. If
014:         * you make commercial use of this software you must purchase a commercial
015:         * license from Xoetrope.</p>
016:         * <p> $Revision: 1.3 $</p>
017:         */
018:
019:        public class XTableModelHelper {
020:            private static XTableModelHelper modelHelper;
021:
022:            private XTableModelHelper() {
023:            }
024:
025:            public static XTableModelHelper getInstance() {
026:                if (modelHelper == null)
027:                    modelHelper = new XTableModelHelper();
028:
029:                return modelHelper;
030:            }
031:
032:            /**
033:             * Clones the current model node. Need to call cloneChildren which iterated
034:             * the children and creates new instances of the children. The call to
035:             * super.clone() does not create new instance of the child nodes.
036:             * @return the newly created XModel.
037:             */
038:            public static XModel clone(XModel src) {
039:                XBaseModel model = new XBaseModel();
040:                cloneChildren(src, model);
041:                return model;
042:            }
043:
044:            /**
045:             * Iterates the children of the source model and transfers them to the target
046:             * model. For each model the attributes also need to be iterated and added.
047:             * @param source the model being cloned
048:             * @param target the new model resuting from the clone operation.
049:             */
050:            private static void cloneChildren(XModel source, XModel target) {
051:                target.setNumAttributes(source.getNumAttributes());
052:                target.setId(source.getId());
053:                for (int att = 0; att < source.getNumAttributes(); att++) {
054:                    target.setAttribValue(att, source.getAttribName(att),
055:                            source.getAttribValue(att));
056:                }
057:
058:                for (int i = 0; i < source.getNumChildren(); i++) {
059:                    XBaseModel child = (XBaseModel) source.get(i);
060:                    XBaseModel newChild = new XBaseModel(target);
061:                    target.append(newChild);
062:                    cloneChildren(child, newChild);
063:                }
064:            }
065:
066:            /**
067:             * merge the conents of one model with another. Calls cloneChildren which
068:             * transfers the data.
069:             * @param mainModel the model which is to be updated
070:             * @param newmodel the model which contains the data to be merged with this model.
071:             */
072:            public static void merge(XModel mainModel, XModel newModel) {
073:                cloneChildren(newModel, mainModel);
074:            }
075:
076:            public static String getAttrib(XModel model, String name) {
077:                return model.getAttribValueAsString(model.getAttribute(name));
078:            }
079:
080:            public static void setAttrib(XModel model, String name, String value) {
081:                model.setAttribValue(model.getAttribute(name), name, value);
082:            }
083:
084:            public static XBaseModel getParent(XBaseModel model, int level) {
085:                XBaseModel parent = model;
086:                for (int i = 0; i < level; i++)
087:                    parent = (XBaseModel) parent.getParent();
088:
089:                return parent;
090:            }
091:
092:            public static int getPositionInModel(XBaseModel refmodel) {
093:                for (int i = 0; i < refmodel.getParent().getNumChildren(); i++) {
094:                    if (refmodel.getParent().get(i).equals(refmodel)) {
095:                        return i;
096:                    }
097:                }
098:                return -1;
099:            }
100:
101:            public static String getValue(Object model) {
102:                return (String) ((XModel) model).get();
103:            }
104:
105:            public static double getDoubleValue(XModel model) {
106:                double ret = 0.0;
107:                String value = (String) model.get();
108:                try {
109:                    if (value != null)
110:                        ret = NumberFormatter.parseDouble(value);
111:                } catch (NumberFormatException ex) {
112:                }
113:                return ret;
114:            }
115:
116:            public static double getDoubleValue(XBaseModel model, String att) {
117:                return getDoubleValue(model, att, 0.0);
118:            }
119:
120:            public static double getDoubleValue(XBaseModel model, String att,
121:                    double defaultValue) {
122:                try {
123:                    return model
124:                            .getAttribValueAsDouble(model.getAttribute(att));
125:                } catch (Exception ex) {
126:                    return defaultValue;
127:                }
128:            }
129:
130:            public static int getIntValue(XModel model) {
131:                int ret = 0;
132:                String value = (String) model.get();
133:                try {
134:                    if (value != null)
135:                        ret = Integer.parseInt(value);
136:                } catch (NumberFormatException ex) {
137:                }
138:                return ret;
139:            }
140:
141:            public static int getIntValue(XBaseModel model, String att) {
142:                return getIntValue(model, att, 0);
143:            }
144:
145:            public static int getIntValue(XBaseModel model, String att,
146:                    int defaultValue) {
147:                try {
148:                    return model.getAttribValueAsInt(model.getAttribute(att));
149:                } catch (Exception ex) {
150:                    return defaultValue;
151:                }
152:            }
153:
154:            public static double addModels(XModel model1, XModel model2) {
155:                double value = getDoubleValue(model1);
156:                value += getDoubleValue(model2);
157:                return value;
158:            }
159:
160:            public static double multipyModels(XModel model1, XModel model2) {
161:                double value = getDoubleValue(model1);
162:                value *= getDoubleValue(model2);
163:                return value;
164:            }
165:
166:            public static double multipyAttribs(XBaseModel model,
167:                    String attrib1, String attrib2) {
168:                double value = getDoubleValue(model, attrib1);
169:                value *= getDoubleValue(model, attrib2);
170:                return value;
171:            }
172:
173:            public static void setTempVar(String name, String value) {
174:                XModel tempmodel = (XModel) XProjectManager.getModel().get(
175:                        "temp/" + name);
176:                tempmodel.set(value);
177:            }
178:
179:            public static String getTempVar(String name) {
180:                XModel tempmodel = (XModel) XProjectManager.getModel().get(
181:                        "temp/" + name);
182:                return (String) tempmodel.get();
183:            }
184:
185:            public static boolean getBooleanValue(XBaseModel model) {
186:                Object o = model.get();
187:                boolean include;
188:                if (o instanceof  Boolean)
189:                    include = ((Boolean) o).booleanValue();
190:                else
191:                    include = o.toString().compareTo("true") == 0 ? true
192:                            : false;
193:
194:                return include;
195:            }
196:
197:            public static boolean isChildNode(XBaseModel ref, XBaseModel parent) {
198:                XBaseModel nextParent = (XBaseModel) ref.getParent();
199:                while (nextParent != null) {
200:                    if (nextParent.equals(ref))
201:                        return true;
202:                    nextParent = (XBaseModel) nextParent.getParent();
203:                }
204:                return false;
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.