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

Last change on this file since 832 was 832, checked in by tobias, on Mar 5, 2010 at 6:03:21 PM

views and data objects of the resource types added.
basic logging with log4j for the beanUtil class.
Configuration and JobSchedule class renamed.

File size: 1.5 KB
Line 
1package de.dass_it.vanhelsing.gui;
2
3//import org.apache.log4j.Logger;
4import javax.swing.tree.DefaultTreeModel;
5import javax.swing.tree.DefaultMutableTreeNode;
6import de.dass_it.vanhelsing.gui.items.*;
7
8
9/*
10 * Helper class to encapsulate all procedure
11 * s to work with the tree structure.
12 */
13public class TreeNavigation extends BeanUtil {
14 private DefaultTreeModel tree;
15 //private Logger logger = Logger.getLogger(this.getClass());
16 public DefaultTreeModel createTree(DefaultMutableTreeNode root, String[] nodes){
17
18 tree = new DefaultTreeModel(root);
19 for(int i = 0; i< nodes.length; i++){
20 addNode(root, nodes[i]);
21 }
22
23 return tree;
24 }
25
26 public DefaultMutableTreeNode addNode(DefaultMutableTreeNode parent, String type){
27 DefaultMutableTreeNode node = new DefaultMutableTreeNode();
28 node.setParent(parent);
29 UserObjectItemType userObject = new UserObjectItemType(node);
30 type = "de.dass_it.vanhelsing.gui.items." + type + "Item";
31 try {
32 Class myClass = Class.forName(type);
33 UserObjectItem item = (UserObjectItem) myClass.newInstance();
34 userObject.setUserObjectItem(item);
35
36 } catch (ClassNotFoundException e){
37 System.err.println("Itemclass "+ type +" must be in the classpath");
38 } catch (InstantiationException e){
39 System.err.println("Class"+type+"must be a concrete class, not an interface or an abstract class");
40 } catch (IllegalAccessException e){
41 System.err.println("Class" + type + " lacks a no-argument constructor");
42 }
43
44 return node;
45 }
46}
Note: See TracBrowser for help on using the repository browser.