KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > tree > simple > SimpleTreeStateModel


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.contrib.tree.simple;
16
17 import java.io.Serializable JavaDoc;
18 import java.util.HashSet JavaDoc;
19 import java.util.Set JavaDoc;
20
21 import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
22
23 /**
24  * @author ceco
25  */

26 public class SimpleTreeStateModel implements ITreeStateModel, Serializable JavaDoc{
27
28     private Set JavaDoc m_setExpanded;
29     private Object JavaDoc m_objSelectedNodeUID = null;
30     
31     /**
32      * Constructor for SimpleTreeStateModel.
33      */

34     public SimpleTreeStateModel() {
35         super();
36         initialize();
37     }
38     private void initialize(){
39         m_setExpanded = new HashSet JavaDoc();
40         m_objSelectedNodeUID = null;
41     }
42
43     /**
44      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getExpandSelection()
45      */

46     public Set JavaDoc getExpandSelection() {
47         return m_setExpanded;
48     }
49     
50     /**
51      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expand(Object)
52      */

53     public void expand(Object JavaDoc objUniqueKey) {
54         m_setExpanded.add(objUniqueKey);
55         //setSelectedNode(objUniqueKey);
56
}
57
58     /**
59      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expandPath(Object)
60      */

61     public void expandPath(Object JavaDoc objUniqueKey) {
62         m_setExpanded.add(objUniqueKey);
63         //setSelectedNode(objUniqueKey);
64
}
65
66     /**
67      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapse(Object)
68      */

69     public void collapse(Object JavaDoc objUniqueKey) {
70         m_setExpanded.remove(objUniqueKey);
71         //setSelectedNode(objUniqueKey);
72
}
73
74     /**
75      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapsePath(Object)
76      */

77     public void collapsePath(Object JavaDoc objUniqueKey) {
78         m_setExpanded.remove(objUniqueKey);
79         //setSelectedNode(objUniqueKey);
80
}
81
82     /**
83      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#isUniqueKeyExpanded(Object)
84      */

85     public boolean isUniqueKeyExpanded(Object JavaDoc objUniqueKey) {
86         return m_setExpanded.contains(objUniqueKey);
87     }
88     /**
89      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getSelectedNode()
90      */

91     public Object JavaDoc getSelectedNode() {
92         return m_objSelectedNodeUID;
93     }
94     
95     public void setSelectedNode(Object JavaDoc objUniqueKey){
96         if(m_objSelectedNodeUID == null || !m_objSelectedNodeUID.equals(objUniqueKey))
97             m_objSelectedNodeUID = objUniqueKey;
98     }
99
100     /**
101      * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#resetState()
102      */

103     public void resetState() {
104         initialize();
105     }
106
107 }
108
Popular Tags