source: trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTreeModel.java@ 7491

Last change on this file since 7491 was 7491, checked in by mdewsnip, 20 years ago

Even more improvements to the workspace and collection trees. These are now hugely improved -- with refreshing being much quicker and much more reliable.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1package org.greenstone.gatherer.file;
2
3import javax.swing.tree.TreePath;
4import org.greenstone.gatherer.Gatherer;
5import org.greenstone.gatherer.collection.CollectionManager;
6import org.greenstone.gatherer.file.FileNode;
7import org.greenstone.gatherer.gui.MirrorPane;
8import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
9
10
11public class WorkspaceTreeModel
12 extends FileSystemModel {
13
14 static private FileNode workspace_tree_root = null;
15 static private WorkspaceTreeModel workspace_tree_model = null;
16
17 static private FileNode greenstone_collections_mapping = null;
18 static private FileNode local_filespace_mapping = null;
19 // static private FileNode web_cache_mapping = null;
20 static private FileNode[] folder_shortcuts = null;
21
22
23 public WorkspaceTreeModel(FileNode root)
24 {
25 super(root);
26 }
27
28
29 static public WorkspaceTreeModel getWorkspaceTreeModel()
30 {
31 // Create a root node to contain the various nodes in the workspace tree
32 workspace_tree_root = new FileNode("ABS_ROOT");
33 workspace_tree_model = new WorkspaceTreeModel(workspace_tree_root);
34
35 // Add the Greenstone Collections mapping
36 greenstone_collections_mapping = CollectionManager.getGreenstoneCollectionsMapping();
37 workspace_tree_root.insert(greenstone_collections_mapping);
38
39 // Add the local filespace
40 local_filespace_mapping = FileSystem.getLocalFileSystem(workspace_tree_model);
41 workspace_tree_root.insert(local_filespace_mapping);
42
43 // Add a mapping to the user home folder
44 workspace_tree_root.insert(FileSystem.getUserHomeMapping());
45
46 // Add public and private web caches if applicable
47 // loadWebCacheMappings();
48
49 // Add any folder shortcuts the user has created
50 refreshFolderShortcuts();
51
52 return workspace_tree_model;
53 }
54
55
56 static public void refreshGreenstoneCollectionsMapping()
57 {
58 greenstone_collections_mapping.refresh();
59 }
60
61
62 static public void refreshFolderShortcuts()
63 {
64 // Check for new/deleted folder shortcuts
65 FileNode[] old_folder_shortcuts = folder_shortcuts;
66 folder_shortcuts = CollectionManager.getFolderShortcuts();
67
68 // Remove any deleted shortcuts from the tree
69 if (old_folder_shortcuts != null) {
70 for (int i = 0; i < old_folder_shortcuts.length; i++) {
71 if (!doesArrayContain(folder_shortcuts, old_folder_shortcuts[i])) {
72 Gatherer.println("Deleted shortcut: " + old_folder_shortcuts[i]);
73 SynchronizedTreeModelTools.removeNodeFromParent(workspace_tree_model,
74 old_folder_shortcuts[i]);
75 }
76 }
77 }
78
79 // Add any new shortcuts to the tree
80 if (folder_shortcuts != null) {
81 for (int i = 0; i < folder_shortcuts.length; i++) {
82 if (!doesArrayContain(old_folder_shortcuts, folder_shortcuts[i])) {
83 Gatherer.println("Added shortcut: " + folder_shortcuts[i]);
84 SynchronizedTreeModelTools.insertNodeInto(workspace_tree_model, workspace_tree_root, folder_shortcuts[i], false);
85 }
86 }
87 }
88 }
89
90
91 static private boolean doesArrayContain(Object[] array, Object item)
92 {
93 if (array == null) {
94 return false;
95 }
96
97 for (int i = 0; i < array.length; i++) {
98 if (item.toString().equals(array[i].toString())) {
99 return true;
100 }
101 }
102
103 return false;
104 }
105}
Note: See TracBrowser for help on using the repository browser.