01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.components.trees;
17:
18: import javax.swing.tree.DefaultMutableTreeNode;
19: import org.itsnat.comp.ItsNatTree;
20: import org.itsnat.comp.ItsNatTreeCellRenderer;
21: import org.itsnat.core.ItsNatDocument;
22: import org.itsnat.core.domutil.ElementRenderer;
23: import org.itsnat.core.domutil.ItsNatTreeWalker;
24: import org.w3c.dom.Element;
25: import org.w3c.dom.html.HTMLTableCellElement;
26:
27: public class TreeTableItemRenderer implements ItsNatTreeCellRenderer {
28: protected ElementRenderer renderer;
29:
30: public TreeTableItemRenderer(ItsNatDocument itsNatDoc) {
31: this .renderer = itsNatDoc.createDefaultElementRenderer();
32: }
33:
34: public void renderTreeCell(ItsNatTree tree, int row, Object value,
35: boolean selected, boolean expanded, boolean leaf,
36: boolean hasFocus, Element labelElem, boolean isNew) {
37: DefaultMutableTreeNode dataNode = (DefaultMutableTreeNode) value;
38: TreeTableItem item = (TreeTableItem) dataNode.getUserObject();
39: renderer.render(null, item.getPrincipal(), labelElem, isNew);
40:
41: Element labelParentElem = (Element) labelElem.getParentNode();
42:
43: if (labelParentElem instanceof HTMLTableCellElement) {
44: /*
45: <tr>
46: <td><img src="..." /><img src="..." /><span><b>Label</b></span></td>
47: <td><b>Other content</b></td>
48: </tr>
49: */
50: HTMLTableCellElement tdSecondElem = (HTMLTableCellElement) ItsNatTreeWalker
51: .getNextSiblingElement(labelParentElem);
52: renderer.render(null, item.getSecondary(), tdSecondElem,
53: isNew);
54: } else {
55: /*
56: <p>
57: <img src="..." /><img src="..." /><span><b>Label</b></span>
58: <span>Other content</span>
59: </p>
60: */
61: Element secondContentElem = ItsNatTreeWalker
62: .getNextSiblingElement(labelElem);
63: renderer.render(null, item.getSecondary(),
64: secondContentElem, isNew);
65: }
66: }
67:
68: public void unrenderTreeCell(ItsNatTree tree, int row,
69: Element treeNodeLabelElem) {
70: }
71: }
|