1 | package org.greenstone.gatherer.gui.tree;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.util.Enumeration;
|
---|
5 | import javax.swing.tree.TreePath;
|
---|
6 | import org.greenstone.gatherer.Configuration;
|
---|
7 | import org.greenstone.gatherer.DebugStream;
|
---|
8 | import org.greenstone.gatherer.Gatherer;
|
---|
9 | import org.greenstone.gatherer.file.FileNode;
|
---|
10 | import org.greenstone.gatherer.file.WorkspaceTreeModel;
|
---|
11 | import org.greenstone.gatherer.util.Utility;
|
---|
12 |
|
---|
13 |
|
---|
14 | public class WorkspaceTree
|
---|
15 | extends DragTree {
|
---|
16 |
|
---|
17 | static public final int LIBRARY_CONTENTS_CHANGED = 10;
|
---|
18 | static public final int DOWNLOADED_FILES_CHANGED = 11;
|
---|
19 | static public final int FOLDER_SHORTCUTS_CHANGED = 12;
|
---|
20 |
|
---|
21 |
|
---|
22 | public WorkspaceTree(String name)
|
---|
23 | {
|
---|
24 | super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), null, true);
|
---|
25 | }
|
---|
26 |
|
---|
27 |
|
---|
28 | public void refresh(int refresh_reason)
|
---|
29 | {
|
---|
30 | DebugStream.println("WorkspaceTree::refresh()... ");
|
---|
31 |
|
---|
32 | // The method for displaying the tree has changed - redraw the tree
|
---|
33 | if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) {
|
---|
34 | DebugStream.println("...Reason: tree display changed.");
|
---|
35 | updateUI();
|
---|
36 | }
|
---|
37 |
|
---|
38 | // The loaded collection has changed - currently do nothing
|
---|
39 | if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
|
---|
40 | DebugStream.println("...Reason: loaded collection changed.");
|
---|
41 | }
|
---|
42 |
|
---|
43 | // The collection's contents have changed - refresh collection's import folder
|
---|
44 | if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
|
---|
45 | DebugStream.println("...Reason: collection contents changed.");
|
---|
46 | String import_directory_str = Gatherer.c_man.getCollectionImport();
|
---|
47 | refreshEveryNodeShowingFolder(import_directory_str);
|
---|
48 | }
|
---|
49 |
|
---|
50 | // The collections in the library have changed - refresh the collect directory
|
---|
51 | if (refresh_reason == WorkspaceTree.LIBRARY_CONTENTS_CHANGED) {
|
---|
52 | DebugStream.println("...Reason: library contents changed.");
|
---|
53 | String collect_directory_str = Configuration.gsdl_path + Utility.COL_DIR;
|
---|
54 | refreshEveryNodeShowingFolder(collect_directory_str);
|
---|
55 | WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
|
---|
56 | }
|
---|
57 |
|
---|
58 | // The downloaded files have changed - refresh that node
|
---|
59 | if (refresh_reason == WorkspaceTree.DOWNLOADED_FILES_CHANGED) {
|
---|
60 | DebugStream.println("...Reason: downloaded files changed.");
|
---|
61 | WorkspaceTreeModel.refreshDownloadedFilesNode();
|
---|
62 | }
|
---|
63 |
|
---|
64 | // The folder shortcuts have changed - refresh only them
|
---|
65 | if (refresh_reason == WorkspaceTree.FOLDER_SHORTCUTS_CHANGED) {
|
---|
66 | DebugStream.println("...Reason: folder shortcuts changed.");
|
---|
67 | WorkspaceTreeModel.refreshFolderShortcuts();
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | private void refreshEveryNodeShowingFolder(String folder_path_str)
|
---|
73 | {
|
---|
74 | // Search through the expanded tree paths, checking if any show the given folder
|
---|
75 | TreePath tree_root_path = new TreePath(getModel().getRoot());
|
---|
76 | Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
|
---|
77 | while (expanded_tree_paths.hasMoreElements()) {
|
---|
78 | TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
|
---|
79 | FileNode tree_node = (FileNode) expanded_tree_path.getLastPathComponent();
|
---|
80 |
|
---|
81 | File tree_node_file = tree_node.getFile();
|
---|
82 | if (tree_node_file == null) {
|
---|
83 | continue;
|
---|
84 | }
|
---|
85 |
|
---|
86 | // Get the path of the open tree node
|
---|
87 | String tree_node_path_str = tree_node_file.toString();
|
---|
88 | if (!tree_node_path_str.endsWith(File.separator)) {
|
---|
89 | tree_node_path_str = tree_node_path_str + File.separator;
|
---|
90 | }
|
---|
91 |
|
---|
92 | // If the specified folder is open, it must be refreshed
|
---|
93 | if (tree_node_path_str.equals(folder_path_str)) {
|
---|
94 | System.err.println("Must refresh node " + tree_node_path_str + "!");
|
---|
95 | ((WorkspaceTreeModel) getModel()).refresh(expanded_tree_path);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|
99 | }
|
---|