package org.greenstone.gatherer.gui.tree; import java.io.File; import java.util.Enumeration; import javax.swing.tree.TreePath; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.file.FileNode; import org.greenstone.gatherer.file.WorkspaceTreeModel; import org.greenstone.gatherer.util.Utility; public class WorkspaceTree extends DragTree { static public int LIBRARY_CONTENTS_CHANGED = 10; static public int FOLDER_SHORTCUTS_CHANGED = 11; public WorkspaceTree(String name) { super(name, WorkspaceTreeModel.getWorkspaceTreeModel(), null, true); } public void refresh(int refresh_reason) { Gatherer.println("WorkspaceTree::refresh()... "); // The method for displaying the tree has changed - redraw the tree if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) { Gatherer.println("...Reason: tree display changed."); updateUI(); } // The loaded collection has changed - currently do nothing if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) { Gatherer.println("...Reason: loaded collection changed."); } // The collection's contents have changed - refresh collection's import folder if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) { Gatherer.println("...Reason: collection contents changed."); String import_directory_str = Gatherer.c_man.getCollectionImport(); refreshEveryNodeShowingFolder(import_directory_str); } // The collections in the library have changed - refresh the collect directory if (refresh_reason == WorkspaceTree.LIBRARY_CONTENTS_CHANGED) { Gatherer.println("...Reason: library contents changed."); String collect_directory_str = Gatherer.config.gsdl_path + Utility.COL_DIR; refreshEveryNodeShowingFolder(collect_directory_str); WorkspaceTreeModel.refreshGreenstoneCollectionsNode(); } // The folder shortcuts have changed - refresh only them if (refresh_reason == WorkspaceTree.FOLDER_SHORTCUTS_CHANGED) { Gatherer.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(); FileNode tree_node = (FileNode) 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); } } } }