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

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

More improvements to workspace tree refreshing... still not perfect though.

  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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 System.err.print("WorkspaceTree::refresh()... ");
26
27 // The collections in the library have changed - refresh the collect directory
28 if (refresh_reason == DragTree.LIBRARY_CONTENTS_CHANGED) {
29 System.err.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 System.err.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 System.err.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 System.err.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 System.err.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.