Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SimpleTreeStateModel |
|
| 1.1818181818181819;1.182 |
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; | |
18 | import java.util.HashSet; | |
19 | import java.util.Set; | |
20 | ||
21 | import org.apache.tapestry.contrib.tree.model.ITreeStateModel; | |
22 | ||
23 | /** | |
24 | * @author ceco | |
25 | */ | |
26 | public class SimpleTreeStateModel implements ITreeStateModel, Serializable | |
27 | { | |
28 | ||
29 | private static final long serialVersionUID = 9206852255511734400L; | |
30 | ||
31 | private Set m_setExpanded; | |
32 | 0 | private Object m_objSelectedNodeUID = null; |
33 | ||
34 | /** | |
35 | * Constructor for SimpleTreeStateModel. | |
36 | */ | |
37 | public SimpleTreeStateModel() | |
38 | { | |
39 | 0 | super(); |
40 | 0 | initialize(); |
41 | 0 | } |
42 | ||
43 | private void initialize() | |
44 | { | |
45 | 0 | m_setExpanded = new HashSet(); |
46 | 0 | m_objSelectedNodeUID = null; |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getExpandSelection() | |
51 | */ | |
52 | public Set getExpandSelection() | |
53 | { | |
54 | 0 | return m_setExpanded; |
55 | } | |
56 | ||
57 | /** | |
58 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expand(Object) | |
59 | */ | |
60 | public void expand(Object objUniqueKey) | |
61 | { | |
62 | 0 | m_setExpanded.add(objUniqueKey); |
63 | // setSelectedNode(objUniqueKey); | |
64 | 0 | } |
65 | ||
66 | /** | |
67 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expandPath(Object) | |
68 | */ | |
69 | public void expandPath(Object objUniqueKey) | |
70 | { | |
71 | 0 | m_setExpanded.add(objUniqueKey); |
72 | // setSelectedNode(objUniqueKey); | |
73 | 0 | } |
74 | ||
75 | /** | |
76 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapse(Object) | |
77 | */ | |
78 | public void collapse(Object objUniqueKey) | |
79 | { | |
80 | 0 | m_setExpanded.remove(objUniqueKey); |
81 | // setSelectedNode(objUniqueKey); | |
82 | 0 | } |
83 | ||
84 | /** | |
85 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapsePath(Object) | |
86 | */ | |
87 | public void collapsePath(Object objUniqueKey) | |
88 | { | |
89 | 0 | m_setExpanded.remove(objUniqueKey); |
90 | // setSelectedNode(objUniqueKey); | |
91 | 0 | } |
92 | ||
93 | /** | |
94 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#isUniqueKeyExpanded(Object) | |
95 | */ | |
96 | public boolean isUniqueKeyExpanded(Object objUniqueKey) | |
97 | { | |
98 | 0 | return m_setExpanded.contains(objUniqueKey); |
99 | } | |
100 | ||
101 | /** | |
102 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getSelectedNode() | |
103 | */ | |
104 | public Object getSelectedNode() | |
105 | { | |
106 | 0 | return m_objSelectedNodeUID; |
107 | } | |
108 | ||
109 | public void setSelectedNode(Object objUniqueKey) | |
110 | { | |
111 | 0 | if (m_objSelectedNodeUID == null |
112 | || !m_objSelectedNodeUID.equals(objUniqueKey)) | |
113 | 0 | m_objSelectedNodeUID = objUniqueKey; |
114 | 0 | } |
115 | ||
116 | /** | |
117 | * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#resetState() | |
118 | */ | |
119 | public void resetState() | |
120 | { | |
121 | 0 | initialize(); |
122 | 0 | } |
123 | ||
124 | } |