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

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

Many more improvements to the workspace and collection trees and their refreshing.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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.unmap();
59 greenstone_collections_mapping.map();
60 }
61
62
63 static public void refreshFolderShortcuts()
64 {
65 // Check for new/deleted folder shortcuts
66 FileNode[] old_folder_shortcuts = folder_shortcuts;
67 folder_shortcuts = CollectionManager.getFolderShortcuts();
68
69 // Remove any deleted shortcuts from the tree
70 if (old_folder_shortcuts != null) {
71 for (int i = 0; i < old_folder_shortcuts.length; i++) {
72 if (!doesArrayContain(folder_shortcuts, old_folder_shortcuts[i])) {
73 Gatherer.println("Deleted shortcut: " + old_folder_shortcuts[i]);
74 SynchronizedTreeModelTools.removeNodeFromParent(workspace_tree_model,
75 old_folder_shortcuts[i]);
76 }
77 }
78 }
79
80 // Add any new shortcuts to the tree
81 if (folder_shortcuts != null) {
82 for (int i = 0; i < folder_shortcuts.length; i++) {
83 if (!doesArrayContain(old_folder_shortcuts, folder_shortcuts[i])) {
84 Gatherer.println("Added shortcut: " + folder_shortcuts[i]);
85 SynchronizedTreeModelTools.insertNodeInto(workspace_tree_model, workspace_tree_root, folder_shortcuts[i], false);
86 }
87 }
88 }
89 }
90
91
92 public void refresh(TreePath path)
93 {
94 // If we're not refreshing the whole tree just refresh a certain path
95 if (path != null) {
96 super.refresh(path);
97 }
98
99 // Refresh each of the nodes in the workspace tree
100 for (int i = 0; i < workspace_tree_root.getChildCount(); i++) {
101 FileNode child_node = (FileNode) workspace_tree_root.getChildAt(i);
102 super.refresh(new TreePath(child_node.getPath()));
103 }
104
105 // Refresh the local filespace tree specially (it is not unmapped so not refreshed)
106 for (int i = 0; i < local_filespace_mapping.getChildCount(); i++) {
107 FileNode child_node = (FileNode) local_filespace_mapping.getChildAt(i);
108 super.refresh(new TreePath(child_node.getPath()));
109 }
110 }
111
112
113 static private boolean doesArrayContain(Object[] array, Object item)
114 {
115 if (array == null) {
116 return false;
117 }
118
119 for (int i = 0; i < array.length; i++) {
120 if (item.toString().equals(array[i].toString())) {
121 return true;
122 }
123 }
124
125 return false;
126 }
127}
Note: See TracBrowser for help on using the repository browser.