KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Collection JavaDoc;
19 import java.util.Date JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.tapestry.contrib.tree.model.ITreeNode;
23
24 public class FileSystem implements IFileSystemTreeNode
25 {
26
27   private transient AssetsHolder m_objAssetsHolder = null;
28     /** @associates <{Drive}>
29      * @supplierCardinality 0..*
30      * @link aggregation*/

31     
32   private Vector JavaDoc m_vDrives;
33
34   public FileSystem()
35   {
36     //initDrives();
37
}
38
39   private void initDrives()
40   {
41     m_vDrives = new Vector JavaDoc();
42     File JavaDoc[] arrFile = File.listRoots();
43
44     if (arrFile != null)
45       for(int i=0; i<arrFile.length; i++)
46       {
47         File JavaDoc objFile = arrFile[i];
48         boolean bFloppy = objFile.getAbsolutePath().startsWith("A:") || objFile.getAbsolutePath().startsWith("B:");
49         if(!bFloppy)
50             m_vDrives.addElement(new Drive(this, objFile));
51       }
52   }
53
54   public Vector JavaDoc getDrives()
55   {
56     if(m_vDrives == null){
57         initDrives();
58     }
59     return m_vDrives;
60   }
61   public int getChildNumber(Object JavaDoc objChild)
62   {
63     for(int i=0;i<m_vDrives.size();i++)
64     {
65       Object JavaDoc objChildDrive = m_vDrives.elementAt(i);
66       if(objChildDrive.equals(objChild))
67       {
68         return i;
69       }
70     }
71     return -1;
72   }
73     /**
74      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#containsChild(ITreeNode)
75      */

76     public boolean containsChild(ITreeNode node) {
77         return true;
78     }
79
80     /**
81      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getAllowsChildren()
82      */

83     public boolean getAllowsChildren() {
84         return true;
85     }
86
87     /**
88      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildCount()
89      */

90     public int getChildCount() {
91         return getDrives().size();
92     }
93
94     /**
95      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getChildren()
96      */

97     public Collection JavaDoc getChildren() {
98         return getDrives();
99     }
100
101     /**
102      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#getParent()
103      */

104     public ITreeNode getParent() {
105         return null;
106     }
107
108     /**
109      * @see org.apache.tapestry.contrib.tree.model.ITreeNode#isLeaf()
110      */

111     public boolean isLeaf() {
112         return false;
113     }
114
115     /**
116      * @see java.lang.Object#toString()
117      */

118     public String JavaDoc toString() {
119         return getName();
120     }
121     public String JavaDoc getName(){
122         return "FileSystem";
123     }
124     
125     /**
126      * @see java.lang.Object#equals(Object)
127      */

128     public boolean equals(Object JavaDoc arg0) {
129         if(!(arg0 instanceof FileSystem))
130             return false;
131         FileSystem objFileSystem = (FileSystem)arg0;
132         if(getName().equals(objFileSystem.getName()))
133             return true;
134         return false;
135     }
136
137     /**
138      * @see java.lang.Object#hashCode()
139      */

140     public int hashCode() {
141         return getName().hashCode();
142     }
143
144     /**
145      * @see org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode#getAbsolutePath()
146      */

147     public String JavaDoc getAbsolutePath() {
148         return "";
149     }
150
151     /**
152      * @see org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode#getAssets()
153      */

154     public AssetsHolder getAssets() {
155         if(m_objAssetsHolder == null){
156             m_objAssetsHolder = new AssetsHolder("/org/apache/tapestry/workbench/tree/examples/fsmodel/computer.gif", "/org/apache/tapestry/workbench/tree/examples/fsmodel/computer.gif");
157         }
158         return m_objAssetsHolder;
159     }
160
161     /**
162      * @see org.apache.tapestry.workbench.tree.examples.fsmodel.IFileSystemTreeNode#getObjectDate()
163      */

164     public Date JavaDoc getDate() {
165         return null;
166     }
167
168 }
169
Popular Tags