Changeset 5847


Ignore:
Timestamp:
2003-11-14T15:03:33+13:00 (20 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
Files:
3 added
9 edited

Legend:

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

    r5785 r5847  
    254254     * @see org.greenstone.gatherer.util.GURL
    255255     */
    256     public void newJob(TreeModel model, boolean overwrite, boolean no_parents, boolean other_hosts, boolean page_requisites, URL url, int depth, String destination) {
     256    public void newJob(/* TreeModel model, */ boolean overwrite, boolean no_parents, boolean other_hosts, boolean page_requisites, URL url, int depth, String destination) {
    257257    // Create the job and fill in the details from gatherer.config.
    258258    Gatherer.println("About to create a new job");
     
    261261        destination = destination + url.getHost();
    262262    }
    263     Job new_job = new Job(model, overwrite, Gatherer.config.get("mirroring.debug", false), no_parents, other_hosts, page_requisites, Gatherer.config.get("mirroring.quiet", false), url, depth, destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple);
     263    Job new_job = new Job(/* model, */ overwrite, Gatherer.config.get("mirroring.debug", false), no_parents, other_hosts, page_requisites, Gatherer.config.get("mirroring.quiet", false), url, depth, destination, Gatherer.config.proxy_pass, Gatherer.config.proxy_user, this, simple);
    264264    // Add to job_queue job list.
    265265    job_queue.add(new_job);
  • 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;
  • trunk/gli/src/org/greenstone/gatherer/file/FileQueue.java

    r5833 r5847  
    596596            // Force the trees to refresh (but only if there is something on screen!)
    597597            if(Gatherer.g_man != null) {
    598                 Gatherer.g_man.refreshTrees();
     598                Gatherer.g_man.refreshTrees(DragTree.COLLECTION_CONTENTS_CHANGED);
    599599            }
    600600            // Reset status area
  • trunk/gli/src/org/greenstone/gatherer/gui/CollectionPane.java

    r5773 r5847  
    5353import org.greenstone.gatherer.gui.GComboBox;
    5454import org.greenstone.gatherer.gui.tree.DragTree;
     55import org.greenstone.gatherer.gui.tree.WorkspaceTree;
    5556import org.greenstone.gatherer.undo.UndoManager;
    5657import org.greenstone.gatherer.util.DragComponent;
     
    7172    private DragTree collection_tree         =  null;
    7273    /** The tree showing the available source workspace. */
    73     private DragTree workspace_tree          =  null;
     74    private WorkspaceTree workspace_tree     =  null;
    7475    /** The threaded queue that handles the actually movement of files, so that the gui remains responsive. */
    7576    private FileQueue file_queue          =  null;
     
    243244    collection_tree_sync.add(collection_tree);
    244245
    245     refreshWorkspace();
     246    refreshWorkspaceTree(DragTree.COLLECTION_CHANGED);
     247    refreshCollectionTree(DragTree.COLLECTION_CHANGED);
    246248
    247249    // Enable or disable the control buttons
     
    250252    new_folder.setEnabled(ready);
    251253    }
     254
    252255    /** Generates the pane on controls used to 'collect' files into the collection. Resposible for creating, connecting and laying out these controls. */
    253256    public void display() {
     
    269272    Dictionary.registerText(workspace_label, "Collection.Workspace");
    270273
    271     workspace = Gatherer.c_man.getWorkspace();
    272     workspace_tree = new DragTree(Utility.WORKSPACE_TREE, workspace, null, true);
     274    workspace_tree = new WorkspaceTree(Utility.WORKSPACE_TREE);
    273275    group.add(workspace_tree);
    274276    workspace_tree.addFocusListener(this);
     
    491493    }
    492494
    493     public DragTree getWorkspaceTree() {
    494     return workspace_tree;
    495     }
    496 
    497     public void refreshTrees() {
     495
     496    public void refreshCollectionTree(int refresh_reason)
     497    {
    498498    collection_tree.refresh(null);
    499     workspace_tree.refresh(null);
    500     }
    501 
    502     public void refreshWorkspace() {
    503     workspace = Gatherer.c_man.getWorkspace();
    504     workspace_tree.setModel(workspace);
    505     workspace_tree_sync.add(workspace_tree);
    506     }
     499    }
     500
     501
     502    public void refreshWorkspaceTree(int refresh_reason)
     503    {
     504    workspace_tree.refresh(refresh_reason);
     505    }
     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    } */
    507514
    508515
  • trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r5842 r5847  
    7272import org.greenstone.gatherer.gui.metaaudit.MetaAuditFrame;
    7373import org.greenstone.gatherer.gui.tree.DragTree;
     74import org.greenstone.gatherer.gui.tree.WorkspaceTree;
    7475import org.greenstone.gatherer.help.HelpFrame;
    7576import org.greenstone.gatherer.msm.ElementWrapper;
     
    359360    create_pane.collectionChanged(ready); // Used to indicate a new BuildOptions model should be loaded.
    360361    preview_pane.collectionChanged(ready); // preview should know when teh coll has changed so it can reload the home page
    361     // Force tree model updates.
    362     Gatherer.c_man.refreshTrees();
     362
    363363    if(!locked) {
    364364                // Now enable tabs as necessary. Do this on event queue to prevent crazy NPEs
     
    533533    }
    534534
    535     public void refreshTrees() {
    536     collection_pane.refreshTrees();
    537     //metaedit_pane.refreshTrees();
     535    public void refreshTrees(int refresh_reason)
     536    {
     537    collection_pane.refreshWorkspaceTree(refresh_reason);
     538    collection_pane.refreshCollectionTree(refresh_reason);
     539    metaedit_pane.refreshTrees();
    538540    }
    539541
     
    580582    // If the rawname was mirror then rebuild workspace tree to remove caches.
    581583    if(rawname.equals("Mirroring")) {
    582         collection_pane.refreshWorkspace();
     584        collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    583585    }
    584586    }
  • trunk/gli/src/org/greenstone/gatherer/gui/MirrorPane.java

    r5593 r5847  
    208208        if(url != null) {
    209209        // Otherwise construct a new download job
    210         getter.newJob(Gatherer.c_man.getWorkspace(), overwrite_checkbox.isSelected(), !higher_checkbox.isSelected(), !same_host_checkbox.isSelected(), automatic_checkbox.isSelected(), url, ((Integer)depth_spinner.getValue()).intValue(), (public_radiobutton.isSelected() ? Utility.CACHE_DIR : Gatherer.c_man.getCollectionCache()));
     210        getter.newJob(/* Gatherer.c_man.getWorkspace(), */ overwrite_checkbox.isSelected(), !higher_checkbox.isSelected(), !same_host_checkbox.isSelected(), automatic_checkbox.isSelected(), url, ((Integer)depth_spinner.getValue()).intValue(), (public_radiobutton.isSelected() ? Utility.CACHE_DIR : Gatherer.c_man.getCollectionCache()));
    211211        }
    212212    }
  • trunk/gli/src/org/greenstone/gatherer/gui/Preferences.java

    r5715 r5847  
    1515import org.greenstone.gatherer.gui.ModalDialog;
    1616import org.greenstone.gatherer.gui.SimpleMenuBar;
     17import org.greenstone.gatherer.gui.tree.DragTree;
    1718import org.greenstone.gatherer.util.StaticStrings;
    1819import org.greenstone.gatherer.util.Utility;
     
    428429        // General preferences
    429430        Gatherer.config.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, show_file_size_checkbox.isSelected());
    430         Gatherer.g_man.collection_pane.refreshTrees();
    431         Gatherer.g_man.metaedit_pane.refreshTrees();
     431        Gatherer.g_man.refreshTrees(DragTree.TREE_DISPLAY_CHANGED);
    432432
    433433        Gatherer.config.set("general.view_extracted_metadata", Configuration.COLLECTION_SPECIFIC, view_extracted_metadata_checkbox.isSelected());
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/DragTree.java

    r5593 r5847  
    5454    static private final int AUTOSCROLL_MARGIN = 12;
    5555
     56    static public int COLLECTION_CHANGED          = 1;
     57    static public int COLLECTION_CONTENTS_CHANGED = 2;
     58    static public int TREE_DISPLAY_CHANGED        = 3;
     59
     60
    5661    public DragTree(String name, String background_name, boolean mixed_selection) {
    5762    super();
     
    452457
    453458    public void refresh(TreePath path) {
    454     ((FileSystemModel)treeModel).refresh(path);
     459    if (treeModel instanceof FileSystemModel) {
     460        ((FileSystemModel)treeModel).refresh(path);
     461    }
     462    else {
     463        // System.err.println("DragTree::refresh - Tree model is " + treeModel);
     464    }
    455465    }
    456466
Note: See TracChangeset for help on using the changeset viewer.