KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > plugin > gui > ParametersWidgetsNode


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.plugin.gui;
24
25 import java.util.Enumeration JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 import org.apache.log4j.Category;
30 import org.objectweb.clif.scenario.util.isac.plugin.ParameterDescription;
31 import org.objectweb.clif.scenario.util.isac.util.tree.Node;
32 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager;
33
34 /**
35  * This class is a node of the parameters widgets trees
36  *
37  * @author JC Meillaud
38  * @author A Peyrard
39  */

40 public class ParametersWidgetsNode {
41     static Category cat = Category.getInstance(ParametersWidgetsNode.class
42             .getName());
43
44     private WidgetDescription widget;
45     private ParametersWidgetsNode parent;
46     private Vector JavaDoc children;
47
48     /**
49      * Build a new parameters widget node
50      *
51      * @param wd
52      * The widget description
53      */

54     public ParametersWidgetsNode(WidgetDescription wd) {
55         cat.debug("-> constructor");
56         this.widget = wd;
57         this.parent = null;
58         this.children = new Vector JavaDoc();
59     }
60
61     /**
62      * @return Returns the parent.
63      */

64     public ParametersWidgetsNode getParent() {
65         cat.debug("-> getParent");
66         return parent;
67     }
68     /**
69      * @param parent
70      * The parent to set.
71      */

72     public void setParent(ParametersWidgetsNode parent) {
73         cat.debug("-> setParent");
74         this.parent = parent;
75     }
76
77     /**
78      * Add a new child to this node
79      *
80      * @param child
81      * The child to be added
82      */

83     public void addChild(ParametersWidgetsNode child) {
84         cat.debug("-> addChild");
85         this.children.add(child);
86     }
87
88     /**
89      * @return Returns the children.
90      */

91     public Vector JavaDoc getChildren() {
92         cat.debug("-> getChildren");
93         return children;
94     }
95
96     /**
97      * Create a new parameters widgets node
98      *
99      * @param parametersNames
100      * The table containing all the parameters values
101      * @param type
102      * The type of the action to create the tree
103      * @param plugin
104      * The name of the plugin
105      * @return The default parameters widgets node created
106      */

107     public static ParametersWidgetsNode createParametersWidgetsNode(
108             Enumeration JavaDoc parametersNames, String JavaDoc type, String JavaDoc plugin) {
109         cat.debug("-> createParametersWidgetsNode");
110         ParametersWidgetsNode root = new ParametersWidgetsNode(null);
111         // add all the parameters
112
cat.warn("THE PWN CREATED IS TYPE : " + type);
113         cat.warn("THE PLUGIN OF THIS ACTION IS : " + plugin);
114         while (parametersNames.hasMoreElements()) {
115
116             ParameterDescription param = (ParameterDescription) parametersNames
117                     .nextElement();
118             cat.warn(" Parameter : " + param.getName());
119             // build a new description for this params
120
// only if it is not the "id" parameter
121
if (!param.getName().equals("id")) {
122                 WidgetDescription desc = new WidgetDescription(
123                         WidgetDescription.TEXT_FIELD, param.getName(),null, null);
124                 // add the new child
125
root.addChild(new ParametersWidgetsNode(desc));
126             } else {
127                 if (Node.isPluginNode(type)) {
128                     if (Node.USE.equals(type)) {
129                         // add a new field to set the id value
130
WidgetDescription desc = new WidgetDescription(
131                                 WidgetDescription.TEXT_FIELD, "id",null, null);
132                         root.addChild(new ParametersWidgetsNode(desc));
133                     } else {
134                         Vector JavaDoc ids = (TreeManager.getTreeManager(null))
135                                 .getPluginObjectByName(plugin);
136                         // build the params
137
Hashtable JavaDoc params = new Hashtable JavaDoc();
138                         // add the differents choices
139
params.put("choices", ids);
140                         WidgetDescription desc = new WidgetDescription(
141                                 WidgetDescription.COMBO, "id",null, params);
142                         root.addChild(new ParametersWidgetsNode(desc));
143                     }
144                 } else {
145                     WidgetDescription desc = new WidgetDescription(
146                             WidgetDescription.TEXT_FIELD, param.getName(),null, null);
147                     // add the new child
148
root.addChild(new ParametersWidgetsNode(desc));
149                 }
150             }
151         }
152         return root;
153     }
154
155     /**
156      * @return Returns the widget.
157      */

158     public WidgetDescription getWidget() {
159         cat.debug("-> getWidget");
160         return widget;
161     }
162
163     public String JavaDoc toString() {
164         String JavaDoc result = "";
165         cat.debug("-> constructor");
166         if (this.widget != null)
167             result = "Widget : \n" + this.widget.toString();
168         if (this.children != null) {
169             result = result + "this ParametersWidgetsNode has "
170                     + this.children.size() + " childrens;\n";
171             for (int i = 0; i < children.size(); i++) {
172                 result = result.concat(((ParametersWidgetsNode) this.children
173                         .elementAt(i)).toString());
174             }
175         }
176         return result;
177     }
178 }
Popular Tags