package org.greenstone.gatherer.file; import org.greenstone.gatherer.collection.CollectionManager; import org.greenstone.gatherer.file.FileNode; import org.greenstone.gatherer.gui.MirrorPane; import org.greenstone.gatherer.util.SynchronizedTreeModelTools; public class WorkspaceTreeModel extends FileSystemModel { static private FileNode workspace_tree_root = null; static private WorkspaceTreeModel workspace_tree_model = null; static private FileNode greenstone_collections_mapping = null; static private FileNode web_cache_mapping = null; static private FileNode[] collection_specific_mappings = null; public WorkspaceTreeModel(FileNode root) { super(root); } static public WorkspaceTreeModel getWorkspaceTreeModel() { // Create a root node to contain the various nodes in the workspace tree workspace_tree_root = new FileNode("ABS_ROOT"); workspace_tree_model = new WorkspaceTreeModel(workspace_tree_root); // Add the Greenstone Collections mapping greenstone_collections_mapping = CollectionManager.getGreenstoneCollectionsMapping(); workspace_tree_root.insert(greenstone_collections_mapping); // Add the local filespace workspace_tree_root.insert(FileSystem.getLocalFileSystem(workspace_tree_model)); // Add a mapping to the user home folder workspace_tree_root.insert(FileSystem.getUserHomeMapping()); // Add public and private web caches if applicable loadWebCacheMappings(); // Add any collection specific mappings loadCollectionSpecificMappings(); return workspace_tree_model; } static private void loadWebCacheMappings() { // If mirroring is enabled show the public and private caches web_cache_mapping = MirrorPane.getWebCacheMapping(); if (web_cache_mapping != null) { workspace_tree_root.insert(web_cache_mapping); } } static private void loadCollectionSpecificMappings() { ///ystem.err.print("Load Collection Specific Mappings... "); // Add the current collection specific mappings collection_specific_mappings = CollectionManager.getCollectionSpecificMappings(); ///ystem.err.print("Retrieved Mappings... "); if (collection_specific_mappings != null) { for (int i = 0; i < collection_specific_mappings.length; i++) { ///ystem.err.print("Setting " + i + " Mapping... "); SynchronizedTreeModelTools.insertNodeInto(workspace_tree_model, workspace_tree_root, collection_specific_mappings[i], false); } } ///ystem.err.println("Done."); } // !! NEEDS WORK !! static public void refreshGreenstoneCollectionsMapping() { greenstone_collections_mapping.unmap(); greenstone_collections_mapping.map(); } // !! NEEDS WORK !! static public void refreshWebCacheMappings() { if (web_cache_mapping != null) { SynchronizedTreeModelTools.removeNodeFromParent(workspace_tree_model, web_cache_mapping); } loadWebCacheMappings(); } // !! NEEDS WORK !! static public void refreshCollectionSpecificMappings() { // Remove all the old collection specific mappings if (collection_specific_mappings != null) { for (int i = 0; i < collection_specific_mappings.length; i++) { SynchronizedTreeModelTools.removeNodeFromParent(workspace_tree_model, collection_specific_mappings[i]); } } loadCollectionSpecificMappings(); } }