Ignore:
Timestamp:
2010-10-15T20:33:43+13:00 (14 years ago)
Author:
ak19
Message:

More changes to making collectdir movable: 1. When not working with a remote GS or server.exe: if the collecthome set in GLI is not the same as the one in gsdlsite.cfg used by the apache web server, then a dialog pops up on exiting GLI allowing the user to set the collecthome value for both GLI (in the user's GLI config.xml) and the server (in gsdlsite.cfg). 2. Collecthome line in gsdlsite.cfg is removed if it is the default GS collect folder. (Just as a recent commit stores an empty string for the open_collection element in the GLI config.xml file if no collection is left open on exiting GLI and the collect folder is the default GS collect directory.) 3. Some bug fixes.

File:
1 edited

Legend:

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

    r23031 r23143  
    104104    private TabUpdater tab_updater = null;
    105105
    106 
    107 
    108 
    109 
    110106  final static String newline = "\n";
    111107    final static String space = "    ";
     
    502498    public void exit(int exit_status)
    503499    {
     500    boolean collection_open = false;
    504501    // If we have a collection open remember it for next time, then save it and close it
    505502    if (Gatherer.c_man.ready()) {
     
    515512        }
    516513        saveThenCloseCurrentCollection();
     514        collection_open = true;
    517515    }
    518516    else {
     
    528526        }
    529527    }
     528   
     529   
     530    // Basically, if GLI coldir != gsdlsite_colhome, we ask them if they want to save GLI coldir as gsdlsite_colhome
     531    // If gsdlsite_colhome = "" (meaning default GS coldir) and GLI is also set to defaultGScoldir, no saving necessary.
     532    // We ONLY do this for the local included apache web server, since the issue revolves around gsdlsite.cfg containing
     533    // the global collecthome when using the apache web server. This is not an issue for remote GS or server.exe (the latter
     534    // has separate config files specifying collecthome for when GLI is running whereas when just the server.exe is running).
     535    if(!Gatherer.isGsdlRemote && !Gatherer.isPersistentServer()) {     
     536   
     537        String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(false); // no filesep at end
     538        String gliColDir = Gatherer.getCollectDirectoryPath();
     539        String serverColDir = Gatherer.gsdlsite_collecthome;
     540       
     541        boolean showSettingsDlg = true;
     542        // if collectdir was changed during GLI session (to something different from what's in gsdlsite), need to ask what to store
     543        if(gliColDir.equals(Gatherer.gsdlsite_collecthome+File.separator)) {   
     544            showSettingsDlg = false;
     545        } else if(Gatherer.gsdlsite_collecthome.equals("") // both set to default coldir
     546                && gliColDir.equals(defaultColDir+File.separator)) {
     547            showSettingsDlg = false;
     548        }
     549        if(showSettingsDlg) {
     550           
     551            // else we will be showing the Collect Directory Settings Dialog
     552            if(gliColDir.endsWith(File.separator)) {
     553                gliColDir = gliColDir.substring(0, gliColDir.length()-1);
     554            }
     555           
     556            if(serverColDir.equals("")) {
     557                serverColDir = defaultColDir;
     558            }   
     559            collectDirSettingsDialog(defaultColDir, serverColDir, gliColDir, collection_open);
     560        }
     561    }
    530562
    531563    // Store the current position and size of the GLI for next time
     
    544576    }
    545577
     578    public void collectDirSettingsDialog(final String defaultColDir,
     579        final String from, final String to, final boolean collection_open)
     580    {   
     581        final JDialog colHomeDialog
     582            = new JDialog(this, Dictionary.get("GUI.CollectHome.title"), true); // this = Gatherer.g_man
     583        colHomeDialog.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     584       
     585       
     586        JRadioButton gliYes = new JRadioButton(Dictionary.get("General.Yes"), true);
     587                        // the default selection for GLI, collecthome=to
     588        JRadioButton serverYes = new JRadioButton(Dictionary.get("General.Yes")); // not selected for the server       
     589        JRadioButton gliNo = null;
     590        JRadioButton gliThirdOption = null;
     591        JRadioButton serverNo = null;
     592        JRadioButton serverThirdOption = null;
     593       
     594        if(from.equals(defaultColDir)) {
     595            gliNo = new JRadioButton(Dictionary.get("GUI.CollectHome.resetToDefault"));
     596            serverNo = new JRadioButton(Dictionary.get("GUI.CollectHome.leaveAtDefault"), true);
     597                        // default selection for server, collecthome=from
     598        } else {
     599            gliNo = new JRadioButton(Dictionary.get("General.No"));
     600            serverNo = new JRadioButton(Dictionary.get("General.No"), true); // default selection for server
     601            if(!to.equals(defaultColDir)) { // neither from nor to is the default GS collect dir, so give them that as the third option
     602                gliThirdOption = new JRadioButton(Dictionary.get("GUI.CollectHome.reset"));
     603                serverThirdOption = new JRadioButton(Dictionary.get("GUI.CollectHome.reset"));     
     604            }
     605        }
     606       
     607        JPanel gliPanel = new JPanel(); // flowlayout by default
     608        ButtonGroup gliGroup = new ButtonGroup();
     609        JPanel serverPanel = new JPanel(); // flowlayout by default
     610        ButtonGroup serverGroup = new ButtonGroup();
     611       
     612        gliGroup.add(gliYes);
     613        gliPanel.add(gliYes);
     614        serverGroup.add(serverYes);
     615        serverPanel.add(serverYes);     
     616       
     617        gliGroup.add(gliNo);
     618        gliPanel.add(gliNo);
     619        serverGroup.add(serverNo);
     620        serverPanel.add(serverNo);
     621           
     622        if(gliThirdOption != null) {
     623            gliThirdOption = new JRadioButton("Reset to default");
     624            serverThirdOption = new JRadioButton("Reset to default");
     625           
     626            gliGroup.add(gliThirdOption);
     627            gliPanel.add(gliThirdOption);
     628            serverGroup.add(serverThirdOption);
     629            serverPanel.add(serverThirdOption);
     630        }
     631       
     632        // vars need to be final to use them in the actionlistener below
     633        final JRadioButton gli_yes = gliYes;
     634        final JRadioButton gli_no = gliNo;
     635        final JRadioButton gli_optional = gliThirdOption;
     636        final JRadioButton server_yes = serverYes;
     637        final JRadioButton server_no = serverNo;
     638        final JRadioButton server_optional = serverThirdOption;
     639       
     640        JButton okButton = new JButton(Dictionary.get("General.OK"));
     641        okButton.addActionListener(new ActionListener() {
     642            public void actionPerformed(ActionEvent e) {
     643                // store the option chosen for GLI
     644                String gliColDir = to; 
     645                if(gli_optional != null && gli_optional.isSelected()) {
     646                    // defaultColDir
     647                    gliColDir = "";
     648                } else if(gli_yes.isSelected()) {
     649                    gliColDir = to;
     650                } else if (gli_no.isSelected()) {
     651                    gliColDir = from;
     652                }
     653                if(defaultColDir.equals(gliColDir)) {
     654                    gliColDir = "";
     655                }
     656                if(!(collection_open && gli_yes.isSelected())) { // don't overwrite open collections
     657                    Configuration.setString(
     658                        "general.open_collection"+Configuration.gliPropertyNameSuffix(),
     659                        true, gliColDir);
     660                }
     661               
     662                // store the option chosen for the server's settings
     663                String serverColDir = from;
     664                if(server_optional != null && server_optional.isSelected()) {
     665                    // defaultColDir
     666                    serverColDir = null;
     667                } else if(server_yes.isSelected()) {
     668                    serverColDir = to;
     669                } else if (server_no.isSelected()) {
     670                    serverColDir = from;
     671                }
     672                if(serverColDir != null && defaultColDir.equals(serverColDir)) {                   
     673                    serverColDir = null;
     674                }
     675                               
     676                Gatherer.gsdlsite_collecthome = Utility.updatePropertyConfigFile(
     677                    Gatherer.getGsdlSiteConfigFile(), "collecthome", serverColDir);
     678               
     679                colHomeDialog.dispose();
     680            }
     681        });
     682       
     683        //String[] dirs = {from, to};       
     684        //JLabel message = new JLabel(Dictionary.get("GUI.CollectHome.message", dirs));
     685        JLabel message = new JLabel(Dictionary.get("GUI.CollectHome.message"));
     686        JLabel fromDirLine = new JLabel(Dictionary.get("GUI.CollectHome.dir", from));
     687        fromDirLine.setBorder(BorderFactory.createEmptyBorder(0,25,0,0)); // padding
     688        JLabel toLine = new JLabel(Dictionary.get("GUI.CollectHome.to"));
     689        JLabel toDirLine = new JLabel(Dictionary.get("GUI.CollectHome.dir", to));
     690        toDirLine.setBorder(BorderFactory.createEmptyBorder(0,25,0,0)); // padding
     691        JLabel gliOption = new JLabel(Dictionary.get("GUI.CollectHome.gli"));
     692        JLabel serverOption = new JLabel(Dictionary.get("GUI.CollectHome.server"));     
     693       
     694        JPanel mainPanel = new JPanel();
     695        mainPanel.setLayout(new GridLayout(9, 1));
     696        mainPanel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); // padding
     697        mainPanel.add(message);
     698        mainPanel.add(fromDirLine);     
     699        mainPanel.add(toLine);
     700        mainPanel.add(toDirLine);
     701        mainPanel.add(gliOption);
     702        mainPanel.add(gliPanel);
     703        mainPanel.add(serverOption);
     704        mainPanel.add(serverPanel);
     705        mainPanel.add(okButton);       
     706        Container c = colHomeDialog.getContentPane();
     707        c.setLayout(new BorderLayout());
     708        c.add(mainPanel, BorderLayout.CENTER);
     709        colHomeDialog.getRootPane().setDefaultButton(okButton);
     710       
     711        colHomeDialog.pack();
     712        colHomeDialog.setVisible(true);
     713    }
     714   
    546715
    547716    /** This method is called when the collection is being built, and is used to disable all controls in all pane which could change the state of the collection.
Note: See TracChangeset for help on using the changeset viewer.