source: vanHelsing/branches/guitechdemo/src/de/dass_it/vanhelsing/gui/ConfigurationBean.java@ 853

Last change on this file since 853 was 849, checked in by tobias, on Mar 23, 2010 at 3:01:06 PM

configView with item data

File size: 4.2 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3import java.lang.reflect.Method;
4import java.util.ArrayList;
5
6import javax.faces.event.ActionEvent;
7import javax.swing.tree.DefaultMutableTreeNode;
8import javax.swing.tree.DefaultTreeModel;
9import de.dass_it.vanhelsing.gui.items.*;
10import de.dass_it.www.vanhelsing.*;
11import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
12import de.dass_it.www.vanhelsing.VanHelsingStub.*;
13
14/*
15 * List all Bacula configuration components by name
16 */
17public class ConfigurationBean extends TreeNavigation {
18
19 private DefaultTreeModel tree;
20 private ArrayList<ViewItem> selectedObject;
21
22 public ConfigurationBean(){
23 DefaultMutableTreeNode root = new DefaultMutableTreeNode();
24 DefaultMutableTreeNode header;
25 DefaultMutableTreeNode leaf;
26 String type;
27 ListResourcesType lrt;
28 GetResourceType grt;
29 DefaultMutableTreeNode myNode;
30 ResourceInfo[] ri;
31 SimpleResource sr;
32 //((ClientItem)selectedObject).setName("ClientNameTest");
33
34 Client c = new Client();
35 String[] nodes = {"Director", "Storage", "Catalog", "Autochanger", "Client", "FileSet", "FDClient", "Schedule", "SDStorage", "Console", "Catalog", "SDDevice", "Job", "JobDefs", "Messages", "Pool"};
36 //String[] nodes = {"Client"};
37 setTree(super.createTree(root, nodes, "Configuration"));
38
39 //forall header wird eine ResourceList[] angefragt
40 for(int i = 0; i < tree.getChildCount(root); i++){
41 header = (DefaultMutableTreeNode)tree.getChild(root, i);
42 type = ((UserObjectItemType)header.getUserObject()).getUserObject().getResType();
43 lrt = new ListResourcesType();
44 lrt.setDirector("bacula-dir");
45 lrt.setResourceType(type);
46 ri = c.getListResources(lrt);
47 if (ri == null || ri.length == 0) continue;
48 for (int j = 0; j < ri.length; j++){
49 //myNode = null;
50 myNode = addNode(header, type, ri[j]);
51 //Node mit Daten befüllen
52 grt = new GetResourceType();
53 grt.setDirector(lrt.getDirector());
54 grt.setResId(ri[j].getResId());
55 sr = c.getSimpleResource(grt);
56 myNode = addNode(myNode, type, sr.getResourceAttributeType());
57 if (myNode != null){
58 header.add(myNode);
59 }
60 }
61 }
62 /*for (int i = 0; i < tree.getChildCount(root); i++){
63 header = (DefaultMutableTreeNode)tree.getChild(root, i);
64
65 for (int j = 0; j < tree.getChildCount(header); j++){
66 leaf = (DefaultMutableTreeNode)tree.getChild(header, j);
67 type = ((UserObjectItemType)leaf.getUserObject()).getUserObject().getResType();
68 grt = new GetResourceType();
69 grt.setDirector("bacula-dir");
70 grt.setResId(((ItemType)(((UserObjectItemType)leaf.getUserObject()).getUserObject())).getResId());
71 sr = c.getSimpleResource(grt);
72 sr.getResourceAttributeType();
73 myNode = addNode(leaf, type, sr.getResourceAttributeType());
74 if (myNode != null){
75 leaf.add(myNode);
76 }
77
78 }
79 }*/
80
81
82 }
83 public void userObjectItemNodeSelected(ActionEvent ae){
84 DefaultMutableTreeNode node;
85 UserObjectItem userObject;
86 selectedObject = new ArrayList<ViewItem>();
87 String Id = BeanUtil.getRequestParameter("userObject.resId");
88 node = getNode(Id, tree);
89 String type = ((UserObjectItem)((UserObjectItemType)node.getUserObject()).getUserObject()).getResType();
90 String classType = "de.dass_it.vanhelsing.gui.items." + type + "Item";
91 //Daten aus dem UserObjectItem extrahieren
92 try {
93
94 UserObjectItem item = ((UserObjectItemType)(node.getUserObject())).getUserObject();
95
96 Class c = ((UserObjectItemType)(node.getUserObject())).getUserObject().getClass();
97 Method[] m = c.getDeclaredMethods();
98 String keyValue;
99 String key;
100 ViewItem vi;
101 for (Method n : m) {
102 if(n.getName().startsWith("get")) {
103 keyValue = (String)n.invoke(item, (Object[])null);
104 if (keyValue == null) continue;
105 key = n.getName().substring(3);
106 vi = new ViewItem();
107 vi.setKey(key); vi.setKeyValue(keyValue); vi.setResType(type);
108 selectedObject.add(vi);
109 }
110 }
111 } catch(Exception e) {
112 e.printStackTrace();
113 }
114 }
115
116 public void setTree(DefaultTreeModel tree) {
117 this.tree = tree;
118 }
119 public DefaultTreeModel getTree() {
120 return tree;
121 }
122 public ArrayList<ViewItem> getSelectedObject() {
123 return selectedObject;
124 }
125 public void setSelectedObject(ArrayList<ViewItem> selectedObject) {
126 this.selectedObject = selectedObject;
127 }
128
129
130}
Note: See TracBrowser for help on using the repository browser.