KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > web > tag > support > HtmlCssDisplayProvider


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh.web.tag.support;
22
23 import java.util.HashMap JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import net.mlw.vlh.ValueListInfo;
27 import net.mlw.vlh.web.ValueListConfigBean;
28 import net.mlw.vlh.web.tag.TableInfo;
29
30 /**
31  * @author Sebastian Beigel, Andrej Zachar
32  * @version $Revision: 1.8 $ $Date: 2005/11/23 14:37:14 $
33  */

34 public class HtmlCssDisplayProvider extends AbstractHTMLDisplayProvider
35 {
36    /**
37     * Get the HTML that comes before the column text.
38     *
39     * @return The HTML that comes before the column text.
40     */

41    public String JavaDoc getHeaderCellPreProcess(ColumnInfo columnInfo, ValueListInfo info)
42    {
43       StringBuffer JavaDoc sb = new StringBuffer JavaDoc(255); // reasonable initial size to avoid the need to prolonge it
44
sb.append("\n<th ");
45
46       if (columnInfo != null)
47       {
48          String JavaDoc attributes = columnInfo.getAttributes();
49          if (attributes != null)
50          {
51             sb.append(attributes);
52          }
53
54          if (columnInfo.getDefaultSort() != null)
55          {
56             String JavaDoc column = info.getSortingColumn();
57             Integer JavaDoc direction = info.getSortingDirection();
58             if (columnInfo.getAdapterPropertyName().equals(column))
59             {
60                sb.append(" class=\"sortable ").append(((ValueListInfo.ASCENDING.equals(direction) ? "orderAsc" : "orderDesc")))
61                      .append("\"");
62             }
63             else
64             {
65                sb.append(" class=\"sortable\"");
66             }
67
68          } // columnInfo.getDefaultSort() != null
69

70          if (columnInfo.getToolTip() != null)
71          {
72             sb.append(" title=\"").append(columnInfo.getToolTip()).append("\""); // html attribute title renderes a toolTip
73
} // columnInfo.getToolTip() != null
74
}
75
76       sb.append(">");
77       return sb.toString();
78    }
79
80    /**
81     * Formats the text to be displayed as the header by waraping it in a link if
82     * sorting is enabled.
83     *
84     * @param columnInfo
85     * The ColumnInfo.
86     * @param tableInfo
87     * The TableInfo.
88     * @param info
89     * The ValueListInfo.
90     * @return The formated HTML.
91     */

92    public String JavaDoc getHeaderLabel(ColumnInfo columnInfo, TableInfo tableInfo, ValueListInfo info, Map JavaDoc includeParameters)
93    {
94
95       ValueListConfigBean config = tableInfo.getConfig();
96       Map JavaDoc parameters = new HashMap JavaDoc(includeParameters);
97
98       if (columnInfo.getDefaultSort() != null)
99       {
100          //Get the current sort column and direction.
101
String JavaDoc column = info.getSortingColumn();
102          Integer JavaDoc direction = info.getSortingDirection();
103
104          parameters.put(ValueListInfo.PAGING_NUMBER_PER + tableInfo.getId(), String.valueOf(info.getPagingNumberPer()));
105          parameters.put(ValueListInfo.PAGING_PAGE + tableInfo.getId(), "1");
106          parameters.put(ValueListInfo.SORT_COLUMN + tableInfo.getId(), columnInfo.getAdapterPropertyName());
107          parameters
108                .put(
109                      ValueListInfo.SORT_DIRECTION + tableInfo.getId(),
110                      ((columnInfo.getAdapterPropertyName().equals(column)) ? (ValueListInfo.ASCENDING.equals(direction) ? ValueListInfo.DESCENDING
111                            : ValueListInfo.ASCENDING)
112                            : columnInfo.getDefaultSort()));
113
114          if (info.isFocusEnabled())
115          {
116             parameters.put(ValueListInfo.DO_FOCUS + tableInfo.getId(), info.isDoFocusAgain() ? "true" : "false");
117             if (info.getFocusProperty() != null)
118             {
119                parameters.put(ValueListInfo.FOCUS_PROPERTY + tableInfo.getId(), info.getFocusProperty());
120             }
121             if (info.getFocusValue() != null)
122             {
123                parameters.put(ValueListInfo.FOCUS_VALUE + tableInfo.getId(), info.getFocusValue());
124             }
125          }
126
127          StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
128
129          renderHeaderLabelLink(sb, columnInfo, tableInfo, info, parameters);
130
131          return sb.toString();
132
133       }
134       else
135       {
136          return columnInfo.getTitle();
137       }
138    }
139
140    /**
141     * Renders a link as a header of the column if the sorting is enabled. Defined as protected to
142     * allow rewriting of an inhrited class.
143     *
144     * @param sb StringBuffer to render into
145     * @param columnInfo The ColumnInfo.
146     * @param tableInfo The TableInfo.
147     * @param info The ValueListInfo.
148     * @param parameters Map of parameters
149     */

150    protected void renderHeaderLabelLink(StringBuffer JavaDoc sb, ColumnInfo columnInfo, TableInfo tableInfo, ValueListInfo info, Map JavaDoc parameters)
151    {
152
153       String JavaDoc column = info.getSortingColumn();
154       Integer JavaDoc direction = info.getSortingDirection();
155
156       sb.append("<a HREF=\"").append(tableInfo.getUrl());
157
158       sb.append(tableInfo.getConfig().getLinkEncoder().encode(tableInfo.getPageContext(), parameters));
159
160       sb.append("\">").append(columnInfo.getTitle()).append("</a>");
161    }
162
163    /**
164     * Get the HTML that comes after the column text.
165     *
166     * @return The HTML that comes after the column text.
167     */

168    public String JavaDoc getHeaderCellPostProcess()
169    {
170       return "</th>";
171    }
172
173    public String JavaDoc getCellPreProcess(Attributes attributes)
174    {
175       return (attributes == null) ? "\n<td>" : "\n<td " + attributes.getCellAttributesAsString() + ">";
176    }
177
178    public String JavaDoc getCellPostProcess()
179    {
180       return "</td>";
181    }
182
183 }
184
Popular Tags