- Timestamp:
- Mar 19, 2010, 5:51:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/gui/src/de/dass_it/vanhelsing/gui/TreeNavigation.java
r846 r847 75 75 System.err.println("Class " + type2 + " lacks a no-argument constructor"); 76 76 } catch (Exception e){ 77 System.err.println( e.toString());77 System.err.println("addHeader: " + e.toString()); 78 78 } 79 79 … … 133 133 System.err.println("Class " + type2 + " lacks a no-argument constructor"); 134 134 } catch (Exception e){ 135 System.err.println( e.toString());135 System.err.println("RI: " + e.toString()); 136 136 } 137 137 138 138 return null; 139 139 } 140 140 public DefaultMutableTreeNode addNode(DefaultMutableTreeNode parent, String type, ResourceAttributeType ra){ 141 DefaultMutableTreeNode node = new DefaultMutableTreeNode(); 142 Class subClass; 143 Class myClass; 144 Method[] raMethods; 145 Method[] methods; 146 Object o; 147 UserObjectItemType userObject = new UserObjectItemType(node); 148 String type2 = "de.dass_it.vanhelsing.gui.items." + type + "Item"; 149 String key = null, value = null; 150 try { 151 subClass = Class.forName(type2); 152 o = subClass.newInstance(); 153 UserObjectItem item = (UserObjectItem) o; 154 item.setResType(type); 155 myClass = item.getClass().asSubclass(subClass); 156 methods = myClass.getMethods(); 157 Method m; 158 Class[] args = new Class[1]; 159 args[0] = String.class; 160 /*for (Method m : methods){ 161 if(m.getName().contains("set" + p)){ 162 m.invoke(item, title); 163 } 164 }*/ 165 for (Method n : ra.getClass().getDeclaredMethods()){ 166 if (n.getName().equals("getKey")) { 167 key = (String)(n.invoke(ra, (Object[])null)); 168 } 169 if (n.getName().equals("getValue")){ 170 value = (String)(n.invoke(ra, (Object[])null)); 171 172 } 173 174 } 175 if(!(key.isEmpty() && value.isEmpty())){ 176 key = key.replaceAll(" ", ""); 177 key = key.replaceFirst(new Character(key.charAt(0)).toString(), 178 new Character(Character.toUpperCase(key.charAt(0))).toString()); 179 m = myClass.getMethod(("set"+key), args); 180 m.invoke(item, value); 181 ((ItemType)o).setValue(key + ": " + value); 182 183 } 184 185 186 187 188 189 //Value-Wert aus Key: Value zusammenbauen 190 191 //ItemObjekt erzeugen und an das UserObjekt referenzieren 192 userObject.setUserObjectItem((UserObjectItem)o); 193 //Eine Referenz auf das UserObjekt wird an das Nodeobjekt übergeben 194 node.setUserObject(userObject); 195 //System.out.println(((ItemType)((UserObjectItem)(node.getUserObject()))).getResId()); 196 return node; 197 } catch (ClassNotFoundException e1){ 198 System.err.println("Itemclass "+ type2 +" must be in the classpath"); 199 } catch (InstantiationException e2){ 200 System.err.println("Class "+type2+" must be a concrete class, not an interface or an abstract class"); 201 } catch (IllegalAccessException e3){ 202 System.err.println("Class " + type2 + " lacks a no-argument constructor"); 203 } catch (Exception e){ 204 System.err.println("Leaf: " + e.toString()); 205 } 206 207 return null; 208 } 141 209 }
Note:
See TracChangeset
for help on using the changeset viewer.