KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ScrollableTableHeaderTag.java,v 1.7 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 header of scrollable
31  * table. The header of the table contains the column headings and will be created
32  * from the content of the body of this tag.
33  *
34  * @version $Id: ScrollableTableHeaderTag.java,v 1.7 2007/01/07 06:14:16 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed 1.4 2006/02/18 05:29:32 bastafidli
38  */

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

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

46    private static final long serialVersionUID = -1476760014171394974L;
47
48    // Constructors /////////////////////////////////////////////////////////////
49

50    /**
51     * Constructor for custom tag.
52     */

53    public ScrollableTableHeaderTag()
54    {
55       super("clsScrollableTable", BlockElementTag.DIV_BLOCK_ELEMENT);
56    }
57    
58    // Business logic ///////////////////////////////////////////////////////////
59

60    /**
61     * {@inheritDoc}
62     */

63    public int doStartTag(
64    ) throws JspException JavaDoc
65    {
66       StringBuffer JavaDoc sbHtml = null;
67       Object JavaDoc objTemp;
68       String JavaDoc strScrollableTableId;
69       boolean bSortableTable;
70
71       objTemp = getCachedContent(ScrollableTableTag.ACTIVE_SCROLLABLE_TABLE_ID,
72                                  false).trim();
73       if (objTemp == null)
74       {
75          throw new JspException JavaDoc("Cannot find scrollable table id on the page. Probable" +
76                                 " cause is that the scrollable table open tag is missing.");
77       }
78       strScrollableTableId = (String JavaDoc)objTemp;
79       
80       objTemp = getCachedContent(ScrollableTableTag.SCROLLABLE_TABLE_SORTABLE,
81                                  false).trim();
82       bSortableTable = (Boolean.TRUE.toString().equalsIgnoreCase((String JavaDoc)objTemp))
83              || ("1".equals((String JavaDoc)objTemp));
84
85       sbHtml = new StringBuffer JavaDoc();
86
87       
88       /*
89       This is how a start of header of a scrollable table looks like
90       
91       We cannot use table because if table has overflow: hidden, then the
92       elements always shrink to fit into visible space. On the other hand
93       div works as expected so we can scroll headers out of view
94       
95       <div id="scrollabletableheader" class="clsScrollableTableHeader"
96            onclick="sortScrollTable(event, 'scrollabletablerealbody');">
97       */

98
99       // Generate the start of the tabbed dialog tab header
100
sbHtml.append("<div id=\"");
101       sbHtml.append(strScrollableTableId);
102       sbHtml.append("header\"");
103       if ((m_strCssclass != null) && (m_strCssclass.length() > 0))
104       {
105          sbHtml.append(" class=\"");
106          sbHtml.append(m_strCssclass);
107          sbHtml.append("Header");
108          sbHtml.append("\"");
109       }
110
111       if (bSortableTable)
112       {
113          sbHtml.append(" onclick=\"sortScrollTable(event, '");
114          sbHtml.append(strScrollableTableId);
115          sbHtml.append("realbody');\"");
116       }
117       sbHtml.append(">");
118       
119       TagUtils.write(pageContext, sbHtml.toString());
120       
121       return (EVAL_BODY_INCLUDE);
122    }
123
124    /**
125     * {@inheritDoc}
126     */

127    public int doEndTag(
128    ) throws JspException JavaDoc
129    {
130       // Finish the scrollable table header
131
TagUtils.write(pageContext, "</div>");
132       
133       return (EVAL_PAGE);
134    }
135 }
136
Popular Tags