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: package org.itsnat.feashow;
16:
17: import javax.swing.tree.DefaultMutableTreeNode;
18: import javax.swing.tree.TreePath;
19: import org.itsnat.comp.ItsNatTree;
20: import org.itsnat.comp.ItsNatTreeCellRenderer;
21: import org.itsnat.core.DocumentTemplate;
22: import org.itsnat.core.domutil.ItsNatTreeWalker;
23: import org.w3c.dom.Element;
24: import org.w3c.dom.html.HTMLAnchorElement;
25:
26: public class MainTreeRenderer implements ItsNatTreeCellRenderer {
27: protected ItsNatTreeCellRenderer delegate;
28:
29: public MainTreeRenderer(ItsNatTreeCellRenderer parent) {
30: this .delegate = parent;
31: }
32:
33: public void renderTreeCell(ItsNatTree tree, int row, Object value,
34: boolean isSelected, boolean isExpanded, boolean isLeaf,
35: boolean hasFocus, Element treeNodeLabelElem, boolean isNew) {
36: if (isNew) {
37: DocumentTemplate mainTemplate = tree.getItsNatDocument()
38: .getDocumentTemplate();
39: String mainTempName = mainTemplate.getName();
40:
41: TreePath path = tree.getTreePathForRow(row);
42: DefaultMutableTreeNode dataNode = (DefaultMutableTreeNode) path
43: .getLastPathComponent();
44: FeatureTreeNode feature = (FeatureTreeNode) dataNode
45: .getUserObject();
46: String featureName = feature.getFeatureName();
47:
48: HTMLAnchorElement permalink = (HTMLAnchorElement) ItsNatTreeWalker
49: .getNextSiblingElement(treeNodeLabelElem);
50: permalink.setHref("?itsnat_doc_name=" + mainTempName
51: + "&feature=" + featureName + ".default");
52: }
53:
54: delegate.renderTreeCell(tree, row, value, isSelected,
55: isExpanded, isLeaf, hasFocus, treeNodeLabelElem, isNew);
56: }
57:
58: public void unrenderTreeCell(ItsNatTree tree, int row,
59: Element treeNodeLabelElem) {
60: }
61: }
|