001: /*
002: * This file is not part of the ItsNat framework.
003: *
004: * Original source code use and closed source derivatives are authorized
005: * to third parties with no restriction or fee.
006: * The original source code is owned by the author.
007: *
008: * This program is distributed AS IS in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
011: *
012: * Author: Jose Maria Arranz Santamaria
013: * (C) Innowhere Software Services S.L., Spanish company, year 2007
014: */
015:
016: package org.itsnat.feashow.features.core.domutils;
017:
018: import org.itsnat.core.ItsNatDocument;
019: import org.itsnat.core.domutil.ElementTable;
020: import org.itsnat.core.domutil.ElementTableRenderer;
021: import org.itsnat.core.domutil.ElementTableStructure;
022: import org.itsnat.core.domutil.ItsNatDOMUtil;
023: import org.itsnat.core.domutil.ItsNatTreeWalker;
024: import org.itsnat.feashow.FeatureTreeNode;
025: import org.w3c.dom.Document;
026: import org.w3c.dom.Element;
027: import org.w3c.dom.html.HTMLTableCellElement;
028: import org.w3c.dom.html.HTMLTableElement;
029: import org.w3c.dom.html.HTMLTableRowElement;
030: import org.w3c.dom.html.HTMLTableSectionElement;
031:
032: public class PatternBasedElementTableTreeNode extends FeatureTreeNode {
033: public PatternBasedElementTableTreeNode() {
034: }
035:
036: public void startExamplePanel() {
037:
038: buildTable("tableId", null, null);
039:
040: ElementTableRenderer customRenderer = new ElementTableRenderer() {
041: public void renderTable(ElementTable table, int row,
042: int col, Object value, Element elem, boolean isNew) {
043: String style;
044: if (row == 0)
045: style = "font-style:italic;";
046: else if (row == 1)
047: style = "font-weight:bold;";
048: else
049: style = "font-size:large;";
050: elem.setAttribute("style", style);
051: ItsNatDOMUtil.setTextContent(elem, value.toString());
052: }
053:
054: public void unrenderTable(ElementTable table, int row,
055: int col, Element cellContentElem) {
056: }
057: };
058:
059: buildTable("tableId2", null, customRenderer);
060:
061: ElementTableStructure customStructure = new ElementTableStructure() {
062: /*
063: <tbody id="tableId3">
064: <tr> <-- row
065: <td>
066: <table>
067: <tbody>
068: <tr> <-- row content
069: <td> <-- cell
070: <table>
071: <tbody>
072: <tr>
073: <td>Cell pattern</td> <-- td: cell content
074: </tr>
075: </tbody>
076: </table>
077: </td>
078: ...
079: </tr>
080: </tbody>
081: </table>
082: </td>
083: </tr>
084: </tbody>
085: */
086: public Element getRowContentElement(ElementTable table,
087: int row, Element elem) {
088: HTMLTableRowElement rowElem = (HTMLTableRowElement) elem;
089: HTMLTableCellElement cellElem = (HTMLTableCellElement) ItsNatTreeWalker
090: .getFirstChildElement(rowElem);
091: HTMLTableElement tableElem = (HTMLTableElement) ItsNatTreeWalker
092: .getFirstChildElement(cellElem);
093: HTMLTableSectionElement tbodyElem = (HTMLTableSectionElement) ItsNatTreeWalker
094: .getFirstChildElement(tableElem);
095: HTMLTableRowElement rowElem2 = (HTMLTableRowElement) ItsNatTreeWalker
096: .getFirstChildElement(tbodyElem);
097: return rowElem2;
098: }
099:
100: public Element getCellContentElement(ElementTable table,
101: int row, int col, Element elem) {
102: HTMLTableCellElement cellElem = (HTMLTableCellElement) elem;
103: HTMLTableElement tableElem = (HTMLTableElement) ItsNatTreeWalker
104: .getFirstChildElement(cellElem);
105: HTMLTableSectionElement tbodyElem = (HTMLTableSectionElement) ItsNatTreeWalker
106: .getFirstChildElement(tableElem);
107: HTMLTableRowElement rowElem = (HTMLTableRowElement) ItsNatTreeWalker
108: .getFirstChildElement(tbodyElem);
109: HTMLTableCellElement cellElem2 = (HTMLTableCellElement) ItsNatTreeWalker
110: .getFirstChildElement(rowElem);
111: return cellElem2;
112: }
113:
114: };
115:
116: buildTable("tableId3", customStructure, customRenderer);
117:
118: buildTable("tableId4", null, null);
119: }
120:
121: public void buildTable(String tableId,
122: ElementTableStructure customStructure,
123: ElementTableRenderer customRenderer) {
124: ItsNatDocument itsNatDoc = getItsNatDocument();
125: Document doc = itsNatDoc.getDocument();
126:
127: Element parent = doc.getElementById(tableId);
128: ElementTable elemTable = itsNatDoc.createElementTable(parent,
129: true, customStructure, customRenderer);
130: elemTable.setColumnCount(3);
131: elemTable.addRow(new String[] { "Madrid", "Plaza Mayor",
132: "Palacio Real" });
133: elemTable.addRow(new String[] { "Sevilla", "Plaza de Espaņa",
134: "Giralda" });
135: elemTable.addRow(new String[] { "Segovia",
136: "Plaza del Azoguejo", "Acueducto Romano" });
137: }
138:
139: public void endExamplePanel() {
140: }
141:
142: }
|