1 12 13 package com.openedit.webui.tree; 14 15 import java.util.List ; 16 17 18 24 public class WebTree 25 { 26 protected String fieldName; 27 protected String fieldId; 28 29 protected WebTreeModel fieldModel; 30 protected TreeRenderer fieldTreeRenderer; 31 32 public WebTree() 33 { 34 } 35 36 41 public WebTree(WebTreeModel inModel) 42 { 43 setModel(inModel); 44 } 46 47 public boolean isEmpty() 48 { 49 if ((getModel() == null) || (getModel().getChildCount(getModel().getRoot()) == 0)) 50 { 51 return true; 52 } 53 else 54 { 55 return false; 56 } 57 } 58 59 64 public void setModel(WebTreeModel model) 65 { 66 fieldModel = model; 67 if ( fieldModel != null && fieldTreeRenderer != null) 68 { 69 getTreeRenderer().expandNode( fieldModel.getRoot() ); 70 } 71 } 72 73 78 public WebTreeModel getModel() 79 { 80 if (fieldModel == null) 81 { 82 fieldModel = new DefaultWebTreeModel(); 83 } 84 85 return fieldModel; 86 } 87 88 public Object getChildChildren(int inCount) 89 { 90 List children = getModel().getChildren(getModel().getRoot() ); 91 if( children.size() < inCount) 92 { 93 Object parent = children.get(inCount); 94 return getModel().getChildren(parent); 95 } 96 return null; 97 } 98 99 100 101 106 public void setName(String inName) 107 { 108 fieldName = inName; 109 } 110 111 116 public String getName() 117 { 118 if (fieldName == null) 119 { 120 fieldName = "WebTree"; 121 } 122 123 return fieldName; 124 } 125 126 131 public String renderAsJavaScript() 132 { 133 TreeRenderer renderer = getTreeRenderer(); 134 return renderer.renderAsString(); 135 } 136 137 public TreeRenderer getTreeRenderer() 138 { 139 if (fieldTreeRenderer == null) 140 { 141 fieldTreeRenderer = new WebTreeNodeTreeRenderer(this); 142 } 143 return fieldTreeRenderer; 144 } 145 146 public void setTreeRenderer(TreeRenderer inTreeRenderer) 147 { 148 fieldTreeRenderer = inTreeRenderer; 149 if ( fieldModel != null && inTreeRenderer != null) 150 { 151 getTreeRenderer().expandNode( getModel().getRoot() ); 152 } 153 154 } 155 156 public String toString() 157 { 158 return getTreeRenderer().renderAsString(); 159 } 160 161 public String getId() 162 { 163 return fieldId; 164 } 165 166 public void setId(String inId) 167 { 168 fieldId = inId; 169 } 170 } 171 | Popular Tags |