1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.contrib.tree.simple; |
16 |
| |
17 |
| import java.io.Serializable; |
18 |
| import java.util.Iterator; |
19 |
| |
20 |
| import javax.swing.tree.TreePath; |
21 |
| |
22 |
| import org.apache.tapestry.contrib.tree.model.ITreeDataModel; |
23 |
| import org.apache.tapestry.contrib.tree.model.ITreeNode; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class SimpleTreeDataModel implements ITreeDataModel, Serializable |
29 |
| { |
30 |
| private static final long serialVersionUID = 9215832847660213349L; |
31 |
| |
32 |
| protected ITreeNode m_objRootNode; |
33 |
| |
34 |
| |
35 |
| |
36 |
0
| public SimpleTreeDataModel(ITreeNode objRootNode) {
|
37 |
0
| super();
|
38 |
0
| m_objRootNode = objRootNode;
|
39 |
| } |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
0
| public Object getRoot() {
|
45 |
0
| return m_objRootNode;
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
0
| public int getChildCount(Object objParent) {
|
52 |
0
| ITreeNode objParentNode = (ITreeNode)objParent;
|
53 |
| |
54 |
0
| return objParentNode.getChildCount();
|
55 |
| } |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
0
| public Iterator getChildren(Object objParent) {
|
61 |
0
| ITreeNode objParentNode = (ITreeNode)objParent;
|
62 |
0
| return objParentNode.getChildren().iterator();
|
63 |
| } |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
0
| public Object getObject(Object objUniqueKey) {
|
69 |
0
| if(objUniqueKey != null) {
|
70 |
0
| TreePath objPath = (TreePath)objUniqueKey;
|
71 |
0
| return objPath.getLastPathComponent();
|
72 |
| } |
73 |
0
| return null;
|
74 |
| } |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
0
| public Object getUniqueKey(Object objTarget, Object objParentUniqueKey) {
|
80 |
0
| TreePath objPath = (TreePath)objParentUniqueKey;
|
81 |
0
| Object objTargetUID = null;
|
82 |
0
| if(objPath != null){
|
83 |
0
| objTargetUID = objPath.pathByAddingChild(objTarget);
|
84 |
| }else{ |
85 |
0
| objTargetUID = new TreePath(objTarget);
|
86 |
| } |
87 |
0
| return objTargetUID;
|
88 |
| } |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
0
| public boolean isAncestorOf(Object objTargetUniqueKey, Object objParentUniqueKey) {
|
94 |
0
| TreePath objParentPath = (TreePath)objParentUniqueKey;
|
95 |
0
| TreePath objTargetPath = (TreePath)objTargetUniqueKey;
|
96 |
0
| boolean bResult = objParentPath.isDescendant(objTargetPath);
|
97 |
0
| return bResult;
|
98 |
| } |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
0
| public Object getParentUniqueKey(Object objChildUniqueKey) {
|
104 |
0
| TreePath objChildPath = (TreePath)objChildUniqueKey;
|
105 |
0
| TreePath objParentPath = objChildPath.getParentPath();
|
106 |
0
| if(objParentPath == null)
|
107 |
0
| return null;
|
108 |
0
| return objParentPath.getLastPathComponent();
|
109 |
| } |
110 |
| |
111 |
| } |