/** *############################################################################ * A component of the Greenstone Librarian Interface, part of the Greenstone * digital library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ * * Copyright (C) 2004 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *############################################################################ */ package org.greenstone.gatherer.file; import java.io.File; import java.util.Enumeration; import javax.swing.tree.TreePath; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.DebugStream; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.gui.tree.DragTree; public class WorkspaceTree extends DragTree { static public final int LIBRARY_CONTENTS_CHANGED = 10; static public final int DOWNLOADED_FILES_CHANGED = 11; static public final int FOLDER_SHORTCUTS_CHANGED = 12; public WorkspaceTree(String name) { super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), true); } public void addDirectoryMapping(String name, File file) { // Update the information stored in the user's configuration Configuration.addDirectoryMapping(name, file); // Now update the tree refresh(FOLDER_SHORTCUTS_CHANGED); } public void refresh(int refresh_reason) { DebugStream.println("WorkspaceTree::refresh()... "); // The method for displaying the tree has changed - redraw the tree if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) { DebugStream.println("...Reason: tree display changed."); updateUI(); } // The loaded collection has changed - currently do nothing if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) { DebugStream.println("...Reason: loaded collection changed."); } // The collection's contents have changed - refresh collection's import folder if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) { DebugStream.println("...Reason: collection contents changed."); String collection_import_directory_path = Gatherer.c_man.getCollectionImportDirectoryPath(); refreshEveryNodeShowingFolder(collection_import_directory_path); } // The collections in the library have changed - refresh the collect directory if (refresh_reason == WorkspaceTree.LIBRARY_CONTENTS_CHANGED) { DebugStream.println("...Reason: library contents changed."); String collect_directory_path = Gatherer.getCollectDirectoryPath(); refreshEveryNodeShowingFolder(collect_directory_path); WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); } // The downloaded files have changed - refresh that node if (refresh_reason == WorkspaceTree.DOWNLOADED_FILES_CHANGED) { DebugStream.println("...Reason: downloaded files changed."); WorkspaceTreeModel.refreshDownloadedFilesNode(); } // The folder shortcuts have changed - refresh only them if (refresh_reason == WorkspaceTree.FOLDER_SHORTCUTS_CHANGED) { DebugStream.println("...Reason: folder shortcuts changed."); WorkspaceTreeModel.refreshFolderShortcuts(); } } private void refreshEveryNodeShowingFolder(String folder_path_str) { // Search through the expanded tree paths, checking if any show the given folder TreePath tree_root_path = new TreePath(getModel().getRoot()); Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path); while (expanded_tree_paths.hasMoreElements()) { TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement(); WorkspaceTreeNode tree_node = (WorkspaceTreeNode) expanded_tree_path.getLastPathComponent(); File tree_node_file = tree_node.getFile(); if (tree_node_file == null) { continue; } // Get the path of the open tree node String tree_node_path_str = tree_node_file.toString(); if (!tree_node_path_str.endsWith(File.separator)) { tree_node_path_str = tree_node_path_str + File.separator; } // If the specified folder is open, it must be refreshed if (tree_node_path_str.equals(folder_path_str)) { System.err.println("Must refresh node " + tree_node_path_str + "!"); ((WorkspaceTreeModel) getModel()).refresh(expanded_tree_path); } } } public void removeDirectoryMapping(WorkspaceTreeNode target) { // Update the information stored in the user's configuration Configuration.removeDirectoryMapping(target.toString()); // Update tree refresh(FOLDER_SHORTCUTS_CHANGED); } }