source: trunk/gli/src/org/greenstone/gatherer/file/FileSystem.java@ 5860

Last change on this file since 5860 was 5847, checked in by mdewsnip, 21 years ago

A much improved workspace tree that only refreshes when it really needs to (and only refreshes what it really needs to). This should prevent the five second plus refreshes on slow machines.

I'm planning to tidy up the collection tree in a similar way, when I get time.

  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1package org.greenstone.gatherer.file;
2
3import java.io.File;
4import javax.swing.filechooser.FileSystemView;
5import org.greenstone.gatherer.Dictionary;
6import org.greenstone.gatherer.file.FileNode;
7import org.greenstone.gatherer.util.ArrayTools;
8
9
10public class FileSystem
11{
12 static public FileNode getLocalFileSystem()
13 {
14 FileNode file_system_root = null;
15
16 // Get all the available roots mounted on the filesystem
17 File[] roots = File.listRoots();
18 if (roots == null) {
19 return null;
20 }
21
22 // If there is just one root use it as the tree root (Linux)
23 if (roots.length == 1) {
24 file_system_root = new FileNode(roots[0], Dictionary.get("Tree.Root"));
25 }
26
27 // Otherwise build a dummy node which has the roots as children
28 else {
29 file_system_root = new FileNode(Dictionary.get("Tree.Root"));
30
31 // Sort the roots into alphabetical order
32 ArrayTools.sort(roots);
33 for (int i = 0; i < roots.length; i++) {
34 // Only add root if it isn't a floppy drive
35 if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
36 file_system_root.insert(new FileNode(roots[i]));
37 }
38 }
39 }
40
41 return file_system_root;
42 }
43
44
45 static public FileNode getUserHomeMapping()
46 {
47 // Generate a special mapping to the user home folder
48 String home_folder_str = System.getProperty("user.home");
49 if (home_folder_str == null || home_folder_str.length() == 0) {
50 return null;
51 }
52
53 File home_folder = new File(home_folder_str);
54 String[] args = new String[1];
55 args[0] = home_folder.getName();
56 return new FileNode(home_folder, Dictionary.get("Tree.Home", args));
57 }
58}
Note: See TracBrowser for help on using the repository browser.