Changeset 5854


Ignore:
Timestamp:
2003-11-16T17:50:12+13:00 (20 years ago)
Author:
mdewsnip
Message:

More improvements to smart workspace tree refreshing. Library contents changes (eg. deleting collections) now refreshes the collect directory nicely.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r5847 r5854  
    10821082        }
    10831083    }
    1084     }
    1085 
    1086     /** Refresh the Greenstone Collections special mapping in the workspace tree to account for collections being added/removed
    1087      */
    1088     public void refreshGreenstoneCollections()
    1089     {
    1090     Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.COLLECTION_CHANGED);
    1091 
    1092     /* FileNode root = (FileNode) workspace_model.getRoot();
    1093     FileNode greenstone_collections_node = null;
    1094     int root_child_count = root.getChildCount();
    1095     String greenstone_collections_str = Dictionary.get("Tree.World");
    1096     for(int i = 0; greenstone_collections_node == null && i < root_child_count; i++) {
    1097         TreeNode child = root.getChildAt(i);
    1098         if(child.toString().equals(greenstone_collections_str)) {
    1099         greenstone_collections_node = (FileNode) child;
    1100         }
    1101         child = null;
    1102     }
    1103     greenstone_collections_str = null;
    1104     root = null;
    1105     if(greenstone_collections_node != null) {
    1106         TreePath greenstone_collections_path = new TreePath(greenstone_collections_node.getPath());
    1107         workspace_model.refresh(greenstone_collections_path);
    1108         greenstone_collections_path = null;
    1109         greenstone_collections_node = null;
    1110         } */
    11111084    }
    11121085
  • trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java

    r5724 r5854  
    4747import org.greenstone.gatherer.gui.ModalDialog;
    4848import org.greenstone.gatherer.gui.SimpleMenuBar;
     49import org.greenstone.gatherer.gui.tree.DragTree;
    4950import org.greenstone.gatherer.util.ArrayTools;
    5051import org.greenstone.gatherer.util.GSDLSiteConfig;
     
    244245     */
    245246    public void actionPerformed(ActionEvent event) {
    246         // Ask the collection manager to refresh the 'Greenstone Collections' folder
    247         Gatherer.c_man.refreshGreenstoneCollections();
    248247        // Done
    249248        prompt.dispose();
     
    312311        File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator);
    313312        if(Utility.delete(delete_me)) {
    314         if (Gatherer.c_man.getCollection()!=null && collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
     313        if (Gatherer.c_man.getCollection() != null && collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
    315314            current_coll_deleted = true;
    316315        }
     316        list_model.removeElement(collection);
     317
     318        // Refresh the collects shown in the workspace tree
     319        Gatherer.g_man.collection_pane.refreshWorkspaceTree(DragTree.LIBRARY_CONTENTS_CHANGED);
    317320
    318321        resultPrompt(true);
    319         list_model.removeElement(collection);
    320322        Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
    321323        confirmation.setEnabled(false);
  • trunk/gli/src/org/greenstone/gatherer/file/FileNode.java

    r5785 r5854  
    275275            files = tools.filter(files, filters[i].filter, filters[i].exclude);
    276276            }
    277             //}
    278             // If this node just happens to be the greenstone collection directory
    279             if(Gatherer.c_man != null && Gatherer.c_man.ready() && file.equals(new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)))) {
    280             // Preclude the directory of any open collection
    281             String collection_name = Gatherer.c_man.getCollection().getName();
    282             for(int j = 0; j < files.length; j++) {
    283                 ///ystem.err.println("Does " + files[j].getName() + " equal " + collection_name + "?");
    284                 if(files[j].getName().equals(collection_name)) {
    285                 // Remove the offending directory
    286                 files = ArrayTools.remove(files, j);
    287                 }
    288             }
    289             }
     277            //}
     278//              // If this node just happens to be the greenstone collection directory
     279//              if(Gatherer.c_man != null && Gatherer.c_man.ready() && file.equals(new File(Utility.getCollectionDir(Gatherer.config.gsdl_path)))) {
     280//              // Preclude the directory of any open collection
     281//              String collection_name = Gatherer.c_man.getCollection().getName();
     282//              for(int j = 0; j < files.length; j++) {
     283//                  ///ystem.err.println("Does " + files[j].getName() + " equal " + collection_name + "?");
     284//                  if(files[j].getName().equals(collection_name)) {
     285//                  // Remove the offending directory
     286//                  files = ArrayTools.remove(files, j);
     287//                  }
     288//              }
     289//              }
    290290            // Finally remove any files whose canonical path do not match their absolute one (ie symbolic links). We only do this test under linux, because under windows there is no such thing as a symbolic link, and instead we suffer difficulties with the 16bit truncated file paths not being the same as the canonical ones (i.e Program Files => Progra~1).
    291291            /* This test to eliminate infinite recursions causes more problems than it solves
  • trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTreeModel.java

    r5847 r5854  
    1111    static private FileNode workspace_tree_root = null;
    1212    static private WorkspaceTreeModel workspace_tree_model = null;
     13    static private FileNode greenstone_collections_mapping = null;
    1314    static private FileNode[] collection_specific_mappings = null;
    1415
     
    2728
    2829    // Add the Greenstone Collections mapping
    29     workspace_tree_root.insert(CollectionManager.getGreenstoneCollectionsMapping());
     30    greenstone_collections_mapping = CollectionManager.getGreenstoneCollectionsMapping();
     31    workspace_tree_root.insert(greenstone_collections_mapping);
    3032
    3133    // Add the local filespace
     
    6163
    6264
     65    static public void refreshGreenstoneCollectionsMapping()
     66    {
     67    greenstone_collections_mapping.unmap();
     68    greenstone_collections_mapping.map();
     69    }
     70
     71
    6372    static public void refreshCollectionSpecificMappings()
    6473    {
  • trunk/gli/src/org/greenstone/gatherer/gui/CollectionPane.java

    r5847 r5854  
    244244    collection_tree_sync.add(collection_tree);
    245245
    246     refreshWorkspaceTree(DragTree.COLLECTION_CHANGED);
    247     refreshCollectionTree(DragTree.COLLECTION_CHANGED);
     246    refreshWorkspaceTree(DragTree.LOADED_COLLECTION_CHANGED);
     247    refreshCollectionTree(DragTree.LOADED_COLLECTION_CHANGED);
    248248
    249249    // Enable or disable the control buttons
     
    504504    workspace_tree.refresh(refresh_reason);
    505505    }
    506 
    507 
    508     /* public void refreshWorkspace() {
    509     System.err.println("CollectionPane::refreshWorkspace()... (ignored)");
    510     // workspace = Gatherer.c_man.getWorkspace();
    511     // workspace_tree.setModel(workspace);
    512     // workspace_tree_sync.add(workspace_tree);
    513     } */
    514506
    515507
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/DragTree.java

    r5847 r5854  
    5454    static private final int AUTOSCROLL_MARGIN = 12;
    5555
    56     static public int COLLECTION_CHANGED          = 1;
     56    static public int LIBRARY_CONTENTS_CHANGED    = 0;
     57    static public int LOADED_COLLECTION_CHANGED   = 1;
    5758    static public int COLLECTION_CONTENTS_CHANGED = 2;
    5859    static public int TREE_DISPLAY_CHANGED        = 3;
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/WorkspaceTree.java

    r5847 r5854  
    2525    System.err.print("WorkspaceTree::refresh()... ");
    2626
    27     // A collection has been opened/closed - reload the workspace tree model
    28     if (refresh_reason == DragTree.COLLECTION_CHANGED) {
    29         System.err.println("Reason: collection changed.");
     27    // The collections in the library have changed - refresh the collect directory
     28    if (refresh_reason == DragTree.LIBRARY_CONTENTS_CHANGED) {
     29        System.err.println("Reason: library contents changed.");
     30        String collect_directory_str = Gatherer.config.gsdl_path + Utility.COL_DIR;
     31        refreshEveryNodeShowingFolder(collect_directory_str);
     32        WorkspaceTreeModel.refreshGreenstoneCollectionsMapping();
     33    }
     34
     35    // A collection has been opened/closed - reload the whole shebang
     36    if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
     37        System.err.println("Reason: loaded collection changed.");
    3038        setModel(WorkspaceTreeModel.getWorkspaceTreeModel());
    3139    }
    3240
    33     // The collection's contents have changed - refresh expanded parts of the collection
     41    // The collection's contents have changed - refresh collection's import folder
    3442    if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
    3543        System.err.println("Reason: collection contents changed.");
    36 
    3744        String import_directory_str = Gatherer.c_man.getCollectionImport();
    38 
    39         TreePath tree_root_path = new TreePath(getModel().getRoot());
    40         Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
    41         while (expanded_tree_paths.hasMoreElements()) {
    42         TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
    43         FileNode tree_node = (FileNode) expanded_tree_path.getLastPathComponent();
    44 
    45         File tree_node_file = tree_node.getFile();
    46         if (tree_node_file == null) {
    47             continue;
    48         }
    49 
    50         // Get the path of the open tree node
    51         String tree_node_path_str = tree_node_file.toString();
    52         if (!tree_node_path_str.endsWith(File.separator)) {
    53             tree_node_path_str = tree_node_path_str + File.separator;
    54         }
    55 
    56         // If the collection import directory is open, it must be refreshed
    57         if (tree_node_path_str.equals(import_directory_str)) {
    58             System.err.println("Must refresh collection import directory!");
    59             ((FileSystemModel) getModel()).refresh(expanded_tree_path);
    60         }
    61         }
     45        refreshEveryNodeShowingFolder(import_directory_str);
    6246    }
    6347
     
    7458    }
    7559    }
     60
     61
     62    private void refreshEveryNodeShowingFolder(String folder_path_str)
     63    {
     64    // Search through the expanded tree paths, checking if any show the given folder
     65    TreePath tree_root_path = new TreePath(getModel().getRoot());
     66    Enumeration expanded_tree_paths = getExpandedDescendants(tree_root_path);
     67    while (expanded_tree_paths.hasMoreElements()) {
     68        TreePath expanded_tree_path = (TreePath) expanded_tree_paths.nextElement();
     69        FileNode tree_node = (FileNode) expanded_tree_path.getLastPathComponent();
     70
     71        File tree_node_file = tree_node.getFile();
     72        if (tree_node_file == null) {
     73        continue;
     74        }
     75
     76        // Get the path of the open tree node
     77        String tree_node_path_str = tree_node_file.toString();
     78        if (!tree_node_path_str.endsWith(File.separator)) {
     79        tree_node_path_str = tree_node_path_str + File.separator;
     80        }
     81
     82        // If the collection import directory is open, it must be refreshed
     83        if (tree_node_path_str.equals(folder_path_str)) {
     84        System.err.println("Must refresh node " + tree_node_path_str + "!");
     85        ((FileSystemModel) getModel()).refresh(expanded_tree_path);
     86        }
     87    }
     88    }
    7689}
Note: See TracChangeset for help on using the changeset viewer.