1 4 package com.openedit.webui.tree; 5 6 import java.util.List ; 7 8 import org.apache.commons.logging.Log; 9 import org.apache.commons.logging.LogFactory; 10 11 import com.openedit.OpenEditException; 12 import com.openedit.WebPageRequest; 13 import com.openedit.modules.BaseModule; 14 import com.openedit.page.PageAction; 15 import com.openedit.page.manage.PageManager; 16 import com.openedit.users.User; 17 18 21 public class TreeModule extends BaseModule 22 { 23 private static final Log log = LogFactory.getLog(TreeModule.class); 24 public static final String PARAMETER_KEY = "treeName"; 25 protected PageManager fieldPageManager; 26 protected String fieldTreeName; 27 28 public void toggleTreeNode( WebPageRequest inRequest ) throws OpenEditException 29 { 30 WebTree tree = (WebTree) getTree(inRequest); 31 Object childNode = findNode(inRequest, tree); 32 if( childNode != null) 33 { 34 if( tree.getTreeRenderer().hasBeenExpanded(childNode) ) 35 { 36 tree.getTreeRenderer().collapseNode(childNode); 37 } 38 else 39 { 40 tree.getTreeRenderer().expandNode(childNode); 41 } 42 } 43 } 44 45 public void expandTreeNode( WebPageRequest inRequest ) throws OpenEditException 46 { 47 WebTree tree = (WebTree) getTree(inRequest); 48 if( tree != null) 49 { 50 Object childNode = findNode(inRequest, tree); 51 52 if (childNode == null) 53 { 54 log.error("Most specify nodeID or nodePath for expansion"); 55 return; 56 } 57 58 tree.getTreeRenderer().expandNode(childNode); 59 } 60 } 61 public void collapseTreeNode( WebPageRequest inRequest ) throws OpenEditException 62 { 63 WebTree tree = getTree(inRequest); 64 if( tree== null) 65 { 66 return; 67 } 68 Object childNode = findNode(inRequest, tree); 69 71 if (childNode == null) 72 { 73 log.error("Most specify nodeID or nodePath for expansion"); 74 return; 75 } 76 77 tree.getTreeRenderer().collapseNode(childNode); 79 } 80 protected Object findNode(WebPageRequest inRequest, WebTree tree) 81 { 82 String id = inRequest.getRequestParameter("nodeID"); 83 if (id != null) 84 { 85 Object childNode = tree.getModel().getChildById(id); 86 if ( childNode != null) 87 { 88 return childNode; 89 } 90 } 91 92 String path = inRequest.getRequestParameter("nodePath"); 94 if (path != null) 95 { 96 Object childNode = getNode((DefaultWebTreeNode) tree.getModel().getRoot(), path.split("/")); 97 return childNode; 98 } 99 return null; 100 } 101 102 public void reloadTree( WebPageRequest inRequest ) throws OpenEditException 103 { 104 String name = findValue("tree-name", inRequest); 105 106 108 inRequest.removeSessionValue(name + inRequest.getUser()); 109 inRequest.redirect(inRequest.getPath()); 110 } 111 112 118 public WebTree getTree( WebPageRequest inRequest ) throws OpenEditException 119 { 120 String treeid = inRequest.getRequestParameter("treeid"); 121 String name = findValue("tree-name",inRequest); 122 if( name == null) 123 { 124 name = findValue("WebTreeName",inRequest); } 126 if( treeid == null) 127 { 128 treeid = name + "_" + inRequest.getUserName(); 129 } 130 WebTree webTree = (WebTree) inRequest.getSessionValue(treeid); 131 132 if (webTree == null && name != null ) 133 { 134 PageAction inAction = inRequest.getCurrentAction(); 136 String root = null; 137 if( inAction.getConfig() != null) 138 { 139 root = inAction.getConfig().getChildValue( "root"); } 141 RepositoryTreeModel model = null; 142 143 if ((root == null) || root.equals("/")) 144 { 145 model = new RepositoryTreeModel( getPageManager().getRepository() ); 149 } 150 else 151 { 152 153 model = new RepositoryTreeModel(getPageManager().getRepository(), root ); 154 } 155 getPageManager().addPageAccessListener(model); 156 157 String ignore = (String ) inAction.getConfig().getChildValue("excludes"); 158 if (ignore != null) 159 { 160 String [] types = ignore.split(","); 161 for (int i = 0; i < types.length; i++) 162 { 163 model.ignore(types[i].trim()); 164 } 165 } 166 167 webTree = new WebTree(model); 168 webTree.setName(name); 169 webTree.setId(treeid); 170 WebTreeNodeTreeRenderer renderero = new WebTreeNodeTreeRenderer(webTree); 172 String prefix = inAction.getConfig().getChildValue( "url-prefix"); 173 if (prefix != null) 174 { 175 renderero.setUrlPrefix(prefix); 176 } 177 String friendly = (String ) inAction.getConfig().getChildValue("friendlyNames"); 178 if (friendly != null) 179 { 180 renderero.setFriendlyNames(Boolean.valueOf(friendly).booleanValue()); 181 } 182 String home = (String ) inRequest.getPageValue( "home" ); 183 renderero.setHome(home); 184 185 webTree.setTreeRenderer(renderero); 186 187 inRequest.putSessionValue(treeid, webTree); 188 } 189 if( webTree != null) 190 { 191 inRequest.putPageValue("pageManager",getPageManager()); 192 inRequest.putPageValue(name , webTree); 193 } 194 return webTree; 195 } 196 197 200 protected DefaultWebTreeNode getNode(DefaultWebTreeNode inRoot, String [] inPath) 201 { 202 DefaultWebTreeNode currentPath = inRoot; 203 204 for (int i = 0; i < inPath.length; i++) 205 { 206 List children = currentPath.getChildren(); 207 208 for (int j = 0; j < children.size(); j++) 209 { 210 DefaultWebTreeNode child = (DefaultWebTreeNode) children.get(j); 211 212 if (inPath[i].equals(child.getName())) 213 { 214 currentPath = child; 215 } 216 } 217 } 218 219 return currentPath; 220 } 221 222 223 public PageManager getPageManager() 224 { 225 return fieldPageManager; 226 } 227 public void setPageManager( PageManager pageManager ) 228 { 229 fieldPageManager = pageManager; 230 } 231 } 232 | Popular Tags |