Ignore:
Timestamp:
2003-11-14T15:03:33+13:00 (21 years ago)
Author:
mdewsnip
Message:

A much improved workspace tree that only refreshes when it really needs to (and only refreshes what it really needs to). This should prevent the five second plus refreshes on slow machines.

I'm planning to tidy up the collection tree in a similar way, when I get time.

Location:
trunk/gli/src/org/greenstone/gatherer/collection
Files:
2 edited

Legend:

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

    r5836 r5847  
    5555import org.greenstone.gatherer.gui.ExternalCollectionPrompt;
    5656import org.greenstone.gatherer.gui.NewMetaSetPrompt;
     57import org.greenstone.gatherer.gui.tree.WorkspaceTree;
    5758import org.greenstone.gatherer.msm.ElementWrapper;
    5859import org.greenstone.gatherer.msm.GDMManager;
     
    9293    private boolean importing = false;
    9394    /** The collection this manager is managing! */
    94     private Collection collection = null;
     95    static private Collection collection = null;
    9596    /** The collection_model. */
    9697    private FileSystemModel collection_model = null;
    9798    /** The workspace model. This becomes invalid on a collection change. */
    98     private FileSystemModel workspace_model = null;
     99    // private FileSystemModel workspace_model = null;
    99100    /** An inner class listener responsible for noting tree changes and resetting saved when they occur. */
    100101    private FMTreeModelListener fm_tree_model_listener = null;
     
    137138        collection.addDirectoryMapping(name, file);
    138139        // Now update the tree
    139         FileSystemModel model = (FileSystemModel) Gatherer.g_man.collection_pane.getWorkspaceTree().getModel();
    140         FileNode parent = (FileNode) model.getRoot();
    141         FileNode target = new FileNode(file, name);
    142         SynchronizedTreeModelTools.insertNodeInto(model, parent, target);
     140        Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    143141    }
    144142    }
     
    207205    collection = null;
    208206    collection_model = null;
    209     workspace_model = null;
     207    // workspace_model = null;
    210208    undo.clear();
    211209    Gatherer.config.setCollectionConfiguration(null);
     
    420418    // Done.
    421419    if(Gatherer.g_man != null) {
    422         workspace_model = null;
     420        // workspace_model = null;
    423421        // set the view to Gather pane
    424422        Gatherer.g_man.setSelectedView(Gatherer.g_man.collection_pane);
     
    611609    return collection_model;
    612610    }
    613     /** Create and return the model behind the workspace tree. Quite an extensive method, as it must first map known greenstone collections, then the local file system and finally any public or private download workspaces. */
    614     public TreeModel getWorkspace() {
    615     ///ystem.err.println("Get Workspace");
    616     if(workspace_model != null) {
    617         return workspace_model;
    618     }
    619     // Determine the local collection directory if any
    620     String current_collection_directory = null;
    621     if(collection != null) {
    622         current_collection_directory = Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName();
    623     }
    624     // Create the workspace tree.
    625     FileNode workspace_root = new FileNode("ABS_ROOT");
    626     workspace_model = new FileSystemModel(workspace_root);
    627     // Create and add Greenstone collections node.
    628     // Starting at the collection directory of gsdl...
    629     FileNode world_root = new FileNode(Dictionary.get("Tree.World"));
    630     world_root.unmap();
    631     workspace_root.insert(world_root);
    632     // Create Local File space.
    633     // Get all the available roots mounted on the system.
    634     File roots[] = File.listRoots();
    635     // If there is just one root use it as the tree root (linux)
    636     if(roots != null) {
    637         FileNode file_root;
    638         String name = Dictionary.get("Tree.Root");
    639         if(roots.length == 1) {
    640         file_root = new FileNode(roots[0], name);
    641         workspace_root.insert(file_root);
    642         }
    643         // Otherwise build a dummy node which has these nodes as children.
    644         else {
    645         file_root = new FileNode(name);
    646         workspace_root.insert(file_root);
    647         // Hopefully this does an alphabetic sort.
    648         ArrayTools.sort(roots);
    649         for(int i = 0; i < roots.length; i++) {
    650            // Only add root if it isn't a floppy drive.
    651            if(!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
    652               FileNode child_root = new FileNode(roots[i]);
    653               file_root.insert(child_root);
    654               child_root = null;
    655            }
    656         }
    657         }
    658         name = null;
    659         file_root = null;
    660     }
    661    
    662     // Now if we can determine user home folder information, generate a 'special mapping' to it
    663     String home_folder_str = System.getProperty("user.home");
    664     if(home_folder_str != null && home_folder_str.length() > 0) {
    665         File home_folder = new File(home_folder_str);
    666         String[] args = new String[1];
    667         args[0] = home_folder.getName();
    668         FileNode home_folder_node = new FileNode(home_folder, Dictionary.get("Tree.Home", args));
    669         workspace_root.insert(home_folder_node);
    670     }
    671 
    672     // If mirroring is enabled show the public and private caches.
    673     if(Gatherer.config.get("workflow.mirror", false)) {
    674         // Add Public workspace
    675         FileNode public_root = new FileNode(new File(Utility.CACHE_DIR), Dictionary.get("Tree.Public"));
    676         workspace_root.insert(public_root);
    677         // Add Private workspace if a collection has been loaded.
    678         if(ready()) {
    679         FileNode private_root = new FileNode(new File(getCollectionCache()), Dictionary.get("Tree.Private"));
    680         workspace_root.insert(private_root);
    681         }
    682     }
    683     // Finally we retrieve and map any predefined special directories.
    684     if(ready()) {
    685         HashMap mappings = collection.getDirectoryMappings();
    686         for(Iterator names = mappings.keySet().iterator(); names.hasNext(); ) {
    687         String name = (String) names.next();
    688         File file = (File) mappings.get(name);
    689         FileNode special_root = new FileNode(file, name);
    690         //workspace_root.insert(special_root);
    691         SynchronizedTreeModelTools.insertNodeInto(workspace_model, workspace_root, special_root);
    692         }
    693     }
    694     ///ystem.err.println("Returning for getWorkspace()");
    695     return workspace_model;
    696     }
     611
     612
     613    static public FileNode getGreenstoneCollectionsMapping()
     614    {
     615    FileNode greenstone_collections_node = new FileNode(Dictionary.get("Tree.World"));
     616    greenstone_collections_node.unmap();
     617    return greenstone_collections_node;
     618    }
     619
     620
     621    static public FileNode[] getCollectionSpecificMappings()
     622    {
     623    if (!ready()) {
     624        return null;
     625    }
     626
     627    // Return any predefined special directories
     628    HashMap mappings = collection.getDirectoryMappings();
     629    FileNode[] mapping_nodes = new FileNode[mappings.size()];
     630    Iterator mappings_iterator = mappings.keySet().iterator();
     631    for (int i = 0; mappings_iterator.hasNext(); i++) {
     632        String mapping_name = (String) mappings_iterator.next();
     633        File mapping_file = (File) mappings.get(mapping_name);
     634        mapping_nodes[i] = new FileNode(mapping_file, mapping_name);
     635    }
     636
     637    return mapping_nodes;
     638    }
     639
     640
    697641    /** This method when called, creates a new GShell in order to run the import.pl script.
    698642     * @see org.greenstone.gatherer.Configuration
     
    855799        // We're done. Let everyone know.
    856800        if(Gatherer.g_man != null) {
    857         workspace_model = null;
     801        // workspace_model = null;
    858802        Gatherer.g_man.collectionChanged(ready());
    859803        }
     
    10971041        //}
    10981042        // Signal collection changed.
    1099         workspace_model = null;
     1043        // workspace_model = null;
    11001044        Gatherer.g_man.collectionChanged(ready());
    11011045        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.INFORMATION_MESSAGE);
     
    11091053     * @return A <i>boolean</i> which is <i>true</i> to indicate a collection has been loaded and thus the collection is ready for editing, <i>false</i> otherwise.
    11101054     */
    1111     public synchronized boolean ready() {
     1055    static public synchronized boolean ready() {
    11121056    if(collection != null) {
    11131057        return true;
     
    11421086    /** Refresh the Greenstone Collections special mapping in the workspace tree to account for collections being added/removed
    11431087     */
    1144     public void refreshGreenstoneCollections() {
    1145     FileNode root = (FileNode) workspace_model.getRoot();
     1088    public void refreshGreenstoneCollections()
     1089    {
     1090    Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.COLLECTION_CHANGED);
     1091
     1092    /* FileNode root = (FileNode) workspace_model.getRoot();
    11461093    FileNode greenstone_collections_node = null;
    11471094    int root_child_count = root.getChildCount();
     
    11611108        greenstone_collections_path = null;
    11621109        greenstone_collections_node = null;
    1163     }
    1164     }
    1165 
    1166     /** Called to refresh the models upon which the trees are based.
    1167      * @see org.greenstone.gatherer.collection.Collection
    1168      */
    1169     public void refreshTrees() {
    1170     }
     1110        } */
     1111    }
     1112
    11711113    /** This method associates the collection build monitor with the build monitor created in CreatePane.
    11721114     * @param monitor A <strong>GShellProgressMonitor</strong> which we will use as the build monitor.
     
    11971139        file = collection.removeDirectoryMapping(target.toString());
    11981140        // Update tree.
    1199         FileSystemModel model = (FileSystemModel) Gatherer.g_man.collection_pane.getWorkspaceTree().getModel();
    1200         SynchronizedTreeModelTools.removeNodeFromParent(model, target);
     1141        Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    12011142    }
    12021143    return file;
  • trunk/gli/src/org/greenstone/gatherer/collection/Job.java

    r5785 r5847  
    6868    private GURL url = null;
    6969
    70     private TreeModel model;
     70    // private TreeModel model;
    7171
    7272    private int depth;
     
    9191    /**
    9292     */
    93     public Job(TreeModel model, boolean clobber, boolean debug, boolean no_parents, boolean other_hosts, boolean page_requisites, boolean quiet, URL initial, int depth, String destination, String proxy_pass, String proxy_user, WGet mummy, boolean simple) {
    94     this.model = model;
     93    public Job(/* TreeModel model, */ boolean clobber, boolean debug, boolean no_parents, boolean other_hosts, boolean page_requisites, boolean quiet, URL initial, int depth, String destination, String proxy_pass, String proxy_user, WGet mummy, boolean simple) {
     94    // this.model = model;
    9595
    9696    this.debug = debug;
Note: See TracChangeset for help on using the changeset viewer.