source: vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/TreeNavigation.java@ 844

Last change on this file since 844 was 844, checked in by tobias, on Mar 18, 2010 at 6:52:29 PM

all libraries moved to WEB-INF/lib

File size: 4.5 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3//import org.apache.log4j.Logger;
4import java.lang.reflect.Method;
5
6import javax.swing.tree.DefaultTreeModel;
7import javax.swing.tree.DefaultMutableTreeNode;
8import de.dass_it.vanhelsing.gui.items.*;
9import de.dass_it.www.vanhelsing.*;
10import de.dass_it.www.vanhelsing.VanHelsingCallbackHandler.*;
11import de.dass_it.www.vanhelsing.VanHelsingStub.*;
12
13/*
14 * Helper class to encapsulate all procedures
15 * to work with the tree structure.
16 */
17public class TreeNavigation extends BeanUtil {
18 private DefaultTreeModel tree;
19 //private Logger logger = Logger.getLogger(this.getClass());
20 public DefaultTreeModel createTree(DefaultMutableTreeNode root,
21 String[] nodes, String title){
22
23 DefaultMutableTreeNode node;
24 DefaultMutableTreeNode myNode;
25 tree = new DefaultTreeModel(root);
26 UserObjectItemType item = new UserObjectItemType(root);
27 UserObjectItem uoi = new TreeItem("Configuration");
28 uoi.setResType("Tree");
29 item.setUserObjectItem(uoi);
30 root.setUserObject(item);
31
32 for(int i = 0; i< nodes.length; i++){
33 //root.add(addNode(root, "Tree", nodes[i]));
34 myNode = null;
35 myNode = addNode(root, nodes[i], nodes[i]);
36 if (myNode != null){
37 root.add(myNode);
38 }
39 }
40 return tree;
41 }
42
43 public DefaultMutableTreeNode addNode(DefaultMutableTreeNode parent, String type, String title){
44 DefaultMutableTreeNode node = new DefaultMutableTreeNode();
45 Class subClass;
46 Class myClass;
47 Method[] methods;
48 Object o;
49 UserObjectItemType userObject = new UserObjectItemType(node);
50 String type2 = "de.dass_it.vanhelsing.gui.items." + type + "Item";
51
52 try {
53 subClass = Class.forName(type2);
54 o = subClass.newInstance();
55 UserObjectItem item = (UserObjectItem) o;
56 item.setResType(type);
57 myClass = item.getClass().asSubclass(subClass);
58 methods = myClass.getMethods();
59 for (Method m : methods){
60 System.err.println(m.getName());
61 if(m.getName().contains("setValue")){
62 m.invoke(item, title);
63 }
64 }
65 //ItemObjekt erzeugen und an das UserObjekt referenzieren
66 userObject.setUserObjectItem((UserObjectItem)o);
67 //Eine Referenz auf das UserObjekt wird an das Nodeobjekt übergeben
68 node.setUserObject(userObject);
69 return node;
70 } catch (ClassNotFoundException e1){
71 System.err.println("Itemclass "+ type2 +" must be in the classpath");
72 } catch (InstantiationException e2){
73 System.err.println("Class "+type2+" must be a concrete class, not an interface or an abstract class");
74 } catch (IllegalAccessException e3){
75 System.err.println("Class " + type2 + " lacks a no-argument constructor");
76 } catch (Exception e){
77 System.err.println(e.toString());
78 }
79
80 return null;
81 }
82 public DefaultMutableTreeNode addNode(DefaultMutableTreeNode parent, String type, ResourceInfo ri){
83 DefaultMutableTreeNode node = new DefaultMutableTreeNode();
84 Class subClass;
85 Class myClass;
86 Method[] riMethods;
87 Method[] methods;
88 Object o;
89 UserObjectItemType userObject = new UserObjectItemType(node);
90 String type2 = "de.dass_it.vanhelsing.gui.items." + type + "Item";
91
92 try {
93 subClass = Class.forName(type2);
94 o = subClass.newInstance();
95 UserObjectItem item = (UserObjectItem) o;
96 item.setResType(type);
97 myClass = item.getClass().asSubclass(subClass);
98 methods = myClass.getMethods();
99 ;
100 /*for (Method m : methods){
101 if(m.getName().contains("set" + p)){
102 m.invoke(item, title);
103 }
104 }*/
105 for (Method n : ri.getClass().getDeclaredMethods()){
106 if (n.getName().startsWith("get")
107 && !(n.getName().contains("OMElement") || n.getName().contains("PullParser"))){
108
109 System.err.println("Name: " + n.getName() +" Feld: "+ n.getName().substring(3));
110 for (Method m : methods){
111 if (m.getName().equals("set"+n.getName().substring(3))){
112 m.invoke(item, n.invoke(ri, (Object[])null));
113 }
114 }
115
116
117 }
118
119 }
120 //ItemObjekt erzeugen und an das UserObjekt referenzieren
121 userObject.setUserObjectItem((UserObjectItem)o);
122 //Eine Referenz auf das UserObjekt wird an das Nodeobjekt übergeben
123 node.setUserObject(userObject);
124 return node;
125 } catch (ClassNotFoundException e1){
126 System.err.println("Itemclass "+ type2 +" must be in the classpath");
127 } catch (InstantiationException e2){
128 System.err.println("Class "+type2+" must be a concrete class, not an interface or an abstract class");
129 } catch (IllegalAccessException e3){
130 System.err.println("Class " + type2 + " lacks a no-argument constructor");
131 } catch (Exception e){
132 System.err.println(e.toString());
133 }
134
135 return null;
136 }
137
138}
Note: See TracBrowser for help on using the repository browser.