KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > tree > examples > fsmodel > FileSystemStateManager


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.workbench.tree.examples.fsmodel;
16
17 import java.io.File JavaDoc;
18
19 import org.apache.tapestry.contrib.tree.model.ITreeDataModel;
20 import org.apache.tapestry.contrib.tree.model.ITreeModel;
21 import org.apache.tapestry.contrib.tree.model.ITreeNode;
22 import org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager;
23 import org.apache.tapestry.contrib.tree.model.ITreeStateModel;
24 import org.apache.tapestry.contrib.tree.simple.SimpleTreeModel;
25
26 /**
27  * @author ceco
28  */

29 public class FileSystemStateManager implements ITreeSessionStateManager {
30     private String JavaDoc m_strRootDir;
31
32     /**
33      * Constructor for FileSystemStateManager.
34      */

35     public FileSystemStateManager(String JavaDoc strRootDir) {
36         super();
37         m_strRootDir = strRootDir;
38     }
39
40     /**
41      * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getSessionState(ITreeModel)
42      */

43     public Object JavaDoc getSessionState(ITreeModel objModel) {
44         return objModel.getTreeStateModel();
45     }
46
47     /**
48      * @see org.apache.tapestry.contrib.tree.model.ITreeSessionStateManager#getModel(Object)
49      */

50     public ITreeModel getModel(Object JavaDoc objSessionState) {
51         ITreeStateModel objStateModel = (ITreeStateModel) objSessionState;
52
53         ITreeNode objParent;
54
55         if (m_strRootDir == null || "".equals(m_strRootDir)) {
56             objParent = new FileSystem();
57         } else {
58             FolderObject objFolder = new FolderObject(null, new File JavaDoc(m_strRootDir), true);
59             objFolder.reload();
60             objParent = objFolder;
61         }
62
63         ITreeDataModel objDataModel = new FileSystemDataModel(objParent);
64         ITreeModel objModel = new SimpleTreeModel(objDataModel,
65                                                     objStateModel);
66
67         return objModel;
68     }
69 }
70
Popular Tags