1 | package org.greenstone.gatherer.file;
|
---|
2 |
|
---|
3 | import javax.swing.tree.TreePath;
|
---|
4 | import org.greenstone.gatherer.Gatherer;
|
---|
5 | import org.greenstone.gatherer.collection.CollectionManager;
|
---|
6 | import org.greenstone.gatherer.file.FileNode;
|
---|
7 | import org.greenstone.gatherer.gui.MirrorPane;
|
---|
8 | import org.greenstone.gatherer.util.SynchronizedTreeModelTools;
|
---|
9 |
|
---|
10 |
|
---|
11 | public 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 | // -- This code is necessary to support the workspace tree file filter --
|
---|
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 | return;
|
---|
98 | }
|
---|
99 |
|
---|
100 | // Refresh each of the nodes in the workspace tree
|
---|
101 | for (int i = 0; i < workspace_tree_root.getChildCount(); i++) {
|
---|
102 | FileNode child_node = (FileNode) workspace_tree_root.getChildAt(i);
|
---|
103 | super.refresh(new TreePath(child_node.getPath()));
|
---|
104 | }
|
---|
105 |
|
---|
106 | // Refresh the local filespace tree specially (it is not unmapped so not refreshed)
|
---|
107 | for (int i = 0; i < local_filespace_mapping.getChildCount(); i++) {
|
---|
108 | FileNode child_node = (FileNode) local_filespace_mapping.getChildAt(i);
|
---|
109 | super.refresh(new TreePath(child_node.getPath()));
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | static private boolean doesArrayContain(Object[] array, Object item)
|
---|
115 | {
|
---|
116 | if (array == null) {
|
---|
117 | return false;
|
---|
118 | }
|
---|
119 |
|
---|
120 | for (int i = 0; i < array.length; i++) {
|
---|
121 | if (item.toString().equals(array[i].toString())) {
|
---|
122 | return true;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | return false;
|
---|
127 | }
|
---|
128 | }
|
---|