source: trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTree.java@ 8783

Last change on this file since 8783 was 8783, checked in by mdewsnip, 19 years ago

Big tidy up of the workspace and collection trees (Gather/Enrich panes). Still a few more changes and bug fixes to come.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2004 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26
27package org.greenstone.gatherer.file;
28
29import java.io.File;
30import java.util.Enumeration;
31import javax.swing.tree.TreePath;
32import org.greenstone.gatherer.Configuration;
33import org.greenstone.gatherer.DebugStream;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.gui.tree.DragTree;
36import org.greenstone.gatherer.util.Utility;
37
38
39public class WorkspaceTree
40 extends DragTree
41{
42 static public final int LIBRARY_CONTENTS_CHANGED = 10;
43 static public final int DOWNLOADED_FILES_CHANGED = 11;
44 static public final int FOLDER_SHORTCUTS_CHANGED = 12;
45
46
47 public WorkspaceTree(String name)
48 {
49 super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), null, true);
50 }
51
52
53 public void addDirectoryMapping(String name, File file)
54 {
55 // Update the information stored in the user's configuration
56 Configuration.addDirectoryMapping(name, file);
57
58 // Now update the tree
59 refresh(FOLDER_SHORTCUTS_CHANGED);
60 }
61
62
63 public void refresh(int refresh_reason)
64 {
65 DebugStream.println("WorkspaceTree::refresh()... ");
66
67 // The method for displaying the tree has changed - redraw the tree
68 if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) {
69 DebugStream.println("...Reason: tree display changed.");
70 updateUI();
71 }
72
73 // The loaded collection has changed - currently do nothing
74 if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
75 DebugStream.println("...Reason: loaded collection changed.");
76 }
77
78 // The collection's contents have changed - refresh collection's import folder
79 if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
80 DebugStream.println("...Reason: collection contents changed.");
81 String import_directory_str = Gatherer.c_man.getCollectionImport();
82 refreshEveryNodeShowingFolder(import_directory_str);
83 }
84
85 // The collections in the library have changed - refresh the collect directory
86 if (refresh_reason == WorkspaceTree.LIBRARY_CONTENTS_CHANGED) {
87 DebugStream.println("...Reason: library contents changed.");
88 String collect_directory_str = Configuration.gsdl_path + Utility.COL_DIR;
89 refreshEveryNodeShowingFolder(collect_directory_str);
90 WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
91 }
92
93 // The downloaded files have changed - refresh that node
94 if (refresh_reason == WorkspaceTree.DOWNLOADED_FILES_CHANGED) {
95 DebugStream.println("...Reason: downloaded files changed.");
96 WorkspaceTreeModel.refreshDownloadedFilesNode();
97 }
98
99 // The folder shortcuts have changed - refresh only them
100 if (refresh_reason == WorkspaceTree.FOLDER_SHORTCUTS_CHANGED) {
101 DebugStream.println("...Reason: folder shortcuts changed.");
102 WorkspaceTreeModel.refreshFolderShortcuts();
103 }
104 }
105
106
107 private void refreshEveryNodeShowingFolder(String folder_path_str)
108 {
109 // Search through the expanded tree paths, checking if any show the given folder
110 TreePath tree_root_path = new TreePath(getModel().getRoot());
111 Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
112 while (expanded_tree_paths.hasMoreElements()) {
113 TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
114 WorkspaceTreeNode tree_node = (WorkspaceTreeNode) expanded_tree_path.getLastPathComponent();
115
116 File tree_node_file = tree_node.getFile();
117 if (tree_node_file == null) {
118 continue;
119 }
120
121 // Get the path of the open tree node
122 String tree_node_path_str = tree_node_file.toString();
123 if (!tree_node_path_str.endsWith(File.separator)) {
124 tree_node_path_str = tree_node_path_str + File.separator;
125 }
126
127 // If the specified folder is open, it must be refreshed
128 if (tree_node_path_str.equals(folder_path_str)) {
129 System.err.println("Must refresh node " + tree_node_path_str + "!");
130 ((WorkspaceTreeModel) getModel()).refresh(expanded_tree_path);
131 }
132 }
133 }
134
135
136 public void removeDirectoryMapping(WorkspaceTreeNode target)
137 {
138 // Update the information stored in the user's configuration
139 Configuration.removeDirectoryMapping(target.toString());
140
141 // Update tree
142 refresh(FOLDER_SHORTCUTS_CHANGED);
143 }
144}
Note: See TracBrowser for help on using the repository browser.