source: trunk/gli/src/org/greenstone/gatherer/gui/tree/WorkspaceTree.java@ 6086

Last change on this file since 6086 was 6086, checked in by jmt12, 20 years ago

Moved the special folder 'shortcuts' from collection based to shared for the installation of gli. This caused some added fun when it turned out one of the workspace tree refreshes was blocking the AWTEvent thread, despite me putting tests in place to stop that from happening. It had never reared its ugly head before, as there were never any shortcut collections being mapped when a collection had been closed, or when GLI was exiting before.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1package org.greenstone.gatherer.gui.tree;
2
3import java.io.File;
4import java.util.Enumeration;
5import javax.swing.tree.TreePath;
6import org.greenstone.gatherer.Gatherer;
7import org.greenstone.gatherer.file.FileNode;
8import org.greenstone.gatherer.file.FileSystemModel;
9import org.greenstone.gatherer.file.WorkspaceTreeModel;
10import org.greenstone.gatherer.util.Utility;
11
12
13public class WorkspaceTree
14 extends DragTree {
15
16 static public int MAPPED_DIRECTORIES_CHANGED = 11;
17
18
19 public WorkspaceTree(String name) {
20 super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), null, true);
21 }
22
23
24 public void refresh(int refresh_reason) {
25 Gatherer.println("WorkspaceTree::refresh()... ");
26
27 // The collections in the library have changed - refresh the collect directory
28 if (refresh_reason == DragTree.LIBRARY_CONTENTS_CHANGED) {
29 Gatherer.println("...Reason: library contents changed.");
30 String collect_directory_str = Gatherer.config.gsdl_path + Utility.COL_DIR;
31 refreshEveryNodeShowingFolder(collect_directory_str);
32 WorkspaceTreeModel.refreshGreenstoneCollectionsMapping();
33 }
34
35 // A collection has been opened/closed - reload the whole shebang
36 if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
37 Gatherer.println("...Reason: loaded collection changed.");
38 setModel(WorkspaceTreeModel.getWorkspaceTreeModel());
39 }
40
41 // The collection's contents have changed - refresh collection's import folder
42 if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
43 Gatherer.println("...Reason: collection contents changed.");
44 String import_directory_str = Gatherer.c_man.getCollectionImport();
45 refreshEveryNodeShowingFolder(import_directory_str);
46 }
47
48 // The method for displaying the tree has changed - redraw the tree
49 if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) {
50 Gatherer.println("...Reason: tree display changed.");
51 updateUI();
52 }
53
54 // The collection specific mapped directories have changed - refresh only them
55 if (refresh_reason == WorkspaceTree.MAPPED_DIRECTORIES_CHANGED) {
56 Gatherer.println("...Reason: mapped directories changed.");
57 WorkspaceTreeModel.refreshWebCacheMappings();
58 WorkspaceTreeModel.refreshCollectionSpecificMappings();
59 updateUI();
60 }
61 }
62
63
64 private void refreshEveryNodeShowingFolder(String folder_path_str)
65 {
66 // Search through the expanded tree paths, checking if any show the given folder
67 TreePath tree_root_path = new TreePath(getModel().getRoot());
68 Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
69 while (expanded_tree_paths.hasMoreElements()) {
70 TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
71 FileNode tree_node = (FileNode) expanded_tree_path.getLastPathComponent();
72
73 File tree_node_file = tree_node.getFile();
74 if (tree_node_file == null) {
75 continue;
76 }
77
78 // Get the path of the open tree node
79 String tree_node_path_str = tree_node_file.toString();
80 if (!tree_node_path_str.endsWith(File.separator)) {
81 tree_node_path_str = tree_node_path_str + File.separator;
82 }
83
84 // If the collection import directory is open, it must be refreshed
85 if (tree_node_path_str.equals(folder_path_str)) {
86 System.err.println("Must refresh node " + tree_node_path_str + "!");
87 ((FileSystemModel) getModel()).refresh(expanded_tree_path);
88 }
89 }
90 }
91}
Note: See TracBrowser for help on using the repository browser.