001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.contrib.tree.simple; 016 017 import java.io.Serializable; 018 import java.util.HashSet; 019 import java.util.Set; 020 021 import org.apache.tapestry.contrib.tree.model.ITreeStateModel; 022 023 /** 024 * @author ceco 025 */ 026 public class SimpleTreeStateModel implements ITreeStateModel, Serializable 027 { 028 029 private static final long serialVersionUID = 9206852255511734400L; 030 031 private Set m_setExpanded; 032 private Object m_objSelectedNodeUID = null; 033 034 /** 035 * Constructor for SimpleTreeStateModel. 036 */ 037 public SimpleTreeStateModel() 038 { 039 super(); 040 initialize(); 041 } 042 043 private void initialize() 044 { 045 m_setExpanded = new HashSet(); 046 m_objSelectedNodeUID = null; 047 } 048 049 /** 050 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getExpandSelection() 051 */ 052 public Set getExpandSelection() 053 { 054 return m_setExpanded; 055 } 056 057 /** 058 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expand(Object) 059 */ 060 public void expand(Object objUniqueKey) 061 { 062 m_setExpanded.add(objUniqueKey); 063 // setSelectedNode(objUniqueKey); 064 } 065 066 /** 067 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#expandPath(Object) 068 */ 069 public void expandPath(Object objUniqueKey) 070 { 071 m_setExpanded.add(objUniqueKey); 072 // setSelectedNode(objUniqueKey); 073 } 074 075 /** 076 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapse(Object) 077 */ 078 public void collapse(Object objUniqueKey) 079 { 080 m_setExpanded.remove(objUniqueKey); 081 // setSelectedNode(objUniqueKey); 082 } 083 084 /** 085 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#collapsePath(Object) 086 */ 087 public void collapsePath(Object objUniqueKey) 088 { 089 m_setExpanded.remove(objUniqueKey); 090 // setSelectedNode(objUniqueKey); 091 } 092 093 /** 094 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#isUniqueKeyExpanded(Object) 095 */ 096 public boolean isUniqueKeyExpanded(Object objUniqueKey) 097 { 098 return m_setExpanded.contains(objUniqueKey); 099 } 100 101 /** 102 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#getSelectedNode() 103 */ 104 public Object getSelectedNode() 105 { 106 return m_objSelectedNodeUID; 107 } 108 109 public void setSelectedNode(Object objUniqueKey) 110 { 111 if (m_objSelectedNodeUID == null 112 || !m_objSelectedNodeUID.equals(objUniqueKey)) 113 m_objSelectedNodeUID = objUniqueKey; 114 } 115 116 /** 117 * @see org.apache.tapestry.contrib.tree.model.ITreeStateModel#resetState() 118 */ 119 public void resetState() 120 { 121 initialize(); 122 } 123 124 }