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

Last change on this file since 6901 was 5898, checked in by mdewsnip, 21 years ago

A quick and ugly hack to assign a model to the root drives under Windows. I'll tidy this up when I get the chance.

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