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

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

Some function and variable name changes, and added the web cache/downloaded files mapping back in.

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