KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > scrollabletable > www > ScrollableTableBodyTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ScrollableTableBodyTag.java,v 1.6 2007/01/07 06:14:16 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.scrollabletable.www;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25
26 import org.opensubsystems.core.www.BlockElementTag;
27 import org.opensubsystems.core.www.TagUtils;
28
29 /**
30  * Custom tag to generate all HTML code necessary to display body of scrollable
31  * table. The body of the table contains the the rows and cells of the table
32  * and will be created from the content of the body of this tag.
33  *
34  * @version $Id: ScrollableTableBodyTag.java,v 1.6 2007/01/07 06:14:16 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.3 2006/02/18 05:29:32 bastafidli
38  */

39 public class ScrollableTableBodyTag extends BlockElementTag
40 {
41    // Attributes ///////////////////////////////////////////////////////////////
42

43    /**
44     * Generated serial version id for this class.
45     */

46    private static final long serialVersionUID = 1517197854549928557L;
47
48    /**
49     * Summary describing content of the table.
50     */

51    protected String JavaDoc m_strSummary;
52    
53    // Constructors /////////////////////////////////////////////////////////////
54

55    /**
56     * Constructor for custom tag.
57     */

58    public ScrollableTableBodyTag()
59    {
60       super("clsScrollableTable", BlockElementTag.DIV_BLOCK_ELEMENT);
61    }
62    
63    // Business logic ///////////////////////////////////////////////////////////
64

65    /**
66     * {@inheritDoc}
67     */

68    public int doStartTag(
69    ) throws JspException JavaDoc
70    {
71       StringBuffer JavaDoc sbHtml = null;
72       Object JavaDoc objTemp;
73       String JavaDoc strScrollableTableId;
74
75       objTemp = getCachedContent(ScrollableTableTag.ACTIVE_SCROLLABLE_TABLE_ID,
76                                  false).trim();
77       if (objTemp == null)
78       {
79          throw new JspException JavaDoc("Cannot find scrollable table id on the page. Probable" +
80                                 " cause is that the scrollable table open tag is missing.");
81       }
82       strScrollableTableId = (String JavaDoc)objTemp;
83       
84       sbHtml = new StringBuffer JavaDoc();
85
86       /*
87       This is how a start of body of a scrollable table looks like
88       
89       This div makes sure that we can scroll the body independently from header
90  
91       Frame is causing to draw only certain line around the table.
92       Possible values are void | above | below | hsides | vsides | lhs | rhs | box | border
93       Rules is causing to draw only certain lines in the table.
94       Possible values are none | groups | rows | cols | all
95       It works only if border is nonzero
96       
97       <div id="scrollabletablebody" class="clsScrollableTableBody"
98            onresize="scrollColumnHeadings('scrollabletableheader', 'scrollabletablebody',
99                                           'scrollabletablebodycolumns');"
100            onscroll="scrollColumnHeadings('scrollabletableheader', 'scrollabletablebody',
101                                           'scrollabletablebodycolumns');"
102            onclick="selectRow('scrollabletable',event);">
103          <%-- This table contains the actual body --%>
104          <table width="100%" cellspacing="0" cellpadding="2" border="1"
105                 id="scrollabletablebodytable"
106                 summary="<tiles:getAsString name="tablesummary" ignore="true"/>"
107                 frame="void"
108                 rules="cols">
109             <%-- This are the actual data for the table--%>
110             <tbody id="scrollabletablerealbody">
111       */

112
113       // Generate the start of the scrollable table body
114
sbHtml.append("<div id=\"");
115       sbHtml.append(strScrollableTableId);
116       sbHtml.append("body\"");
117       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
118       {
119          sbHtml.append(" class=\"");
120          sbHtml.append(m_strCssclass);
121          sbHtml.append("Body");
122          sbHtml.append("\"");
123       }
124       sbHtml.append(" onresize=\"scrollColumnHeadings('");
125       sbHtml.append(strScrollableTableId);
126       sbHtml.append("header', '");
127       sbHtml.append(strScrollableTableId);
128       sbHtml.append("body', '");
129       sbHtml.append(strScrollableTableId);
130       sbHtml.append("bodycolumns');\"");
131       sbHtml.append(" onscroll=\"scrollColumnHeadings('");
132       sbHtml.append(strScrollableTableId);
133       sbHtml.append("header', '");
134       sbHtml.append(strScrollableTableId);
135       sbHtml.append("body', '");
136       sbHtml.append(strScrollableTableId);
137       sbHtml.append("bodycolumns');\"");
138       sbHtml.append(" onclick=\"selectRow('");
139       sbHtml.append(strScrollableTableId);
140       sbHtml.append("', event);\"");
141       sbHtml.append(">\n");
142       
143       sbHtml.append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\"" +
144                     " border=\"1\" frame=\"void\" rules=\"cols\" id=\"");
145       sbHtml.append(strScrollableTableId);
146       sbHtml.append("bodytable\"");
147       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
148       {
149          sbHtml.append(" class=\"");
150          sbHtml.append(m_strCssclass);
151          sbHtml.append("BodyTable");
152          sbHtml.append("\"");
153       }
154       if ((m_strSummary != null) && (m_strSummary.length() > 0))
155       {
156          sbHtml.append(" summary=\"");
157          sbHtml.append(m_strSummary);
158          sbHtml.append("\"");
159       }
160       sbHtml.append(">\n");
161
162       // Since now we are inside of real table, insert here the header settings
163
// to configure table columns
164
sbHtml.append(getCachedContent(
165          ScrollableTableHeaderSettingsTag.SCROLLABLE_TABLE_HEADER_SETTINGS_CACHE, true));
166       
167       sbHtml.append("<tbody id=\"");
168       sbHtml.append(strScrollableTableId);
169       sbHtml.append("realbody\"");
170       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
171       {
172          sbHtml.append(" class=\"");
173          sbHtml.append(m_strCssclass);
174          sbHtml.append("RealBody");
175          sbHtml.append("\"");
176       }
177       sbHtml.append(">");
178       
179       TagUtils.write(pageContext, sbHtml.toString());
180       
181       return (EVAL_BODY_INCLUDE);
182    }
183
184    /**
185     * {@inheritDoc}
186     */

187    public int doEndTag(
188    ) throws JspException JavaDoc
189    {
190       // Finish the scrollable table body
191
TagUtils.write(pageContext, "</tbody>\n</table>\n</div>");
192       
193       return (EVAL_PAGE);
194    }
195    
196    /**
197     * @return String - summary describing content of the table
198     */

199    public String JavaDoc getSummary()
200    {
201       return m_strSummary;
202    }
203    
204    /**
205     * @param strSummary - summary describing content of the table
206     */

207    public void setSummary(
208       String JavaDoc strSummary
209    )
210    {
211       m_strSummary = strSummary;
212    }
213 }
214
Popular Tags