KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > core > comp > DefaultTableView


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DefaultTableView.java,v 1.11 2004/02/01 05:16:27 christianc Exp $
19  */

20 package org.enhydra.barracuda.core.comp;
21
22 import java.util.*;
23
24 import org.apache.log4j.*;
25 import org.w3c.dom.*;
26 import org.w3c.dom.html.*;
27
28 import org.enhydra.barracuda.core.util.dom.DOMUtil;
29 import org.enhydra.barracuda.plankton.*;
30
31
32 /**
33  * This class provides the default implementation for
34  * a TableView. It provides a View for components to
35  * render themselves in. Unlike other views, the TableView
36  * provides convenience methods to access the header, body,
37  * and footer elements of the view.
38  */

39 public class DefaultTableView extends DefaultView implements TableView {
40
41     protected static final Logger logger = Logger.getLogger(DefaultTableView.class.getName());
42
43     protected Element header = null;
44     protected Element body = null;
45     protected Element footer = null;
46     protected Element caption = null; //ndc_101202.1
47

48     /**
49      * Public noargs constructor. This creates a view which is not bound
50      * to any particular node. You must bind the view to a node before you
51      * can actually use it for anything
52      */

53     public DefaultTableView() {
54         this(null);
55     }
56
57     /**
58      * Create a view and bind it to a node.
59      *
60      * @param node the node the view should be bound to
61      */

62     public DefaultTableView(Node node) {
63         if (node!=null) setNode(node);
64     }
65
66     /**
67      * Get the header element from the particular Node that
68      * backs this view.
69      *
70      * @return the header element (may be null if there is
71      * no recognized header)
72      */

73     public Element getHeaderElement() {
74         return header;
75     }
76     
77     /**
78      * Get the body element from the particular Node that
79      * backs this view. There will always be a body element.
80      * It will either correspond to the <tbody> element or
81      * to the entire table (ie. the whole table is body)
82      *
83      * @return the body element
84      */

85     public Element getBodyElement() {
86         return (body!=null ? body : (Element) node);
87     }
88     
89     /**
90      * Get the footer element from the particular Node that
91      * backs this view.
92      *
93      * @return the footer element (may be null if there is
94      * no recognized footer)
95      */

96     public Element getFooterElement() {
97         return footer;
98     }
99
100     //ndc_101202.1 - added
101
/**
102      * Get the caption element from the particular Node that
103      * backs this view.
104      *
105      * @return the caption element (may be null if there is
106      * no recognized caption)
107      */

108     public Element getCaptionElement() {
109         return caption;
110     }
111
112     /**
113      * Here we are going to look for custom header, footer, and
114      * body elements
115      */

116     protected void customSearchForTemplates(Node curnode) {
117         //if we already have the header, body, and footer just return
118
if (header!=null && body!=null && footer!=null) return;
119
120         //make sure its an element
121
if (!(curnode instanceof Element)) return;
122         Element el = (Element) curnode;
123         if (logger.isDebugEnabled()) {
124             logger.debug("node [tag="+el.getTagName()+" id="+DOMUtil.getID(el)+"] implements the following interfaces:");
125             Iterator it = Classes.getAllInterfaces(curnode).iterator();
126             while (it.hasNext()) {
127                 Object JavaDoc o = it.next();
128                 logger.debug(o.toString());
129             }
130         }
131                 
132         //see if its an instance of HTMLTableElement
133
if (curnode instanceof HTMLTableSectionElement) {
134         
135             String JavaDoc tagName = el.getTagName().toUpperCase();
136             if (tagName.equals("THEAD")) {
137                 if (header==null) header = el;
138             } else if (tagName.equals("TBODY")) {
139                 if (body==null) body = el;
140             } else if (tagName.equals("TFOOT")) {
141                 if (footer==null) footer = el;
142             }
143         }
144
145         //ndc_101202.1 - added
146
if (curnode instanceof HTMLTableCaptionElement){
147             String JavaDoc tagName = el.getTagName().toUpperCase();
148             if (tagName.equals("CAPTION")) {
149                 if (caption==null) caption = el;
150             }
151         }
152     }
153
154     /*
155      * @return a String representation of a TableView and the node it is bound to
156      */

157     public String JavaDoc toString() {
158         return "TableView:"+getName()+" (bound to Node:"+DOMUtil.getID(node)+")";
159     }
160     
161 }
Popular Tags