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

Last change on this file was 874, checked in by slederer, on May 21, 2010 at 5:57:59 PM

Ant-Buildfile und weitere Libraries hinzugefügt

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