Changeset 34205


Ignore:
Timestamp:
2020-06-18T00:06:23+12:00 (4 years ago)
Author:
ak19
Message:

Collection ConfigFileEditor related changes, bugfixes and improvements: 1. In investigating why clientGLI > Edit > collectionConfig.xml > Save button didn't save and get reflected in the interface, found that regular GLI had the same problem. A simple all to c_man.saveCollection() fixed it for GLI, apparently should do so for client-GLI too but still to test. 2. A larger change is to make sure edits in GLI that affect collCfg.xml get saved to collCfg.xml before Edit > collCfg.xml loads the config file. This includes user values entered in controls being edited in the currently selected GLI pane. GLI code gave me a massive run-around to figure how its magic auto-save feature was working but I think I've figured it out now: It's that in GLI Panes which affect colCfg.xml (like Format pane), the loseFocus() on a GLI Pane triggers loseFocus() on GUI controls in that Pane (e.g. Format Pane's General field controls). These controls then save their current values to the collConfig in memory. Then an explicit call to c_man.saveCollection() happens. So just calling c_man.saveCollection before an Edit > collCfg.xml operation won't save the active edits in the current controls of the selected GLI Pane. Based on this understanding, I've forced a loseFocus() on the current pane, to force it to save the current state of its controls, before GLI loads the CollConfigEditor. It works. 3. ConfigFileEditor in GLI (and therefore hopefully in client-GLI too) no longer closes and reopens the collection on saving colcfg edits. This was a quick fix in the past to the problem of getting GLI to immediately reflect changes made to the currently open collection's colcfg.xml file. With the fixes in (1) and (2) this commit is able make a useful improvement to this behaviour, as the changes in this commit avoid having to close and reopen a collection after saving changes in CollConfigEditor, while aiming for the same effect of getting the interface to immediately reflect the edits. Great gains could especially be had with client-GLI, assuming this commit works for it too, as the close then reloading collection operation can take such a long time with client-GLI. Fingers crossed.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
5 edited

Legend:

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

    r24824 r34205  
    6767    // This method is initilised in CollectionDesignManager.java constructor
    6868    public CollectionConfiguration(File collect_config_file)
    69     {
     69    {       
     70        load(collect_config_file);
     71    }
     72
     73    private void load(File collect_config_file) {
    7074        this.collect_config_file = collect_config_file;
    7175        this.collect_config_filename = collect_config_file.getName();
     
    8488
    8589        //XMLTools.printXMLNode(document.getDocumentElement());
     90    }
     91
     92
     93    public void reload() {
     94        load(this.collect_config_file);
    8695    }
    8796
  • main/trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java

    r32704 r34205  
    120120    }
    121121
     122
     123    public void reloadConfig() {
     124    // Parse and load the current collection configuration again
     125    // Used after GLI > Edit > collectionConfig.xml > Save to get these edits into GLI.
     126   
     127    collect_config.reload();
     128    if (DebugStream.isDebuggingEnabled()) {
     129        collect_config.display();
     130    }
     131    loadDesignDetails();
     132    DebugStream.println("CollectionDesignModule loaded.");
     133    }
     134
    122135    /** Reloads the various managers to ensure they have built themselves from the latest details available in the collection configuration class
    123136     * @see org.greenstone.gatherer.cdm.ClassifierManager
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r34168 r34205  
    13031303    }
    13041304
    1305 
     1305   
     1306    public void reloadAfterConfigFileEdited() {
     1307    // Copying just the part of LoadCollectionInternal below that loads the config file
     1308    // Need to reload the *existing* config file, however. So calling custom method reloadConfig()
     1309   
     1310    // Don't see why this stuff here (vs LoadCollectionInternal) would need to happen in its own
     1311    // Thread for my use: when the modal Edit > collectionConfig.xml dialog has saved and closed.
     1312   
     1313    // reload current collection's config
     1314    collection.cdm.reloadConfig();
     1315
     1316    // We're done. Let everyone know.
     1317    DebugStream.println(Dictionary.get("CollectionManager.Loading_Successful", collection.getName()));
     1318    Gatherer.refresh(Gatherer.COLLECTION_OPENED);
     1319    }
     1320   
    13061321    public void loadCollection(String collection_file_path)
    13071322    {
  • main/trunk/gli/src/org/greenstone/gatherer/gui/ConfigFileEditor.java

    r32093 r34205  
    8080    String collection_folder_path = Gatherer.getCollectDirectoryPath();
    8181    String collectionName  = Gatherer.c_man.getCollection().getName(); // we won't be in this constructor if collection is null.
     82
     83    // Gatherer.c_man.saveCollection(); // on Edit > collectionConfig.xml menu click,
     84    // collection save has already happened as GLI pane.lostFocus() got called on current GLI Pane
     85    // if/where this affects collectionConfig.xml. For an explanation, see GUIManager.java,
     86    // look for "if(esrc == menu_bar.edit_config)"
     87
    8288    this.config_file = new File(collection_folder_path + File.separator + collectionName, Utility.CONFIG_GS3_FILE); // col config editing is a GS3 feature
    8389
     
    201207    // Final dialog setup & positioning.
    202208    setDefaultCloseOperation(DISPOSE_ON_CLOSE); // get rid of this dialog when it's closed (on dispose())
     209    this.addWindowListener(new WindowAdapter() { // called on dispose. Return focus to any curr GLI Pane
     210        public void windowClose(WindowEvent we) {
     211            Gatherer.g_man.doRegainFocus();
     212        }
     213        });
     214   
     215
     216   
    203217    getRootPane().setDefaultButton(save_button);
    204218    Dimension screen_size = Configuration.screen_size;
     
    234248        // close and reopen the collection in GLI
    235249        String current_collection_filepath = Gatherer.c_man.getCollection().getCollectionPath();
    236         Gatherer.c_man.closeCollection();
    237         Gatherer.c_man.loadCollection(current_collection_filepath);
     250        ////Gatherer.c_man.closeCollection(); // explicit save was necessary after all
     251                                              // closeCollection() doesn't auto-save
     252        ////Gatherer.c_man.loadCollection(current_collection_filepath);
     253
     254       
     255        // Fixing bug: Edit > colcfg wasn't being saved on Save when client-GLI.
     256        // And in fact, it wasn't properly saving in GLI for some GLI panes.
     257        // That's because save needs to be explicitly called. (Didn't understand how GLI's
     258        // "autosave" worked until now. GLI > File > Close a collection saves it, but underneath
     259        // it calles SAVEandCloseCollection.
     260       
     261        // Works - but arduous: have to load in the entire collection just because cfg changed?
     262        // Especial pain with client-GLI where reloading takes forever.
     263        //Gatherer.g_man.saveThenCloseCurrentCollection();
     264        //Gatherer.c_man.loadCollection(current_collection_filepath);
     265
     266        // Better way: don't have to close and reopen the entire collection after editing colCfg.xml
     267        // This just updates GLI's interface with the current collCfg.xml.
     268        // Fingers crossed this works for client-GLI, because then the coll won't need to be closed
     269        // and reopened each time after Edit > collectionCfg.xml gets saved.
     270        Gatherer.c_man.saveCollection(); // should save colcfg whether GLI or client-GLI
     271        Gatherer.c_man.reloadAfterConfigFileEdited();
     272        //Gatherer.g_man.updateUI(); // didn't do what I hoped it would, so is this relevant here?
     273                     // It's done when a new collection is loaded, so may be useful?
     274                     // But all my tests concerning GLI > Edit > collConfig.xml worked out without it
     275       
    238276    }
    239277   
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r32923 r34205  
    148148    }
    149149
    150 
     150   
    151151    public void windowLostFocus(WindowEvent e)
    152152    {
     
    266266    else if(esrc == menu_bar.edit_config) {   
    267267        if(Gatherer.c_man.getCollection() != null) {
    268 
     268        // Before we open the current collection's collectionConfig.xml for editing,
     269        // need to make sure any presently unsaved edits are saved into collConfig
     270        // so they are reflected in this config file when loaded into the editor for editing.
     271        // A simple Gatherer.c_man.saveCollection() is not sufficient: it won't save ongoing
     272        // edits in the currently selected GLI Pane (where relevant to colcfg)
     273       
     274        // Whenever a user swaps from one GLI pane to another, loseFocus() is called on the pane
     275        // and for some GLI Panes, this triggers a collection save, but notably also triggers a
     276        // loseFocus() on the pane's editing fields/controls, which saves any ongoing mods in that
     277        // pane to the collectionConfiguration file.
     278        // - See loseFocus() of BaseConfigPane.java (that only SOME gli Pane's inherit from)
     279        // and also apparent in GUIManager.windowLostFocus().
     280        // - And for implementations of Control.loseFocus(), see for example via
     281        // CollectionManager.loadDesignDetails() -> GeneralManager (for Format > General tab)
     282        // which leads to GeneralManager.loseFocus() which gets "Called to store the current
     283        // value of the components" - of its Controls. Exactly the behaviour we want!
     284       
     285        // Not all GLI Panes inherit from BaseConfigPane, but then, not all GLI Panes
     286        // make changes to the collection Config file; e.g. the Gather pane makes changes to
     287        // the file system, Enrich makes changes to metadata.xml files and *.mds metadata sets
     288        // files. But Design and Format panes make changes to collectionConfig.xml.
     289        // In theory Create pane ought to as well, e.g. can set import options which also exists
     290        // as ImportOptions in collectionConfig.xml, but they're not linked (yet) and Create pane
     291        // doesn't inherit from BaseConfigPane. CreatePane's loseFocus() also don't call
     292        // for the the collection to be saved.
     293
     294        // What all this means is that when we prepare to open the collectionConfig.xml,
     295        // we want a collection save but want also the current state of GLI edits to be saved
     296        // into collConfig before we display the collConfig file for editing.
     297        // To trigger this behaviour we want to call loseFocus() on the current pane, called
     298        // "previous_pane". That method may or may not force a save to collConfig,
     299        // depending on whether it is warranted for that pane, but in such cases it will also
     300        // cascade the loseFocus() call to the controls in that pane, who will save their current
     301        // values into the colcfg in memory before this gets saved to the colCfg.xml file. 
     302       
     303        if(previous_pane != null) {
     304            doLoseFocus();
     305        }
     306        //Gatherer.c_man.saveCollection(); //shouldn't have to do this, in theory. See above comment
     307       
    269308        ConfigFileEditor configEditor = new ConfigFileEditor();
    270309        configEditor.setVisible(true);
     
    10351074    }
    10361075
    1037 
     1076    // Want to triger loseFocus() on GLI Panes at will when Menu > Edit > collectionConfig.xml clicked.
     1077    // And when done editing, want to trigger doRegainFocs().
     1078    // loseFocus() on GLI Panes is not universally inherited from a common base class
     1079    // But loseFocus() is important as it forces saves as-is of user entered values in gui fields
     1080    // When alling doLoseFocus() on GLI > Edit > collConfig.xml, we force a save of the current state
     1081    // of the current pane (called "previous_pane").
     1082    // Else a save is only triggered when another GLI Pane is clicked. We can't expect a user to
     1083    // remember to click other panes whenever they want to edit the collConfig.xml.   
     1084    private void doLoseFocus() {
     1085   
     1086    if (previous_pane != null) {
     1087        if (previous_pane == gather_pane) {
     1088        gather_pane.loseFocus();
     1089        }
     1090        else if (previous_pane == enrich_pane) {
     1091        enrich_pane.loseFocus();
     1092        }
     1093        else if (previous_pane == design_pane) {
     1094        design_pane.loseFocus();
     1095        }
     1096        else if (previous_pane == create_pane) {
     1097        create_pane.loseFocus();
     1098        }
     1099        else if (previous_pane == format_pane) {
     1100        format_pane.loseFocus();
     1101        }
     1102    }
     1103    }
     1104    public void doRegainFocus() {
     1105   
     1106    if (previous_pane != null) {
     1107        if (previous_pane == gather_pane) {
     1108        gather_pane.gainFocus();
     1109        }
     1110        else if (previous_pane == enrich_pane) {
     1111        enrich_pane.gainFocus();
     1112        }
     1113        else if (previous_pane == design_pane) {
     1114        design_pane.gainFocus();
     1115        }
     1116        else if (previous_pane == create_pane) {
     1117        create_pane.gainFocus();
     1118        }
     1119        else if (previous_pane == format_pane) {
     1120        format_pane.gainFocus();
     1121        }
     1122    }
     1123    }
     1124   
    10381125    /** Any implementation of ChangeListener must include this method so we can be informed when the state of one of the registered objects changes. In this case we are listening to view changes within the tabbed pane.
    10391126     * @param event A ChangeEvent containing information about the event that fired this call.
Note: See TracChangeset for help on using the changeset viewer.