01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wikitext.WidgetBuilder;
06: import fitnesse.html.HtmlTag;
07:
08: public class TableCellWidget extends ParentWidget {
09: private TableRowWidget parentRow = null;
10:
11: private boolean isLiteral;
12:
13: public TableCellWidget(TableRowWidget parentRow, String text,
14: boolean isLiteral) throws Exception {
15: super (parentRow);
16: this .parentRow = parentRow;
17: this .isLiteral = isLiteral;
18: addChildWidgets(text.trim());
19: }
20:
21: public String render() throws Exception {
22: return makeCellTag();
23: }
24:
25: private String makeCellTag() throws Exception {
26: HtmlTag cellTag = new HtmlTag("td");
27: if (computeColSpan().length() > 0) {
28: cellTag.addAttribute("colspan", computeColSpan());
29: }
30: if (childHtml().equals(""))
31: cellTag.add(" ");
32: else
33: cellTag.add(childHtml());
34:
35: // Add a column class so we have a CSS handle
36: int currentColumn = parentRow.children.indexOf(this ) + 1;
37: cellTag.addAttribute("class", "column" + currentColumn);
38: return cellTag.html();
39: }
40:
41: private String computeColSpan() {
42: int currentColumn = parentRow.children.indexOf(this ) + 1;
43: int maxTableColumn = parentRow.getParentTable().getColumns();
44: int maxColumnThisRow = parentRow.numberOfChildren();
45:
46: String colspan = "";
47: if (currentColumn == maxColumnThisRow
48: && currentColumn != maxTableColumn) {
49: colspan = String
50: .valueOf(maxTableColumn - currentColumn + 1);
51: }
52: return colspan;
53: // return "";
54: }
55:
56: public WidgetBuilder getBuilder() {
57: if (isLiteral)
58: return WidgetBuilder.literalAndVariableWidgetBuilder;
59: else
60: return parent.getBuilder();
61: }
62: }
|