KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > guiframework > view > descriptors > CCDynamicTreeDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * CCDynamicTreeDescriptor.java
26  *
27  * Created on April 8, 2004, 1:25 PM
28  */

29
30 package com.sun.enterprise.tools.guiframework.view.descriptors;
31
32 import java.util.ArrayList JavaDoc;
33 import java.util.List JavaDoc;
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 //import com.sun.enterprise.tools.admingui.tree.BasicTree;
48

49 /**
50  *
51  * @author anilam
52  */

53 public class CCDynamicTreeDescriptor extends ViewDescriptor {
54     
55     
56     /** Creates a new instance of CCDynamicTreeDescriptor */
57     public CCDynamicTreeDescriptor(String JavaDoc name) {
58         super(name);
59         //System.out.println("!!!!!!!!!!! CCDynamicTreeDescriptor constructor ");
60
}
61     
62     /**
63      * This is a factory method for IndexTreeView instances.
64      *
65      * @param ctx The RequestContext
66      * @param container The container of the new IndexTreeView
67      * @param name The IndexTreeView name
68      */

69     public View getInstance(RequestContext ctx, ContainerView container, String JavaDoc name) {
70         //System.out.println("!!!!!!!!!!! getInstance ");
71
CCTreeModelInterface model = getModel(ctx, (String JavaDoc)getParameter("treeIteratorClass"), container);
72         return new DescriptorCCDynamicTree(ctx, container, name, this, model);
73     }
74     
75      public CCTreeModelInterface getModel(RequestContext ctx, String JavaDoc treeIteratorClassName, ContainerView container) {
76     // Determine if the session should be used w/ the model manager.
77
boolean fromSession = shouldGetModelFromSession();
78     boolean toSession = shouldPutModelToSession();
79     String JavaDoc instanceName = getModelInstanceName();
80         //System.out.println("!!!!!!!!!!! getModel");
81
// Use the ModelManager to create/get the model
82
// This is specified in admingui/ModelTypeMapImpl
83
ModelManager mgr = RequestManager.getRequestContext().getModelManager();
84     CCTreeModel model = (CCTreeModel)mgr.getModel(
85         CCTreeModelInterface.class,
86         instanceName, fromSession, toSession);
87         
88         //The model returned by the model manager is the same instance for every request.
89
//We should check if this has already been initialized and set up already before
90
//we try to initialize it.
91

92         List JavaDoc list = model.getNodes();
93         //System.out.println("!!!!!!!!!!!!!getNodes");
94
if (list ==null || list.size() ==0) {
95             //System.out.println("!!!!!!!!!!!!! node list size is EMPTY");
96
try{
97                 Class JavaDoc cls = Class.forName(treeIteratorClassName);
98                 BasicTree obj = (BasicTree) cls.newInstance();
99                 obj.init(this, ctx);
100                 //Create the root node
101
Object JavaDoc root = obj.getRoot();
102                 String JavaDoc 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 JavaDoc ex){
109                 throw new FrameworkException(
110                 "Cannot find the class " + treeIteratorClassName + " specified by the param 'modelClass'",
111                 ex, this, container);
112             }catch(Exception JavaDoc ex1){
113                 throw new FrameworkException("Cannot build the tree model ", ex1, this, container);
114             }
115         }
116         //System.out.println("!!!!!!!!!!!!! getModel returns");
117
return model;
118      }
119      
120      
121      private int createSubTree(BasicTree obj, Object JavaDoc parent, CCNavNode parentNode, int id){
122          
123          if (!obj.hasChildren(parent)){
124              parentNode.setAcceptsChildren(false);
125              return id;
126          }
127          ArrayList JavaDoc list = obj.getChildren(parent);
128          for(int i=0; i<list.size(); i++){
129              Object JavaDoc data = list.get(i);
130              String JavaDoc nm = obj.getDisplayName(data);
131             //System.out.println("XXXX call CCNavNode id= " + id + " nm=" +nm) ;
132
CCNavNode node = new CCNavNode(id++, nm, "", "");
133             //System.out.println("after creating CCNavNode");
134
node.setValue(obj.getURL()+obj.getKey(data));
135              //System.out.println(nm + ": Value set to " + node.getValue());
136
parentNode.addChild(node);
137              id = createSubTree(obj, data, node, id);
138          }
139          //System.out.println("====== CreateSubTree returns =========");
140
return id;
141      }
142 }
143
Popular Tags