View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.tree2;
20  
21  import java.util.HashSet;
22  
23  public class TreeStateBase implements TreeState
24  {
25  
26      private static final long serialVersionUID = -6767283932185878071L;
27      private HashSet _expandedNodes = new HashSet();
28      private boolean _transient = false;
29      private String _selected;
30  
31      // see interface
32      public boolean isNodeExpanded(String nodeId)
33      {
34          return (_expandedNodes.contains(nodeId) /*&& !getNode().isLeaf()*/);
35      }
36  
37      // see interface
38      public void toggleExpanded(String nodeId)
39      {
40          if (_expandedNodes.contains(nodeId))
41          {
42              _expandedNodes.remove(nodeId);
43          }
44          else
45          {
46              _expandedNodes.add(nodeId);
47          }
48      }
49  
50      // see interface
51      public boolean isTransient()
52      {
53          return _transient;
54      }
55  
56      // see interface
57      public void setTransient(boolean trans)
58      {
59          _transient = trans;
60      }
61  
62      // see interface
63      public void expandPath(String[] nodePath)
64      {
65          for (int i=0; i < nodePath.length; i++)
66          {
67              String nodeId = nodePath[i];
68              _expandedNodes.add(nodeId);
69          }
70      }
71  
72      // see interface
73      public void collapsePath(String[] nodePath)
74      {
75          for (int i=0; i < nodePath.length; i++)
76          {
77              String nodeId = nodePath[i];
78              _expandedNodes.remove(nodeId);
79          }
80      }
81  
82      public void setSelected(String nodeId)
83      {
84          _selected = nodeId;
85      }
86  
87      public boolean isSelected(String nodeId)
88      {
89          return nodeId.equals(_selected);
90      }
91  }