Changeset 30701


Ignore:
Timestamp:
08/12/16 19:47:27 (4 years ago)
Author:
ak19
Message:

All the changes to get the new collectionConfig.xml Editor (ConfigFileEditor.java) to work.

Location:
main/trunk/gli
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/classes/dictionary.properties

    r29509 r30701  
    648648General.Redo:Redo
    649649General.Redo_Tooltip:Restore the last undo
     650General.Save:Save
    650651General.Undo:Undo
    651652General.Undo_Tooltip:Undo the last edit
     
    769770Menu.Edit_Cut:Cut ({0}-x)
    770771Menu.Edit_Paste:Paste ({0}-v)
     772Menu.Edit_Config:Edit collectionConfig.xml
    771773Menu.Expand:Open Folder
    772774Menu.Explode_Metadata_Database:Explode metadata database
     
    962964FormatConversionDialog.XHTML_Tidy_Tooltip:Will run HTML Tidy over the Greenstone3 format statement to try to fix up obvious XHTML errors.
    963965FormatConversionDialog.XML_Still_Invalid:XML is still invalid.
     966
     967#***** ConfigFileEditor *****
     968ConfigFileEditor.Tooltip:Greenstone 3 collection configuration XML editor.
     969ConfigFileEditor.Save_Tooltip:Save changes and close.
     970ConfigFileEditor.Cancel_Tooltip:Close without saving.
    964971
    965972#**********************
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r29036 r30701  
    257257        DebugStream.println(cce.toString());
    258258        }
     259    }
     260    else if(esrc == menu_bar.edit_config) {   
     261        if(Gatherer.c_man.getCollection() != null) {
     262        //JOptionPane.showMessageDialog(this, "Not yet implemented", "Edit config", JOptionPane.INFORMATION_MESSAGE);
     263        ConfigFileEditor configEditor = new ConfigFileEditor();
     264        configEditor.setVisible(true);
     265        configEditor.setSize(900,700);
     266       
     267        }     
    259268    }
    260269
     
    11331142        }
    11341143        }
     1144        else if(e.getSource() == menu_bar.edit) { // someone clicked the toplevel Edit menu
     1145        // gray out the Edit Config File menu if there's no collection currently open.
     1146        if(Gatherer.c_man.getCollection() == null) {
     1147            menu_bar.edit_config.setEnabled(false);
     1148        }
     1149        else { // don't forget to reenable the Edit ConfigXML menu item when applicable
     1150            menu_bar.edit_config.setEnabled(true);
     1151        }
     1152        }
     1153
    11351154    }
    11361155    }
  • main/trunk/gli/src/org/greenstone/gatherer/gui/MenuBar.java

    r28628 r30701  
    7676    public JMenuItem edit_cut;
    7777    public JMenuItem edit_paste;
     78    public JMenuItem edit_config;
    7879    public JMenuItem help_general;
    7980    public JMenuItem help_download;
     
    162163    edit.setText(Dictionary.get("Menu.Edit"));
    163164    edit.setComponentOrientation(Dictionary.getOrientation());
    164 
    165165    String modkey = "ctrl";
    166166    if(Utility.isMac()) { // on Mac, we now use the Apple key instead of Ctrl for GLI/GEMS edit shortcuts
     
    182182    edit_paste.addActionListener(Gatherer.g_man);
    183183    edit_paste.setComponentOrientation(Dictionary.getOrientation());
     184
    184185    // Layout (edit menu)
    185186    edit.add(edit_cut);
    186187    edit.add(edit_copy);
    187188    edit.add(edit_paste);
     189
     190    // if GS3, then we have a menu item that allows editing of config files
     191    if(Gatherer.GS3) {   
     192
     193        edit_config = new JMenuItem(Dictionary.get("Menu.Edit_Config"));
     194        // handle the actual Edit > ColConfig.xml menu item
     195        edit_config.addActionListener(Gatherer.g_man);
     196        edit_config.setComponentOrientation(Dictionary.getOrientation());
     197        edit.add(edit_config);
     198        // The Edit menu itself now listens, in order to gray out the
     199        // Edit > collectionConfig.xml option when no collection is open
     200        // (JMenu doesn't work with ActionListener only with MenuListener, see
     201        // http://stackoverflow.com/questions/9862165/jmenu-actionlistener)
     202        edit.addMenuListener(menu_listener);
     203
     204    }
    188205
    189206    // Help menu
  • main/trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r29972 r30701  
    7474    static final public String PERL_EXECUTABLE_WINDOWS = "Perl.exe";
    7575
     76
     77    /**
     78     * Reads in a text file and returns the contents as a String
     79     */
     80    static public String readFile(File file) {
     81    BufferedReader fin = null;
     82    StringBuffer contents = new StringBuffer();
     83   
     84    try {
     85        fin = new BufferedReader(new FileReader(file));
     86        String line = null;
     87        while((line = fin.readLine()) != null) {
     88        contents.append(line);
     89        contents.append("\n");
     90        }
     91    } catch(IOException e) {
     92        System.err.println("*** Could not read in file: " + file.toString());
     93        System.err.println("*** Exception occurred: " + e.getMessage());
     94    } finally {
     95        try {
     96        if(fin != null) {
     97            fin.close();
     98            fin = null;
     99        }
     100        } catch(IOException ioe) {
     101        fin = null;
     102       
     103        }
     104    }
     105
     106    return contents.toString();
     107    }
    76108
    77109    /**
  • main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java

    r29730 r30701  
    1313import java.io.IOException;
    1414import java.io.StringReader;
     15import java.io.StringWriter; // for elementToString()
    1516
    1617// SAX
     
    2829import javax.xml.parsers.SAXParser;
    2930import javax.xml.parsers.SAXParserFactory;
     31// for elementToString():
     32import javax.xml.transform.OutputKeys;
     33import javax.xml.transform.Transformer;
     34import javax.xml.transform.TransformerFactory;
     35import javax.xml.transform.dom.DOMSource;
     36import javax.xml.transform.stream.StreamResult;
    3037
    3138
     
    523530        if (xml_file.exists() == false)
    524531        {
     532            System.err.println("@@@ file " + xml_file + " does not exist.");
    525533            return null;
    526534        }
     
    12241232        }
    12251233    }
     1234
     1235
     1236   
     1237    // This method will convert an Element to a String too, like xmlNodeToString() above.
     1238    // But for a document root element (doc.getDocumentElement()), this method will additionally
     1239    // return its processing instruction line at the start (<?xml ... ?>).
     1240    // This method copied into GLI from src/java/org/greenstone/gsdl3/util/GSXML.java
     1241    public static String elementToString(Element e, boolean indent)
     1242    {
     1243    String str = "";
     1244    try
     1245        {
     1246        TransformerFactory tf = TransformerFactory.newInstance();
     1247        Transformer trans = tf.newTransformer();
     1248        StringWriter sw = new StringWriter();
     1249        if (indent)
     1250            {
     1251            trans.setOutputProperty(OutputKeys.INDENT, "yes");
     1252            }
     1253        else
     1254            {
     1255            trans.setOutputProperty(OutputKeys.INDENT, "no");
     1256            }
     1257        trans.transform(new DOMSource(e), new StreamResult(sw));
     1258        str += sw.toString();
     1259        }
     1260    catch (Exception ex)
     1261        {
     1262        str += "Exception: couldn't write " + e + " to log";
     1263        }
     1264    finally
     1265        {
     1266        return str;
     1267        }
     1268    }
    12261269}
Note: See TracChangeset for help on using the changeset viewer.