Source Code Cross Referenced for BasicTreeNode.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » 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 » ERP CRM Financial » SourceTap CRM » com.sourcetap.sfa.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
004:         *
005:         *  The contents of this file are subject to the SourceTap Public License 
006:         * ("License"); You may not use this file except in compliance with the 
007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010:         * the specific language governing rights and limitations under the License.
011:         *
012:         * The above copyright notice and this permission notice shall be included
013:         * in all copies or substantial portions of the Software.
014:         *
015:         */
016:
017:        package com.sourcetap.sfa.ui;
018:
019:        import java.io.Writer;
020:        import java.util.ArrayList;
021:        import java.util.Enumeration;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import javax.swing.tree.DefaultMutableTreeNode;
027:
028:        import org.ofbiz.entity.GenericDelegator;
029:        import org.ofbiz.entity.GenericEntityException;
030:        import org.ofbiz.entity.GenericValue;
031:
032:        /**
033:         * DOCUMENT ME!
034:         *
035:         */
036:        public class BasicTreeNode extends DefaultMutableTreeNode implements 
037:                UITreeNode {
038:            private static String defaultClassName = "com.sourcetap.sfa.ui.BasicTreeNode";
039:
040:            public BasicTreeNode() {
041:                super ();
042:            }
043:
044:            public BasicTreeNode(Object userObject) {
045:                super (userObject);
046:            }
047:
048:            /**
049:             * DOCUMENT ME!
050:             *
051:             * @param delegator 
052:             * @param entityName 
053:             * @param keyAttributeName 
054:             * @param parentAttributeName 
055:             * @param nodeClassName 
056:             *
057:             * @return 
058:             *
059:             * @throws GenericEntityException 
060:             * @throws ClassNotFoundException 
061:             * @throws LinkageError 
062:             * @throws ExceptionInInitializerError 
063:             * @throws InstantiationException 
064:             * @throws IllegalAccessException 
065:             */
066:            public static BasicTreeNode createTree(GenericDelegator delegator,
067:                    String entityName, String keyAttributeName,
068:                    String parentAttributeName, String nodeClassName)
069:                    throws GenericEntityException, ClassNotFoundException,
070:                    LinkageError, ExceptionInInitializerError,
071:                    InstantiationException, IllegalAccessException {
072:                ArrayList orderBy = new ArrayList();
073:                orderBy.add(parentAttributeName);
074:
075:                List rows = delegator.findAll(entityName, orderBy);
076:                GenericValue[] genericValue = (GenericValue[]) rows
077:                        .toArray(new GenericValue[0]);
078:
079:                return createTree(genericValue, keyAttributeName,
080:                        parentAttributeName, nodeClassName);
081:            }
082:
083:            /**
084:             * DOCUMENT ME!
085:             *
086:             * @param delegator 
087:             * @param entityName 
088:             * @param keyAttributeName 
089:             * @param parentAttributeName 
090:             *
091:             * @return 
092:             *
093:             * @throws GenericEntityException 
094:             * @throws ClassNotFoundException 
095:             * @throws LinkageError 
096:             * @throws ExceptionInInitializerError 
097:             * @throws InstantiationException 
098:             * @throws IllegalAccessException 
099:             */
100:            public static BasicTreeNode createTree(GenericDelegator delegator,
101:                    String entityName, String keyAttributeName,
102:                    String parentAttributeName) throws GenericEntityException,
103:                    ClassNotFoundException, LinkageError,
104:                    ExceptionInInitializerError, InstantiationException,
105:                    IllegalAccessException {
106:                return createTree(delegator, entityName, keyAttributeName,
107:                        parentAttributeName, defaultClassName);
108:            }
109:
110:            /**
111:             * DOCUMENT ME!
112:             *
113:             * @param gv 
114:             * @param keyAttributeName 
115:             * @param parentAttributeName 
116:             * @param nodeClassName 
117:             *
118:             * @return 
119:             *
120:             * @throws ClassNotFoundException 
121:             * @throws LinkageError 
122:             * @throws ExceptionInInitializerError 
123:             * @throws InstantiationException 
124:             * @throws IllegalAccessException 
125:             */
126:            public static BasicTreeNode createTree(GenericValue[] gv,
127:                    String keyAttributeName, String parentAttributeName,
128:                    String nodeClassName) throws ClassNotFoundException,
129:                    LinkageError, ExceptionInInitializerError,
130:                    InstantiationException, IllegalAccessException {
131:                Class nodeClass = Class.forName(nodeClassName);
132:
133:                HashMap nodes = new HashMap();
134:
135:                BasicTreeNode root = null;
136:
137:                boolean multiRootNodes = false;
138:                int numNodes = gv.length;
139:                int i;
140:
141:                for (i = 0; i < numNodes; i++) {
142:                    String parentId = (String) gv[i].get(parentAttributeName);
143:                    String nodeId = (String) gv[i].get(keyAttributeName);
144:
145:                    if (parentId == null) {
146:                        parentId = "";
147:                    }
148:
149:                    BasicTreeNode parent = (BasicTreeNode) nodes.get(parentId);
150:
151:                    if (parent == null) {
152:                        parent = (BasicTreeNode) nodeClass.newInstance();
153:                        parent.setUserObject("PLACEHOLDER");
154:                        nodes.put(parentId, parent);
155:                    }
156:
157:                    parent = (BasicTreeNode) nodes.get(parentId);
158:
159:                    BasicTreeNode this Node = (BasicTreeNode) nodes.get(nodeId);
160:
161:                    if (this Node == null) {
162:                        this Node = (BasicTreeNode) nodeClass.newInstance();
163:                        this Node.setUserObject(gv[i]);
164:                        nodes.put(nodeId, this Node);
165:                    } else {
166:                        this Node.setUserObject(gv[i]);
167:                    }
168:
169:                    parent.add(this Node);
170:                }
171:
172:                root = (BasicTreeNode) nodes.get("");
173:
174:                for (Iterator i1 = nodes.values().iterator(); i1.hasNext();) {
175:                    BasicTreeNode node = (BasicTreeNode) i1.next();
176:                    Object userObject = node.getUserObject();
177:
178:                    if (userObject instanceof  String) {
179:                        if (root == null) {
180:                            root = node;
181:                        } else if (!root.equals(node)) {
182:                            root.add(node);
183:                        }
184:                    }
185:                }
186:
187:                if ((root != null) && (root.getUserObject() instanceof  String)
188:                        && (root.getChildCount() == 1)) {
189:                    root = (BasicTreeNode) root.getChildAt(0);
190:                    root.setParent(null);
191:                }
192:
193:                return root;
194:            }
195:
196:            /* outputs the HTML necessary to render the node contents */
197:            public void displayHtml(Writer out) throws java.io.IOException {
198:                if (isRoot()) {
199:                    out.write("<table border=0 cellspacing=0 cellpadding=0>\n");
200:                    out.write("<tr>\n");
201:                    out.write("<td valign=top>\n");
202:                } else {
203:                    BasicTreeNode parent = (BasicTreeNode) getParent();
204:                    int numSiblings = parent.getChildCount();
205:                    int curPos = parent.getIndex(this );
206:
207:                    out
208:                            .write("<table width=100% border=0 cellspacing=0 cellpadding=0>\n");
209:
210:                    if (curPos == 0) {
211:                        out.write("<td width=50% height=0></td>\n");
212:                    } else {
213:                        out
214:                                .write("<td width=50% ><img src=/sfaimages/horz.gif width=100% height=1></td>\n");
215:                    }
216:
217:                    if (curPos == (numSiblings - 1)) {
218:                        out.write("<td width=50% height=0></td>\n");
219:                    } else {
220:                        out
221:                                .write("<td width=50% ><img src=/sfaimages/horz.gif width=100% height=1></td>\n");
222:                    }
223:
224:                    out
225:                            .write("</tr><tr><td colspan=2 align=center><img src=/sfaimages/vert.gif></td></tr>\n");
226:
227:                    out.write("</table>\n");
228:                }
229:
230:                out
231:                        .write("<table align=center width=100% border=0 cellspacing=0 cellpassing=0>\n");
232:                out
233:                        .write("<tr align=center><td width=5></td><td align=center>\n");
234:                out
235:                        .write("<table width=100 border=1 cellspacing=0 cellpadding=2 align=center bordercolordark=#000000 bordercolorlight=#000000 bordercolor=#000000>\n");
236:                out.write("<tr></td><td height=80>\n");
237:
238:                String displayText = getDisplayText();
239:                out.write("" + displayText + "");
240:
241:                out.write("</td></tr></table>\n");
242:                out.write("</td><td width=5></td></tr></table>\n");
243:
244:                int numChildren = getChildCount();
245:
246:                if (numChildren > 0) {
247:                    out
248:                            .write("<table width=100% border=0 cellspacing=0 cellpadding=0 align=center>\n");
249:                    out.write("<tr><td align=center colspan=" + numChildren
250:                            + "><img src='/sfaimages/vert.gif'></td></tr>\n");
251:                    out.write("</table>\n");
252:                }
253:
254:                out.write("<table border=0 cellspacing=0 cellpadding=0>\n");
255:                out.write("<tr>\n");
256:
257:                for (Enumeration e = children(); e.hasMoreElements();) {
258:                    out.write("<td valign=top align=center>\n");
259:
260:                    BasicTreeNode child = (BasicTreeNode) e.nextElement();
261:                    child.displayHtml(out);
262:                    out.write("</td>\n");
263:                }
264:
265:                out.write("</tr></table>\n");
266:
267:                if (isRoot()) {
268:                    out.write("</tr>\n");
269:                    out.write("</table>\n");
270:                }
271:            }
272:
273:            /* can be overridden to display the contents of a node */
274:            public String getDisplayText() {
275:                Object o = getUserObject();
276:
277:                String name = "";
278:
279:                if (o instanceof  String) {
280:                    name = (String) o;
281:
282:                    if (name.equals("PLACEHOLDER")) {
283:                        name = "";
284:                    }
285:                } else if (o instanceof  GenericValue) {
286:                    GenericValue gv = (GenericValue) o;
287:                    name = (String) gv.toString();
288:
289:                    //			name = (String) gv.get("roleName");
290:                }
291:
292:                String html = "<font color=#003399><b><center>" + name
293:                        + "</center></b>\n";
294:
295:                //		html += "<br><div align=right><a href=\"viewdeptinfo.php?deptid=$deptid1\"><img src=\"/sfaimages/info.gif\" alt=\"View Department Information\" width=\"17\" height=\"17\" border=0></a></div>\n";
296:                return html;
297:            }
298:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.