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.ElementList;
020: import org.itsnat.core.domutil.ElementListRenderer;
021: import org.itsnat.core.domutil.ElementListStructure;
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 PatternBasedElementListTreeNode extends FeatureTreeNode {
033: public PatternBasedElementListTreeNode() {
034: }
035:
036: public void startExamplePanel() {
037: buildList("elementListId", null, null);
038:
039: buildList("elementListId2", null, null);
040:
041: ElementListRenderer customRenderer = new ElementListRenderer() {
042: public void renderList(ElementList list, int index,
043: Object value, Element elem, boolean isNew) {
044: String style;
045: if (index == 0)
046: style = "font-style:italic;";
047: else if (index == 1)
048: style = "font-weight:bold;";
049: else
050: style = "font-size:large;";
051: elem.setAttribute("style", style);
052: ItsNatDOMUtil.setTextContent(elem, value.toString());
053: }
054:
055: public void unrenderList(ElementList list, int index,
056: Element contentElem) {
057: }
058: };
059:
060: buildList("elementListId3", null, customRenderer);
061:
062: ElementListStructure customStructure = new ElementListStructure() {
063: public Element getContentElement(ElementList list,
064: int index, Element elem) {
065: /*
066: <tr>
067: <td>
068: <table border="1px">
069: <tbody>
070: <tr><td>Element Pattern</td></tr>
071: </tbody>
072: </table>
073: </td>
074: </tr>
075: */
076: HTMLTableRowElement rowElem = (HTMLTableRowElement) elem;
077: HTMLTableCellElement cellElem = (HTMLTableCellElement) ItsNatTreeWalker
078: .getFirstChildElement(rowElem);
079: HTMLTableElement tableElem = (HTMLTableElement) ItsNatTreeWalker
080: .getFirstChildElement(cellElem);
081: HTMLTableSectionElement tbodyElem = (HTMLTableSectionElement) ItsNatTreeWalker
082: .getFirstChildElement(tableElem);
083: HTMLTableRowElement rowElem2 = (HTMLTableRowElement) ItsNatTreeWalker
084: .getFirstChildElement(tbodyElem);
085: HTMLTableCellElement cellElem2 = (HTMLTableCellElement) ItsNatTreeWalker
086: .getFirstChildElement(rowElem2);
087: return cellElem2;
088: }
089: };
090:
091: buildList("elementListId4", customStructure, customRenderer);
092: }
093:
094: public void buildList(String listId,
095: ElementListStructure customStructure,
096: ElementListRenderer customRenderer) {
097: ItsNatDocument itsNatDoc = getItsNatDocument();
098: Document doc = itsNatDoc.getDocument();
099: Element parent = doc.getElementById(listId);
100: ElementList elemList = itsNatDoc.createElementList(parent,
101: true, customStructure, customRenderer);
102: elemList.addElement("Madrid");
103: elemList.addElement("Barcelona");
104: elemList.addElement("Sevilla");
105: }
106:
107: public void endExamplePanel() {
108: }
109:
110: }
|