Ignore:
Timestamp:
2010-09-01T16:20:27+12:00 (14 years ago)
Author:
ak19
Message:

For ticket 152 (moveable collectdir): busy cursor when changing a collectdir takes some time to finish.

File:
1 edited

Legend:

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

    r22806 r22831  
    821821
    822822
    823     public static void collectDirectoryHasChanged(String oldCollectPath, String newCollectPath) {
    824     if(oldCollectPath.equals(newCollectPath)) {
    825         return; // nothing to be done
    826     }
    827 
    828     // first save any open collection in the old location, then close it
    829     if(Gatherer.c_man.getCollection() != null) {
    830         Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
    831     }
    832    
    833     // change to new collect path
    834     Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
    835                 true, newCollectPath);
    836     Gatherer.setCollectDirectoryPath(newCollectPath);
    837    
    838 
    839     // refresh the Documents in Greenstone Collections
    840     //WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
    841     Gatherer.g_man.refreshWorkspaceTreeGreenstoneCollections();
    842    
    843     // The web server needs to be told where a new (non-standard) collecthome home is.
    844     // The web server reads collecthome from cgi-bin/gsdlsite.cfg, where the property
    845     // collecthome can be specified if a non-standard collecthome is to be used. If no
    846     // such property is specified in the file, then it assumes the standard GS collecthome.
    847     // This method does nothing for a remote Greenstone.   
    848     if(Gatherer.isGsdlRemote) {
    849         return;
    850     }   
    851 
    852     String gsdlsitecfg = "";
    853     if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
    854         gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"
    855             + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    856     } else { // cgi-bin/gsdlsite.cfg
    857         gsdlsitecfg = Configuration.gsdl_path + File.separator
    858             + "cgi-bin" + File.separator + "gsdlsite.cfg";
    859     }
    860 
    861     // non-destructive update of gsdl(3)site.cfg (comments preserved)
    862     String collectDir = Gatherer.getCollectDirectoryPath();
    863     //collectDir = "\"" + collectDir.substring(0, collectDir.length()-1) + "\""; // remove file separator at end   
    864     collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end   
    865     Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir);
    866 
    867     if(!Gatherer.GS3 && Gatherer.isLocalLibrary) {
    868         // for Images in the collection to work, the apache web server
    869         // configuration's COLLECTHOME should be updated on collectdir change.
    870         // Does nothing for server.exe at the moment
    871 
    872         LocalLibraryServer.reconfigure();
    873     }
     823    public static void collectDirectoryHasChanged(
     824        String oldCollectPath, String newCollectPath, final Component container)
     825    {
     826        // Will use a busy cursor if the process of changing the collect directory takes more
     827        // than half a second/500ms. See http://www.catalysoft.com/articles/busyCursor.html
     828        Cursor originalCursor = container.getCursor();
     829        java.util.TimerTask timerTask = new java.util.TimerTask() {
     830            public void run() {
     831                // set the cursor on the container:
     832                container.setCursor(new Cursor(Cursor.WAIT_CURSOR));
     833            }
     834        };
     835        java.util.Timer timer = new java.util.Timer();
     836       
     837        try {
     838            timer.schedule(timerTask, 500);
     839       
     840            if(oldCollectPath.equals(newCollectPath)) {
     841                return; // nothing to be done
     842            }
     843
     844            // first save any open collection in the old location, then close it
     845            if(Gatherer.c_man.getCollection() != null) {
     846                Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
     847            }
     848           
     849            // change to new collect path
     850            Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     851                        true, newCollectPath);
     852            Gatherer.setCollectDirectoryPath(newCollectPath);
     853           
     854
     855            // refresh the Documents in Greenstone Collections
     856            //WorkspaceTreeModel.refreshGreenstoneCollectionsNode();
     857            Gatherer.g_man.refreshWorkspaceTreeGreenstoneCollections();
     858           
     859            // The web server needs to be told where a new (non-standard) collecthome home is.
     860            // The web server reads collecthome from cgi-bin/gsdlsite.cfg, where the property
     861            // collecthome can be specified if a non-standard collecthome is to be used. If no
     862            // such property is specified in the file, then it assumes the standard GS collecthome.
     863            // This method does nothing for a remote Greenstone.   
     864            if(Gatherer.isGsdlRemote) {
     865                return;
     866            }   
     867
     868            String gsdlsitecfg = "";
     869            if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
     870                gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"
     871                    + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     872            } else { // cgi-bin/gsdlsite.cfg
     873                gsdlsitecfg = Configuration.gsdl_path + File.separator
     874                    + "cgi-bin" + File.separator + "gsdlsite.cfg";
     875            }
     876
     877            // non-destructive update of gsdl(3)site.cfg (comments preserved)
     878            String collectDir = Gatherer.getCollectDirectoryPath();
     879            //collectDir = "\"" + collectDir.substring(0, collectDir.length()-1) + "\""; // remove file separator at end   
     880            collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end   
     881            Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir);
     882
     883            if(!Gatherer.GS3 && Gatherer.isLocalLibrary) {
     884                // for Images in the collection to work, the apache web server
     885                // configuration's COLLECTHOME should be updated on collectdir change.
     886                // Does nothing for server.exe at the moment
     887
     888                LocalLibraryServer.reconfigure();
     889            }
     890        } finally { // Note try-finally section without catch:
     891            // "Java's finally clause is guaranteed to be executed even when
     892            // an exception is thrown and not caught in the current scope."
     893            // See http://www.catalysoft.com/articles/busyCursor.html
     894            // the following code fragment is guaranteed to restore the original
     895            // cursor now the custom actionPerformed() processing is complete, regardless
     896            // of whether the processing method terminates normally or throws an exception
     897            // and regardedless of where in the call stack the exception is caught.         
     898           
     899            timer.cancel();
     900            container.setCursor(originalCursor);
     901        }
    874902    }
    875903
Note: See TracChangeset for help on using the changeset viewer.