Source Code Cross Referenced for ElementTreeNodeStructureDefaultImpl.java in  » Ajax » ItsNat » org » itsnat » impl » core » domutil » 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 » ItsNat » org.itsnat.impl.core.domutil 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          ItsNat Java Web Application Framework
003:          Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
004:          Author: Jose Maria Arranz Santamaria
005:
006:          This program is free software: you can redistribute it and/or modify
007:          it under the terms of the GNU Affero General Public License as published by
008:          the Free Software Foundation, either version 3 of the License, or
009:          (at your option) any later version. See the GNU Affero General Public 
010:          License for more details. See the copy of the GNU Affero General Public License
011:          included in this program. If not, see <http://www.gnu.org/licenses/>.
012:         */
013:
014:        package org.itsnat.impl.core.domutil;
015:
016:        import org.itsnat.core.domutil.ElementTreeNode;
017:        import org.itsnat.core.domutil.ElementTreeNodeStructure;
018:        import org.itsnat.core.domutil.ItsNatTreeWalker;
019:        import org.itsnat.impl.core.util.*;
020:        import org.w3c.dom.Element;
021:        import org.w3c.dom.html.HTMLTableCellElement;
022:        import org.w3c.dom.html.HTMLTableElement;
023:        import org.w3c.dom.html.HTMLTableRowElement;
024:        import org.w3c.dom.html.HTMLTableSectionElement;
025:
026:        /**
027:         Ejemplo:
028:         <li>
029:         <span><span>handle</span><span>Icon</span><span><b>Item content</b></span></span>
030:         <ul>
031:         </ul>
032:         </li> 
033:        
034:         * @author jmarranz
035:         */
036:        public class ElementTreeNodeStructureDefaultImpl implements 
037:                ElementTreeNodeStructure {
038:            public static final ElementTreeNodeStructureDefaultImpl SINGLETON = new ElementTreeNodeStructureDefaultImpl();
039:
040:            /**
041:             * Creates a new instance of ElementTreeNodeStructureDefaultImpl
042:             */
043:            private ElementTreeNodeStructureDefaultImpl() {
044:            }
045:
046:            public static ElementTreeNodeStructureDefaultImpl newElementTreeNodeStructureDefault() {
047:                // A día de hoy no se guarda estado por lo que el SINGLETON ayuda a disminuir el número de objetos
048:                return SINGLETON;
049:            }
050:
051:            public static Element getEffectiveParentElement(
052:                    Element treeNodeParent) {
053:                if (treeNodeParent instanceof  HTMLTableRowElement) {
054:                    /*
055:                       Ejemplo de patrón:
056:                        <table>
057:                            <tbody id="someId">
058:                                <tr> <-- el treeNodeParent
059:                                    <td>
060:                                        (nodo)
061:                                    </td>  
062:                                </tr>
063:                            </tbody>
064:                         </table>  
065:                     
066:                        O como tree-table con <table>:             
067:                            <table>
068:                                <tbody id="someId">
069:                                    <tr> <-- el treeNodeParent
070:                                        <td>
071:                                            (nodo)
072:                                        </td>
073:                                        <td>Otros</td>
074:                                        ...
075:                                    </tr>
076:                                </tbody>
077:                             </table>              
078:                     */
079:                    return ItsNatTreeWalker
080:                            .getFirstChildElement(treeNodeParent);
081:                } else
082:                    return treeNodeParent;
083:            }
084:
085:            public static Element getContentElement(boolean treeTable,
086:                    Element treeNodeParent) {
087:                treeNodeParent = getEffectiveParentElement(treeNodeParent);
088:
089:                // treeNodeParent es por ejemplo un <li> (o un <td> si es con <table>)
090:
091:                if (!treeTable) {
092:                    /*
093:                        - Ejemplo de patrón:
094:                     <ul id="someId">
095:                        <li> <-- el (efectivo) treeNodeParent
096:                            <span><span>handle</span><span>Icon</span><span><b>Item content</b></span></span>
097:                            <ul>
098:                            </ul>
099:                        </li>
100:                     <ul>                                            
101:
102:                     - Ejemplo con <table>:
103:                    <table>
104:                        <tbody id="someId">
105:                            <tr> 
106:                                <td> <-- el (efectivo) treeNodeParent
107:                                    <span><span>handle</span><span>Icon</span><span><b>Item content</b></span></span>
108:                                    <table>
109:                                        <tbody />
110:                                    </table>
111:                                </td>  
112:                            </tr>
113:                        </tbody>
114:                     </table>
115:
116:                      Devolverá el <span> padre del handler, icono y contenido                 
117:                     */
118:                    return ItsNatTreeWalker
119:                            .getFirstChildElement(treeNodeParent);
120:                } else {
121:                    /*
122:                     - Ejemplo de patrón:
123:                     <div id="someId">
124:                        <p> <-- el (efectivo) treeNodeParent
125:                            <span>handle</span><span>Icon</span><span><b>Item content</b></span>
126:                        </p>
127:                     <div>                   
128:                     
129:                    - Ejemplo con <table>: 
130:                    <table>
131:                        <tbody id="someId">
132:                            <tr> 
133:                                <td> <-- el efectivo treeNodeParent
134:                                    <span>handle</span>
135:                                    <span>Icon</span>
136:                                    <span><b>Label</b></span>
137:                                </td>
138:                                <td>Otros</td>
139:                                ...
140:                            </tr>
141:                        </tbody>
142:                     </table>              
143:                     */
144:                    return treeNodeParent;
145:                }
146:            }
147:
148:            public Element getContentElement(ElementTreeNode treeNode,
149:                    Element nodeParent) {
150:                return getContentElement(treeNode.isTreeTable(), nodeParent);
151:            }
152:
153:            public static Element getHandleElement(Element contentParent) {
154:                if (contentParent instanceof  HTMLTableElement) {
155:                    // Estructura guiada por un <table> (por ejemplo):
156:                    // <table><tbody><tr><td><img src="Handle" /></td><td><img src="Icon" /></td><td>Label</td></tr></td></table> 
157:                    HTMLTableSectionElement tbody = (HTMLTableSectionElement) ItsNatTreeWalker
158:                            .getFirstChildElement(contentParent);
159:                    HTMLTableRowElement row = (HTMLTableRowElement) ItsNatTreeWalker
160:                            .getFirstChildElement(tbody);
161:                    return getHandleElement(row);
162:                } else {
163:                    // Estructura tipo 
164:                    // <contentParent><handle/><icon/><label>...Label...</label></contentParent>
165:                    // Por ejemplo:
166:                    // <span><img src="Handle" /><img src="Icon" /><span><b>Label</b></span></span> 
167:                    // Devuelve null si es una estructura tipo:
168:                    // <contentParent>Label</contentParent> 
169:
170:                    Element handleElem = ItsNatTreeWalker
171:                            .getFirstChildElement(contentParent);
172:                    if (handleElem == null)
173:                        return null; // Es una estructura tipo: <contentParent>Label</contentParent>  
174:                    Element siblingElem = ItsNatTreeWalker
175:                            .getNextSiblingElement(handleElem);
176:                    if (siblingElem == null)
177:                        return null; // Es una estructura tipo: <contentParent><opt>Label</opt></contentParent> , ej. <span><b>Label</b></span>
178:
179:                    return handleElem;
180:                }
181:            }
182:
183:            public static Element getHandleElement(boolean treeTable,
184:                    Element treeNodeParent) {
185:                Element contentParent = getContentElement(treeTable,
186:                        treeNodeParent);
187:                return getHandleElement(contentParent);
188:            }
189:
190:            public static Element getIconElement(boolean treeTable,
191:                    Element treeNodeParent) {
192:                Element handleElem = getHandleElement(treeTable, treeNodeParent);
193:                if (handleElem != null)
194:                    return ItsNatTreeWalker.getNextSiblingElement(handleElem);
195:                else
196:                    return null; // Si no hay handle no puede haber icon, caso de <contentParent>Label</contentParent> o similar
197:            }
198:
199:            public static Element getLabelElement(boolean treeTable,
200:                    Element treeNodeParent) {
201:                Element iconElem = getIconElement(treeTable, treeNodeParent);
202:                if (iconElem != null)
203:                    return ItsNatTreeWalker.getNextSiblingElement(iconElem);
204:                else {
205:                    //  Caso de <contentParent>Label</contentParent> o 
206:                    // <contentParent><opt>Label</opt></contentParent> o similar
207:                    return getContentElement(treeTable, treeNodeParent);
208:                }
209:            }
210:
211:            public static Element getChildListElement(boolean treeTable,
212:                    Element treeNodeParent) {
213:                if (treeTable)
214:                    return null; // Es el caso de TreeTable, no tiene sentido llamar a getChildListElement en el caso de TreeTable pero por si acaso
215:
216:                Element contentElem = getContentElement(treeTable,
217:                        treeNodeParent);
218:                Element nextSiblingToContentElem = ItsNatTreeWalker
219:                        .getNextSiblingElement(contentElem);
220:
221:                if (nextSiblingToContentElem == null)
222:                    return null; // No hay hijos
223:
224:                if (nextSiblingToContentElem instanceof  HTMLTableElement) {
225:                    /* Ver en getContentElement el ejemplo completo:
226:                        <td>
227:                            <span><span>handle</span><span>Icon</span><span><b>Item content</b></span></span>
228:                            <table> <-- nextSiblingToContentElem
229:                                <tbody>
230:                                </tbody>
231:                            </table>
232:                        </td>             
233:                     */
234:                    return (HTMLTableSectionElement) ItsNatTreeWalker
235:                            .getFirstChildElement(nextSiblingToContentElem); // Devuelve el <tbody>            
236:                } else {
237:                    /* Ver en getContentElement el ejemplo completo:
238:                        <li> 
239:                            <span><span>handle</span><span>Icon</span><span><b>Item content</b></span></span>
240:                            <ul>  <-- nextSiblingToContentElem 
241:                            </ul>
242:                        </li>             
243:                     */
244:                    return nextSiblingToContentElem;
245:                }
246:            }
247:
248:            public Element getHandleElement(ElementTreeNode treeNode,
249:                    Element nodeParent) {
250:                return getHandleElement(treeNode.isTreeTable(), nodeParent);
251:            }
252:
253:            public Element getIconElement(ElementTreeNode treeNode,
254:                    Element nodeParent) {
255:                return getIconElement(treeNode.isTreeTable(), nodeParent);
256:            }
257:
258:            public Element getLabelElement(ElementTreeNode treeNode,
259:                    Element nodeParent) {
260:                return getLabelElement(treeNode.isTreeTable(), nodeParent);
261:            }
262:
263:            public Element getChildListElement(ElementTreeNode treeNode,
264:                    Element nodeParent) {
265:                return getChildListElement(treeNode.isTreeTable(), nodeParent);
266:            }
267:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.