KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > tree > DefaultNodeRenderer


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.tree;
14
15 import org.w3c.dom.Document JavaDoc;
16 import org.w3c.dom.Element JavaDoc;
17
18 import com.tonbeller.wcf.controller.RequestContext;
19
20 /**
21  * creates an Element "tree-node" with an attribute "label", whose value is node.toString()
22  * @author av
23  */

24 public class DefaultNodeRenderer implements NodeRenderer {
25   protected String JavaDoc nodeElementName = DEFAULT_NODE_ELEMENT_NAME;
26   private LabelProvider labelProvider;
27
28   public DefaultNodeRenderer() {
29     labelProvider = new DefaultLabelProvider();
30   }
31
32   public DefaultNodeRenderer(LabelProvider labelProvider) {
33     this.labelProvider = labelProvider;
34   }
35   
36   public Element JavaDoc renderNode(RequestContext context, Document JavaDoc factory, Object JavaDoc node) {
37     Element JavaDoc nodeElem = factory.createElement(nodeElementName);
38     nodeElem.setAttribute("label", labelProvider.getLabel(node));
39     return nodeElem;
40   }
41
42   /**
43    * Returns the nodeElementName.
44    * @return String
45    */

46   public String JavaDoc getNodeElementName() {
47     return nodeElementName;
48   }
49
50   /**
51    * Sets the nodeElementName.
52    * @param nodeElementName The nodeElementName to set
53    */

54   public void setNodeElementName(String JavaDoc nodeElementName) {
55     this.nodeElementName = nodeElementName;
56   }
57
58   /**
59    * @return Returns the labelProvider.
60    */

61   public LabelProvider getLabelProvider() {
62     return labelProvider;
63   }
64   /**
65    * @param labelProvider The labelProvider to set.
66    */

67   public void setLabelProvider(LabelProvider labelProvider) {
68     this.labelProvider = labelProvider;
69   }
70 }
71
Popular Tags