source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/ConfigurationBean.java@ 871

Last change on this file since 871 was 871, checked in by tobias, on May 10, 2010 at 7:42:51 PM

additional clients can be added to the configuration

File size: 7.6 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3import java.lang.reflect.Method;
4import java.util.ArrayList;
5
6import javax.faces.context.FacesContext;
7import javax.faces.event.ActionEvent;
8import javax.faces.event.ValueChangeEvent;
9import javax.faces.model.SelectItem;
10import javax.swing.tree.DefaultMutableTreeNode;
11import javax.swing.tree.DefaultTreeModel;
12import de.dass_it.vanhelsing.gui.items.*;
13import de.dass_it.www.vanhelsing.*;
14import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
15import de.dass_it.www.vanhelsing.VanHelsingStub.*;
16
17/**
18 * List all Bacula configuration components by name.
19 */
20public class ConfigurationBean implements IViewBean{
21
22
23 private DataTree dataTree;
24 private ConcreteUserObjectItem selectedObject;
25 private boolean createResource;
26 private String selectedId;
27
28 public ConfigurationBean() {
29 init();
30 }
31
32 /**
33 * init() builds the data tree of the configuration view. The heading nodes are read from the properties file.
34 * the web service will be queried for each heading node(e.g. client).
35 */
36 private void init(){
37 DefaultMutableTreeNode parent;
38 ResourceInfo resItems[];
39 SimpleResource sr;
40 Client c = new Client();
41 UserObjectItemFactory UOFactory = new UserObjectItemFactory();
42 setDataTree(new DataTree());
43 dataTree.setTree("Configuration");
44 for (String name : BeanUtil.getProperty("nodes").split(",")){
45 parent = dataTree.createNode(dataTree.getRoot(),
46 UOFactory.createUserObjectItem(
47 c.makeResourceInfo(BeanUtil.getProperty("defaultdirector"), -1, name, name)
48 )
49 );
50 resItems = c.getListResources(BeanUtil.getProperty("defaultdirector"), name);
51 if (resItems != null){
52 for (ResourceInfo rinfo : resItems){
53 sr = c.getSimpleResource(rinfo.getDirector(), rinfo.getResId());
54 if (sr != null){
55 //TODO: discard the SimpleResource ResInfo return value and work with the query object
56 dataTree.createNode(parent,
57 UOFactory.createUserObjectItem(
58 sr.getResourceAttributeType(), rinfo));
59 }
60 }
61 }
62 }
63 dataTree.createKeyValueLists();
64 dataTree.updateUserObjects();
65 createResource = false;
66 selectedObject = null;
67 }
68
69 /**
70 * transfers the selected (by attribute resId) dataobject (resource) into an ArrayList of ViewItems.<br/>
71 * Each ViewItem contain the key value pair and the rendering type. If the attribute is rendered as a
72 * selectOneMenu, the values for the selectOneMenu will be read from the data tree.
73 *
74 * @param ae ActionEvent which contains relevant information about the component tree. the variable is not used.
75 */
76 public void renderResource(ActionEvent ae){
77 DefaultMutableTreeNode node;
78 String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("userObject.resId");
79 int numId = new Integer(id);
80 String name = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("userObject.resName");
81 if (numId > 0){
82 node = dataTree.getNodeById(numId);
83 selectedObject = (ConcreteUserObjectItem)((UserObjectItemType)(node.getUserObject())).getUserObject();
84 } else {
85 node = dataTree.getNodeByName(name);
86 selectedObject = (ConcreteUserObjectItem)((UserObjectItemType)(node.getUserObject())).getUserObject();
87 }
88 createResource = false;
89 }
90
91 /**
92 * reads the properties of a given resource to create a resource object
93 * @param ae
94 */
95 public void newResourceButtonListener(ActionEvent ae){
96 String type = "Client";
97 UserObjectItemFactory UOFactory = new UserObjectItemFactory();
98 selectedObject = (ConcreteUserObjectItem)UOFactory.createUserObjectItem(type);
99 for (ViewItem vi : selectedObject.getViewItemList()){
100 if(vi.getSelectOneMenu()){
101 vi.setKeyValueList(dataTree.getKeyValueList().get(vi.getKey()));
102 }
103 if (vi.getRadioGroup()){
104 vi.setKeyValueList(dataTree.getKeyValueList().get("trueFalse"));
105 }
106 }
107 createResource = true;
108 }
109
110 public void newClientButtonListener(ActionEvent ae){
111 newResourceButtonListener(ae);
112 }
113 public void userObjectItemOptionSelected(ValueChangeEvent vce){
114 System.err.println("vce.oldValue: " +vce.getOldValue()+" vce.newValue: "+vce.getNewValue());
115
116 }
117 /**
118 * repeat the entire construction process of the data tree
119 * @param ae
120 */
121 public void reloadResourceButtonListener(ActionEvent ae){
122 init();
123 }
124 public void deleteResourceButtonListener(ActionEvent ae){
125 BeanUtil.setInfoMessage(null, "Diese Methode ist noch nicht implementiert.");
126 }
127 /**
128 * save the currently selected object
129 * @param ae
130 */
131 public void saveClientButtonListener(ActionEvent ae){
132 if (createResource){
133 Client c = new Client();
134 SimpleResource sr;
135 UserObjectItemFactory UOFactory = new UserObjectItemFactory();
136 for (ViewItem vi : selectedObject.getViewItemList()){
137 if(vi.getKey().equals("name")){
138 selectedObject.setResName(vi.getKeyValue());
139 }
140 }
141 int newResId =
142 c.createSimpleResource(c.makeResAttrTypeArray(selectedObject.getViewItemList()),
143 c.makeResourceInfo(selectedObject.getDirector(), selectedObject.getResId(),
144 selectedObject.getResName(), selectedObject.getResType()));
145 BeanUtil.setInfoMessage(null, "Neue Resource erzeugt (Id: "+newResId+")");
146 //neue Resource einlesen und in den Baum eintragen
147 //sr = c.getSimpleResource(selectedObject.getDirector(), newResId);
148 sr = new SimpleResource();
149 sr.setResourceAttributeType(c.makeResAttrTypeArray(selectedObject.getViewItemList()));
150 sr.setResourceInfo(c.makeResourceInfo(selectedObject.getDirector(), selectedObject.getResId(),
151 selectedObject.getResName(), selectedObject.getResType()));
152 dataTree.createNode(dataTree.getNodeByName("Client"),
153 UOFactory.createUserObjectItem(sr.getResourceAttributeType(),
154 sr.getResourceInfo()));
155 dataTree.updateUserObjects();
156 }
157 }
158
159 /**
160 * Setter method for the tree attribute
161 * @param tree tree contains the DefaultTreeModel for the data tree
162 */
163 public void setDataTree(DataTree dataTree) {
164 this.dataTree = dataTree;
165 }
166 /**
167 * getter method for the tree attribute
168 * @return tree tree contains the DefaultTreeModel for the data tree
169 */
170 public DataTree getDataTree() {
171 return dataTree;
172 }
173
174 public void createNodeButtonListener(ActionEvent ae) {
175 // TODO Auto-generated method stub
176
177 }
178
179 public void deleteNodeButtonListener(ActionEvent ae) {
180 // TODO Auto-generated method stub
181
182 }
183
184
185 public void readNodeButtonListener(ActionEvent ae) {
186 // TODO Auto-generated method stub
187
188 }
189
190 public void selectNode(ActionEvent ae) {
191 // TODO Auto-generated method stub
192
193 }
194
195 public void updateNodeButtonListener(ActionEvent ae) {
196 // TODO Auto-generated method stub
197
198 }
199
200 /**
201 * gettter method for the selectedObject attribute
202 * @return selectedObject selectedObject contains the data object of the selected leaf node.
203 */
204 public ConcreteUserObjectItem getSelectedObject() {
205 return selectedObject;
206 }
207
208 /**
209 * setter method for the selectedObject attribute
210 * @param selectedObject selectedObject contains the data object of the selected leaf node
211 */
212 public void setSelectedObject(ConcreteUserObjectItem selectedObject) {
213 this.selectedObject = selectedObject;
214 }
215
216 /**
217 * getter method for the resId attribute of the selectedObject i.e. the selected leaf node of the data tree
218 * @return id resId attribute of the selected object
219 */
220 public int getSelectedId(){
221 if (selectedObject != null){
222 return selectedObject.getResId();
223 }
224 return -1;
225 }
226 /*public String getSelectedName(){
227 if (selectedObject != null){
228 if (selectedObject.size() > 0){
229 return selectedObject.get(0).getResName();
230 }
231 }
232 return "";
233 }*/
234 public void setCreateResource(boolean b){
235 this.createResource = b;
236 }
237 public boolean getCreateResource(){
238 return createResource;
239 }
240
241}
Note: See TracBrowser for help on using the repository browser.