1 12 13 package com.openedit.webui.tree; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import com.openedit.util.PathUtilities; 19 20 26 public class DefaultWebTreeModel implements WebTreeModel 27 { 28 protected DefaultWebTreeNode fieldRoot; 29 30 33 public DefaultWebTreeModel() 34 { 35 } 36 37 42 public DefaultWebTreeModel(DefaultWebTreeNode inRoot) 43 { 44 fieldRoot = inRoot; 45 } 46 47 50 public Object getChild(Object parent, int index) 51 { 52 return ((DefaultWebTreeNode) parent).getChild(index); 53 } 54 public List getChildrenInRows(Object inParent, int inColCount) 55 { 56 List children = getChildren(inParent); 58 double rowscount = (double)children.size() / (double)inColCount; 59 60 List rows = new ArrayList (); 61 for (int i = 0; i < rowscount; i++) 62 { 63 int start = i*inColCount; 64 int end = i*inColCount + inColCount; 65 List sublist = children.subList(start,Math.min( children.size(),end )); 66 rows.add(sublist); 67 } 68 return rows; 69 70 } 71 public List getChildren(Object parent) 72 { 73 return ((DefaultWebTreeNode) parent).getChildren(); 74 } 75 76 79 public int getChildCount(Object parent) 80 { 81 return ((DefaultWebTreeNode) parent).getChildCount(); 82 } 83 84 87 public int getIndexOfChild(Object parent, Object child) 88 { 89 return ((DefaultWebTreeNode) parent).getIndexOfChild((DefaultWebTreeNode) child); 90 } 91 92 95 public boolean isLeaf(Object node) 96 { 97 return ((DefaultWebTreeNode) node).isLeaf(); 98 } 99 100 105 public void setRoot(DefaultWebTreeNode inRoot) 106 { 107 fieldRoot = inRoot; 108 } 109 110 113 public Object getRoot() 114 { 115 return fieldRoot; 116 } 117 118 public String getId( Object inNode ) 119 { 120 return String.valueOf( ( (DefaultWebTreeNode) inNode ).getID() ); 121 } 122 123 public Object getParent(Object inNode) 124 { 125 DefaultWebTreeNode child = (DefaultWebTreeNode) inNode; 126 return child.getParent(); 127 } 128 129 public Object getChildById(String inId) 130 { 131 return findNodeById(getRoot(), inId); 132 } 133 134 public Object findNodeById(Object inRoot, String inId) 135 { 136 String test = getId(inRoot); 137 if ( test.equals(inId) ) 138 { 139 return inRoot; 140 } 141 int count = getChildCount(inRoot); 142 for (int i = 0; i < count; i++) 143 { 144 Object child = getChild(inRoot,i); 145 child = findNodeById(child,inId); 146 if ( child != null) 147 { 148 return child; 149 } 150 } 151 return null; 152 } 153 154 155 } 156 | Popular Tags |