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 |
|
---|
27 | package org.greenstone.gatherer.file;
|
---|
28 |
|
---|
29 | import java.io.File;
|
---|
30 | import java.util.Enumeration;
|
---|
31 | import javax.swing.tree.TreePath;
|
---|
32 | import org.greenstone.gatherer.Configuration;
|
---|
33 | import org.greenstone.gatherer.DebugStream;
|
---|
34 | import org.greenstone.gatherer.Gatherer;
|
---|
35 | import org.greenstone.gatherer.gui.tree.DragTree;
|
---|
36 |
|
---|
37 |
|
---|
38 | public class WorkspaceTree
|
---|
39 | extends DragTree
|
---|
40 | {
|
---|
41 | static public final int LIBRARY_CONTENTS_CHANGED = 10;
|
---|
42 | static public final int DOWNLOADED_FILES_CHANGED = 11;
|
---|
43 | static public final int FOLDER_SHORTCUTS_CHANGED = 12;
|
---|
44 |
|
---|
45 |
|
---|
46 | public WorkspaceTree(String name)
|
---|
47 | {
|
---|
48 | super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), true);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | public void addDirectoryMapping(String name, File file)
|
---|
53 | {
|
---|
54 | // Update the information stored in the user's configuration
|
---|
55 | Configuration.addDirectoryMapping(name, file);
|
---|
56 |
|
---|
57 | // Now update the tree
|
---|
58 | refresh(FOLDER_SHORTCUTS_CHANGED);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | public void refresh(int refresh_reason)
|
---|
63 | {
|
---|
64 | DebugStream.println("WorkspaceTree::refresh()... ");
|
---|
65 |
|
---|
66 | // The method for displaying the tree has changed - redraw the tree
|
---|
67 | if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) {
|
---|
68 | DebugStream.println("...Reason: tree display changed.");
|
---|
69 | updateUI();
|
---|
70 | }
|
---|
71 |
|
---|
72 | // The loaded collection has changed - currently do nothing
|
---|
73 | if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
|
---|
74 | DebugStream.println("...Reason: loaded collection changed.");
|
---|
75 | }
|
---|
76 |
|
---|
77 | // The collection's contents have changed - refresh collection's import folder
|
---|
78 | if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
|
---|
79 | DebugStream.println("...Reason: collection contents changed.");
|
---|
80 | String collection_import_directory_path = Gatherer.c_man.getCollectionImportDirectoryPath();
|
---|
81 | refreshEveryNodeShowingFolder(collection_import_directory_path);
|
---|
82 | }
|
---|
83 |
|
---|
84 | // The collections in the library have changed - refresh the collect directory
|
---|
85 | if (refresh_reason == WorkspaceTree.LIBRARY_CONTENTS_CHANGED) {
|
---|
86 | DebugStream.println("...Reason: library contents changed.");
|
---|
87 | String collect_directory_path = Gatherer.getCollectDirectoryPath();
|
---|
88 | refreshEveryNodeShowingFolder(collect_directory_path);
|
---|
89 | WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
|
---|
90 | }
|
---|
91 |
|
---|
92 | // The downloaded files have changed - refresh that node
|
---|
93 | if (refresh_reason == WorkspaceTree.DOWNLOADED_FILES_CHANGED) {
|
---|
94 | DebugStream.println("...Reason: downloaded files changed.");
|
---|
95 | WorkspaceTreeModel.refreshDownloadedFilesNode();
|
---|
96 | }
|
---|
97 |
|
---|
98 | // The folder shortcuts have changed - refresh only them
|
---|
99 | if (refresh_reason == WorkspaceTree.FOLDER_SHORTCUTS_CHANGED) {
|
---|
100 | DebugStream.println("...Reason: folder shortcuts changed.");
|
---|
101 | WorkspaceTreeModel.refreshFolderShortcuts();
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | private void refreshEveryNodeShowingFolder(String folder_path_str)
|
---|
107 | {
|
---|
108 | // Search through the expanded tree paths, checking if any show the given folder
|
---|
109 | TreePath tree_root_path = new TreePath(getModel().getRoot());
|
---|
110 | Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
|
---|
111 | while (expanded_tree_paths.hasMoreElements()) {
|
---|
112 | TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
|
---|
113 | WorkspaceTreeNode tree_node = (WorkspaceTreeNode) expanded_tree_path.getLastPathComponent();
|
---|
114 |
|
---|
115 | File tree_node_file = tree_node.getFile();
|
---|
116 | if (tree_node_file == null) {
|
---|
117 | continue;
|
---|
118 | }
|
---|
119 |
|
---|
120 | // Get the path of the open tree node
|
---|
121 | String tree_node_path_str = tree_node_file.toString();
|
---|
122 | if (!tree_node_path_str.endsWith(File.separator)) {
|
---|
123 | tree_node_path_str = tree_node_path_str + File.separator;
|
---|
124 | }
|
---|
125 |
|
---|
126 | // If the specified folder is open, it must be refreshed
|
---|
127 | if (tree_node_path_str.equals(folder_path_str)) {
|
---|
128 | System.err.println("Must refresh node " + tree_node_path_str + "!");
|
---|
129 | ((WorkspaceTreeModel) getModel()).refresh(expanded_tree_path);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 |
|
---|
135 | public void removeDirectoryMapping(WorkspaceTreeNode target)
|
---|
136 | {
|
---|
137 | // Update the information stored in the user's configuration
|
---|
138 | Configuration.removeDirectoryMapping(target.toString());
|
---|
139 |
|
---|
140 | // Update tree
|
---|
141 | refresh(FOLDER_SHORTCUTS_CHANGED);
|
---|
142 | }
|
---|
143 | }
|
---|