1 23 24 29 30 package com.sun.enterprise.tools.guiframework.view.descriptors; 31 32 import java.util.ArrayList ; 33 import java.util.List ; 34 import com.iplanet.jato.ModelManager; 35 import com.iplanet.jato.RequestManager; 36 import com.iplanet.jato.RequestContext; 37 import com.iplanet.jato.view.ContainerView; 38 import com.iplanet.jato.view.ContainerViewBase; 39 import com.iplanet.jato.view.View; 40 41 import com.sun.web.ui.model.CCTreeModel; 42 import com.sun.web.ui.model.CCTreeModelInterface; 43 import com.sun.web.ui.model.CCNavNode; 44 45 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 46 import com.sun.enterprise.tools.guiframework.view.DescriptorCCDynamicTree; 47 49 53 public class CCDynamicTreeDescriptor extends ViewDescriptor { 54 55 56 57 public CCDynamicTreeDescriptor(String name) { 58 super(name); 59 } 61 62 69 public View getInstance(RequestContext ctx, ContainerView container, String name) { 70 CCTreeModelInterface model = getModel(ctx, (String )getParameter("treeIteratorClass"), container); 72 return new DescriptorCCDynamicTree(ctx, container, name, this, model); 73 } 74 75 public CCTreeModelInterface getModel(RequestContext ctx, String treeIteratorClassName, ContainerView container) { 76 boolean fromSession = shouldGetModelFromSession(); 78 boolean toSession = shouldPutModelToSession(); 79 String instanceName = getModelInstanceName(); 80 ModelManager mgr = RequestManager.getRequestContext().getModelManager(); 84 CCTreeModel model = (CCTreeModel)mgr.getModel( 85 CCTreeModelInterface.class, 86 instanceName, fromSession, toSession); 87 88 92 List list = model.getNodes(); 93 if (list ==null || list.size() ==0) { 95 try{ 97 Class cls = Class.forName(treeIteratorClassName); 98 BasicTree obj = (BasicTree) cls.newInstance(); 99 obj.init(this, ctx); 100 Object root = obj.getRoot(); 102 String displayName = obj.getDisplayName(root); 103 CCNavNode rootNode = new CCNavNode(0, displayName, "", ""); 104 rootNode.setAsRoot(); 105 rootNode.setValue(obj.getURL()+obj.getKey(null)); 106 model.addNode(rootNode); 107 createSubTree(obj, root, rootNode, 1); 108 }catch (ClassNotFoundException ex){ 109 throw new FrameworkException( 110 "Cannot find the class " + treeIteratorClassName + " specified by the param 'modelClass'", 111 ex, this, container); 112 }catch(Exception ex1){ 113 throw new FrameworkException("Cannot build the tree model ", ex1, this, container); 114 } 115 } 116 return model; 118 } 119 120 121 private int createSubTree(BasicTree obj, Object parent, CCNavNode parentNode, int id){ 122 123 if (!obj.hasChildren(parent)){ 124 parentNode.setAcceptsChildren(false); 125 return id; 126 } 127 ArrayList list = obj.getChildren(parent); 128 for(int i=0; i<list.size(); i++){ 129 Object data = list.get(i); 130 String nm = obj.getDisplayName(data); 131 CCNavNode node = new CCNavNode(id++, nm, "", ""); 133 node.setValue(obj.getURL()+obj.getKey(data)); 135 parentNode.addChild(node); 137 id = createSubTree(obj, data, node, id); 138 } 139 return id; 141 } 142 } 143 | Popular Tags |