root / tags / v1_1_Build_1012 / libraries / libGDBMS / src / test / java / com / hardcode / gdbms / gui / GDBMSAdapterTreeModel.java @ 12987
History | View | Annotate | Download (2.75 KB)
1 |
/*
|
---|---|
2 |
* Created on 12-oct-2004
|
3 |
*/
|
4 |
package com.hardcode.gdbms.gui; |
5 |
|
6 |
import com.hardcode.gdbms.engine.instruction.Adapter; |
7 |
import com.hardcode.gdbms.engine.instruction.Utilities; |
8 |
|
9 |
import java.util.Enumeration; |
10 |
import java.util.Hashtable; |
11 |
|
12 |
import javax.swing.tree.DefaultTreeModel; |
13 |
import javax.swing.tree.TreeNode; |
14 |
|
15 |
|
16 |
/**
|
17 |
* DOCUMENT ME!
|
18 |
*
|
19 |
* @author Fernando Gonz?lez Cort?s
|
20 |
*/
|
21 |
public class GDBMSAdapterTreeModel extends DefaultTreeModel { |
22 |
/**
|
23 |
* DOCUMENT ME!
|
24 |
*
|
25 |
* @param arg0
|
26 |
* @param arg1
|
27 |
*/
|
28 |
public GDBMSAdapterTreeModel(TreeNode arg0, boolean arg1) { |
29 |
super(arg0, arg1);
|
30 |
} |
31 |
|
32 |
/**
|
33 |
* DOCUMENT ME!
|
34 |
*
|
35 |
* @param arg0
|
36 |
*/
|
37 |
public GDBMSAdapterTreeModel(TreeNode arg0) { |
38 |
super(arg0);
|
39 |
} |
40 |
|
41 |
/**
|
42 |
* Crea un nuevo GDBMSAdapterTreeModel.
|
43 |
*
|
44 |
* @param root DOCUMENT ME!
|
45 |
*/
|
46 |
public GDBMSAdapterTreeModel(Adapter root) {
|
47 |
super(null); |
48 |
this.setRoot(new AdapterNode(root)); |
49 |
} |
50 |
|
51 |
/**
|
52 |
* DOCUMENT ME!
|
53 |
*
|
54 |
* @param root DOCUMENT ME!
|
55 |
*/
|
56 |
public void setTree(Adapter root) { |
57 |
this.setRoot(new AdapterNode(root)); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* DOCUMENT ME!
|
62 |
*
|
63 |
* @author Fernando Gonz?lez Cort?s
|
64 |
*/
|
65 |
public class AdapterNode implements TreeNode { |
66 |
private Adapter node;
|
67 |
|
68 |
/**
|
69 |
* Crea un nuevo AdapterNode.
|
70 |
*
|
71 |
* @param n DOCUMENT ME!
|
72 |
*/
|
73 |
public AdapterNode(Adapter n) {
|
74 |
node = n; |
75 |
} |
76 |
|
77 |
/**
|
78 |
* @see javax.swing.tree.TreeNode#getChildCount()
|
79 |
*/
|
80 |
public int getChildCount() { |
81 |
return node.getChilds().length;
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* @see javax.swing.tree.TreeNode#getAllowsChildren()
|
86 |
*/
|
87 |
public boolean getAllowsChildren() { |
88 |
return true; |
89 |
} |
90 |
|
91 |
/**
|
92 |
* @see javax.swing.tree.TreeNode#isLeaf()
|
93 |
*/
|
94 |
public boolean isLeaf() { |
95 |
return node.getChilds().length == 0; |
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see javax.swing.tree.TreeNode#children()
|
100 |
*/
|
101 |
public Enumeration children() { |
102 |
Hashtable foo = new Hashtable(); |
103 |
|
104 |
for (int i = 0; i < node.getChilds().length; i++) { |
105 |
foo.put(new AdapterNode(node.getChilds()[i]), ""); |
106 |
} |
107 |
|
108 |
return foo.keys();
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* @see javax.swing.tree.TreeNode#getParent()
|
113 |
*/
|
114 |
public TreeNode getParent() { |
115 |
return new AdapterNode(node.getParent()); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* @see javax.swing.tree.TreeNode#getChildAt(int)
|
120 |
*/
|
121 |
public TreeNode getChildAt(int arg0) { |
122 |
return new AdapterNode(node.getChilds()[arg0]); |
123 |
} |
124 |
|
125 |
/**
|
126 |
* @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
|
127 |
*/
|
128 |
public int getIndex(TreeNode arg0) { |
129 |
for (int i = 0; i < node.getChilds().length; i++) { |
130 |
if (((AdapterNode) arg0).node == node) {
|
131 |
return i;
|
132 |
} |
133 |
} |
134 |
|
135 |
return -1; |
136 |
} |
137 |
|
138 |
/**
|
139 |
* DOCUMENT ME!
|
140 |
*
|
141 |
* @return DOCUMENT ME!
|
142 |
*/
|
143 |
public String toString() { |
144 |
String className = node.getClass().getName();
|
145 |
className = className.substring(className.lastIndexOf("."));
|
146 |
|
147 |
return className + "(" + Utilities.getText(node.getEntity()) + ")"; |
148 |
} |
149 |
} |
150 |
} |