Changeset 8971


Ignore:
Timestamp:
2005-02-07T10:36:51+13:00 (19 years ago)
Author:
mdewsnip
Message:

More GEMS fixes, by Matthew Whyte. Can now create subelements of subelements.

Location:
trunk/gli/src/org/greenstone/gatherer/gems
Files:
9 edited

Legend:

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

    r8932 r8971  
    6363    private String namespace = "";
    6464    private ArrayList subelements = null; //The list of subelements
    65     // private XMLTools xmlTools = new XMLTools(); //uh, a class of XML tools, i guess
    66 
    6765    private Troolean is_extracted = new Troolean();
     66
    6867    /** Constructor for elements with no namespace necessary.
    6968     * @param element The DOM <strong>Element</strong> this is to be based on.
     
    9594       @param name the name of the subelement to check for, as a <strong>String</strong>
    9695       @author Matthew Whyte
    97        @date last modified: 19/01/04
     96       Date last modified: 19/01/04
    9897    */
    9998    public boolean containsSubelement(String name)
     
    113112    }
    114113
     114    /*
     115      Check to see if the element contains any subelements
     116      @return tree if element contains subelements
     117      @author Matthew Whyte
     118      Date last modified: 2/02/05
     119     */
     120    public boolean containsSubelements()
     121    {
     122    return(subelements.size() != 0);
     123    }
     124
    115125    /**
    116126       Method to add a subelement to the list of subelements.
     
    122132    {
    123133    subelements.add(element);
     134    }
     135
     136    /**
     137       Method to remove a subelement from the list of subelements.
     138       @param element the subelement to remove from the list, as a <strong>Element</strong>
     139       @author Matthew Whyte
     140       Date last modified: 27/01/05
     141     */
     142    public void removeSubelementFromList(Element element)
     143    {
     144    subelements.remove(element);
    124145    }
    125146
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java

    r8932 r8971  
    3636package org.greenstone.gatherer.gems;
    3737
    38 
    3938import java.awt.*;
    4039import java.awt.event.*;
     
    8786    static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
    8887    static final private Dimension RENAME_ELEMENT_SIZE = new Dimension(400, 95);
    89     static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
    9088    static final private Dimension ADD_SET_SIZE = new Dimension(400,150);
    9189    static final private Dimension RENAME_SET_SIZE = new Dimension(400,120);
    9290    static final private Dimension OPEN_SETS_SIZE = new Dimension(400,135);
    9391    static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
    94     static final private Dimension ADD_OR_EDIT_VALUE_SIZE = new Dimension(600,440);
    95    
    9692    static final private Dimension COMPONENT_SIZE = new Dimension(300,30);
    9793    static final private Dimension SIZE = new Dimension(800,480);
    9894    static final private String BLANK = "blank";
    9995    static final private String ELEMENT = "element";
    100     static final private String PROFILE = "profile";
    10196    static final private String SET = "set";
    102     static final private String SUBELEMENT = "subelement";
    103     static final private String VALUES = "values";
    10497
    10598    static final public String METADATA_SET_TEMPLATE = "xml/template.mds";
     
    109102    static final public int T_COLLECTION = 0;
    110103    static final public int T_ELEMENT    = 1;
    111     static final public int T_PROFILER   = 2;
    112     static final public int T_ROOT       = 3;
    113104    static final public int T_SET        = 4;
    114     static final public int T_SUBELEMENT = 5;
    115 
    116    // static final public String MAX_LOADED_SETS = 64;
     105
     106    //static final public String MAX_LOADED_SETS = 64;
    117107    static public Configuration config = null;
    118108    private MetadataSetManager msm = new MetadataSetManager(this);
    119109
    120110    public AddElementActionListener add_element_action_listener = null;
    121     private AddFileActionListener add_file_action_listener = null;
    122111    public  AddSetActionListener add_set_action_listener = null;
    123112    /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */
    124113    public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null;
    125     /** The class used to handle add or edit value actions has to be globally available so that we can dispose of its dialog properly. */
    126     //public AddOrEditValueActionListener add_or_edit_value_action_listener = null;
    127114    private boolean ignore = false;
    128115    /** A card layout is used to switch between the two differing detail views. */
    129116    private CardLayout card_layout = null;
    130     /** A card layout is used to switch between a value tree or an empty placeholder (if no value tree available). */
    131     private CardLayout element_values_layout = null;
    132117
    133118    /** Um, the size of the screen I'd guess. */
    134119    private Dimension screen_size = null;
    135120    private ElementWrapper current_element = null;
    136     private ElementWrapper current_subelement = null;
    137     private GValueNode current_value_node = null;
    138121    /** A reference to ourselves so our inner classes can dispose of us. */
    139122    private GEMS self = null;
     
    142125    private int current_attribute_type = -1;
    143126
    144     private JLabel element_name = null;
    145     private JLabel profile_name = null;
     127    //private JLabel element_name = null;
    146128    private JLabel set_name = null;
    147129    private JScrollPane element_attributes_scroll = null;
    148     private JScrollPane profile_attributes_scroll = null;
    149130    private JScrollPane set_attributes_scroll = null;
    150     private JScrollPane subelement_attributes_scroll = null;
    151131    private JPanel details_pane = null;
    152     private JPanel element_values_pane = null;
    153     private KeepTreeRootExpandedListener keep_root_expanded_listener = null;
    154132    private GEMSModel model = null;
    155133    private GEMSNode current_node = null;
    156134    private MetadataSet current_set = null;
    157     private Object target = null;
    158135    public RemoveSetActionListener remove_set_action_listener;
    159     private SmarterTable subelement_attributes = null;
    160136    private SmarterTable element_attributes = null;
    161     private SmarterTable profile_attributes = null;
    162137    private SmarterTable set_attributes = null;
    163     private SmarterTree element_values = null;
    164138    public org.w3c.dom.Element rootelement;
    165139   
     
    171145    /** A tree that represents the current metadata sets associated with this collection. */
    172146    private SmarterTree mds_tree = null;
    173     private String current_collection_file = null;
    174147    private String dialog_options[] = null;
    175148    private boolean atLeastOneSetChanged = false;
     
    195168           
    196169        config = new Configuration(go.gsdl_path, null, null);
    197        
    198            
    199170    }
    200171    catch (Exception exception) {
     
    226197    dialog_options[1] = Dictionary.get("General.Cancel");
    227198
    228     // Creation
    229     setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    230     setSize(SIZE);
    231     setJMenuBar(new GEMSMenuBar());
    232     Dictionary.setText(this, "GEMS.Title");
    233 
    234     JPanel content_pane = (JPanel) getContentPane();
    235     content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
    236          
    237     JPanel upper_pane = new JPanel();
    238     upper_pane.setOpaque(false);
    239          
    240199    // Load all the core metadata sets (in the GLI "metadata" directory)
    241200    model = new GEMSModel();
     
    254213    }
    255214
     215    // Creation
     216    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
     217    setSize(SIZE);
     218    setJMenuBar(new GEMSMenuBar());
     219    Dictionary.setText(this, "GEMS.Title");
     220
     221    JPanel content_pane = (JPanel) getContentPane();
     222    content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));     
     223    JPanel upper_pane = new JPanel();
     224    upper_pane.setOpaque(false);
     225    JPanel set_details_pane = new JPanel();
     226    set_details_pane.setOpaque(false);
     227    JPanel set_name_pane = new JPanel();
     228    set_name_pane.setOpaque(false);
     229    JLabel set_name_label = new JLabel();
     230    set_name_label.setOpaque(false);
     231    JPanel element_details_pane = new JPanel();
     232    element_details_pane.setOpaque(false);   
     233    JPanel element_inner_pane = new JPanel();
     234    element_inner_pane.setOpaque(false);
     235    JPanel blank_pane = new JPanel(); // Some blank panel
     236    blank_pane.setOpaque(false);
     237
     238    details_pane = new JPanel();
     239    details_pane.setOpaque(false);
     240    card_layout = new CardLayout();
     241    set_name = new JLabel();
     242   
    256243    JPanel mds_tree_pane = new JPanel();
    257244    mds_tree_pane.setOpaque(false);
    258245    mds_tree_pane.setPreferredSize(new Dimension(300,500));
     246
    259247    mds_tree = new SmarterTree(model);
    260248    mds_tree.setCellRenderer(new GEMSTreeCellRenderer());
     
    264252    mds_tree.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    265253    mds_tree.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    266        
    267254        //add popupevent handler for tree items
    268      
    269255        mds_tree.addMouseListener(popupListener);
    270256    mds_tree.addKeyListener(new KeyPressedHandler());
    271     details_pane = new JPanel();
    272     details_pane.setOpaque(false);
    273     card_layout = new CardLayout();
    274          
    275     JPanel set_details_pane = new JPanel();
    276     set_details_pane.setOpaque(false);
    277          
    278     JPanel set_name_pane = new JPanel();
    279     set_name_pane.setOpaque(false);
    280     JLabel set_name_label = new JLabel();
    281     set_name_label.setOpaque(false);
    282     set_name = new JLabel();
     257    mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());
    283258         
    284259    JPanel set_attributes_pane = new JPanel();
     
    300275    set_attributes.addMouseListener(new AddOrEditAttributeActionListener());
    301276    set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key
    302     JPanel element_details_pane = new JPanel();
    303     element_details_pane.setOpaque(false);
    304 
    305     JPanel element_name_pane = new JPanel();
    306     element_name_pane.setOpaque(false);
    307     JLabel element_name_label = new JLabel();
    308     element_name_label.setOpaque(false);
    309          
    310     JPanel element_inner_pane = new JPanel();
    311     element_inner_pane.setOpaque(false);
     277    set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
    312278         
    313279    JPanel element_attributes_pane = new JPanel();
     
    328294    element_attributes.addMouseListener(new AddOrEditAttributeActionListener());
    329295    element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
    330        
    331     element_values_layout = new CardLayout();
    332     element_values_pane = new JPanel();
    333     element_values_pane.setOpaque(false);
    334     element_values = new SmarterTree();
    335     element_values.setBackground(config.getColor("coloring.collection_tree_background", false));
    336     element_values.setForeground(config.getColor("coloring.collection_tree_foreground", false));
    337     element_values.setRootVisible(false);
    338     element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    339     element_values.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    340        
    341     JPanel subelement_details_pane = new JPanel();
    342     subelement_details_pane.setOpaque(false);
    343     JPanel subelement_name_pane = new JPanel();
    344     subelement_name_pane.setOpaque(false);
    345     JLabel subelement_name_label = new JLabel();
    346     subelement_name_label.setOpaque(false);
    347     JPanel subelement_inner_pane = new JPanel();
    348     subelement_inner_pane.setOpaque(false);
    349 
    350     JPanel subelement_attributes_pane = new JPanel();
    351     subelement_attributes_pane.setOpaque(false);
    352     subelement_attributes_scroll = new JScrollPane();
    353     subelement_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
    354     subelement_attributes_scroll.setOpaque(true);
    355     subelement_attributes = new SmarterTable();
    356     subelement_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    357     subelement_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
    358     subelement_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
    359     subelement_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
    360     subelement_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
    361     subelement_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    362     subelement_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    363     subelement_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    364         subelement_attributes.addMouseListener(popupListener);
    365     subelement_attributes.addMouseListener(new AddOrEditAttributeActionListener());
    366     subelement_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
    367    
    368     JPanel element_novalues_pane = new JPanel();
    369 
    370     keep_root_expanded_listener = new KeepTreeRootExpandedListener();
    371 
    372     JPanel profile_details_pane = new JPanel();
    373     profile_details_pane.setOpaque(false);
    374     JPanel profile_name_pane = new JPanel();
    375     profile_name_pane.setOpaque(false);
    376     JLabel profile_name_label = new JLabel();
    377     profile_name_label.setOpaque(false);
    378     profile_name = new JLabel();
    379     profile_name.setBorder(BorderFactory.createLoweredBevelBorder());
    380     profile_name.setOpaque(false);
    381 
    382     JPanel profile_attributes_pane = new JPanel();
    383     profile_attributes_pane.setOpaque(false);
    384     profile_attributes_scroll = new JScrollPane();
    385     profile_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
    386     profile_attributes_scroll.setOpaque(true);
    387     profile_attributes = new SmarterTable();
    388     profile_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    389     profile_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
    390     profile_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
    391     profile_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
    392     profile_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
    393     profile_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    394     profile_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    395     profile_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    396 
    397     JPanel button_pane = new JPanel();
    398     button_pane.setOpaque(false);
    399 
    400     JPanel button_label_pane = new JPanel();
    401     button_label_pane.setOpaque(false);
    402 
    403     JLabel attribute_label = new JLabel();
    404     attribute_label.setOpaque(false);
    405     Dictionary.setText(attribute_label, "GEMS.Attribute");
    406 
    407     JLabel element_label = new JLabel();
    408     element_label.setOpaque(false);
    409     Dictionary.setText(element_label, "GEMS.Element");
    410 
    411     JLabel file_label = new JLabel();
    412     file_label.setOpaque(false);
    413     Dictionary.setText(file_label, "GEMS.File");
    414 
    415     JLabel set_label = new JLabel();
    416     set_label.setOpaque(false);
    417     Dictionary.setText(set_label, "GEMS.Set");
    418 
    419     JLabel value_label = new JLabel();
    420     value_label.setOpaque(false);
    421     Dictionary.setText(value_label, "GEMS.Value");
    422 
    423     JPanel inner_button_pane = new JPanel();
    424     inner_button_pane.setOpaque(false);
     296    element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
    425297
    426298    add_element_action_listener = new AddElementActionListener();
    427     add_file_action_listener = new AddFileActionListener();
    428299    add_set_action_listener = new AddSetActionListener();
    429300    add_or_edit_attribute_action_listener = new AddOrEditAttributeActionListener();
    430301    remove_set_action_listener = new RemoveSetActionListener();
    431 
    432     // Some blank panel
    433     JPanel blank_pane = new JPanel();
    434     blank_pane.setOpaque(false);
    435     JPanel edit_file_pane = new JPanel();
    436     edit_file_pane.setOpaque(false);
    437     JPanel edit_element_pane = new JPanel();
    438     edit_element_pane.setOpaque(false);
    439     JPanel edit_set_pane = new JPanel();
    440     edit_set_pane.setOpaque(false);
    441 
    442     element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
    443     subelement_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(subelement_attributes));
    444     profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes));
    445     set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
    446     mds_tree.addTreeSelectionListener(new MDSTreeSelectionListener());
    447302
    448303    // Layout
     
    450305    mds_tree_pane.add(new JScrollPane(mds_tree), BorderLayout.CENTER);
    451306         
     307    //Set panes
    452308    set_name_pane.setLayout(new BorderLayout());
    453309    set_name_pane.add(set_name_label, BorderLayout.WEST);
     
    455311               
    456312    set_attributes_scroll.setViewportView(set_attributes);
    457 
    458313    set_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
    459314    set_attributes_pane.setLayout(new BorderLayout());
     
    464319    set_details_pane.add(set_name_pane, BorderLayout.NORTH);
    465320    set_details_pane.add(set_attributes_pane, BorderLayout.CENTER);
    466 
    467     element_name_pane.setLayout(new BorderLayout());
    468     //element_name_pane.add(element_name_label, BorderLayout.WEST);
    469     //element_name_pane.add(element_name, BorderLayout.CENTER);
    470                
     321       
     322    //Element panes
    471323    element_attributes_scroll.setViewportView(element_attributes);
    472 
    473324    element_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
    474325    element_attributes_pane.setLayout(new BorderLayout());
    475326    element_attributes_pane.add(element_attributes_scroll, BorderLayout.CENTER);
    476327         
    477     element_values_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Values")), BorderFactory.createEmptyBorder(2,2,2,2)));
    478     element_values_pane.setLayout(new BorderLayout());
    479     element_values_pane.add(new JScrollPane(element_values), BorderLayout.CENTER);
    480     element_values_pane.setLayout(element_values_layout);
    481     //element_values_pane.add(element_novalues_pane, BLANK);
    482     //element_values_pane.add(new JScrollPane(element_values), VALUES);
    483 
    484328    element_inner_pane.setLayout(new BorderLayout());
    485329    element_inner_pane.add(element_attributes_pane);
    486     //element_inner_pane.add(element_values_pane);
    487330         
    488331    element_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Element_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
    489332    element_details_pane.setLayout(new BorderLayout());
    490     //element_details_pane.add(element_name_pane, BorderLayout.NORTH);
    491333    element_details_pane.add(element_inner_pane, BorderLayout.CENTER);
    492    
    493     subelement_name_pane.setLayout(new BorderLayout());
    494     subelement_attributes_scroll.setViewportView(subelement_attributes);
    495     subelement_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
    496     subelement_attributes_pane.setLayout(new BorderLayout());
    497     subelement_attributes_pane.add(subelement_attributes_scroll, BorderLayout.CENTER);
    498    
    499 
    500     subelement_inner_pane.setLayout(new BorderLayout());
    501     subelement_inner_pane.add(subelement_attributes_pane);
    502     subelement_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Subelement_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
    503     subelement_details_pane.setLayout(new BorderLayout());
    504     subelement_details_pane.add(subelement_inner_pane, BorderLayout.CENTER);
    505    
    506     profile_name_pane.setLayout(new BorderLayout());
    507     profile_name_pane.add(profile_name_label, BorderLayout.WEST);
    508     profile_name_pane.add(profile_name, BorderLayout.CENTER);
    509 
    510     profile_attributes_scroll.setViewportView(profile_attributes);
    511 
    512     profile_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profiles")), BorderFactory.createEmptyBorder(2,2,2,2)));
    513     profile_attributes_pane.setLayout(new BorderLayout());
    514     profile_attributes_pane.add(profile_attributes_scroll, BorderLayout.CENTER);
    515 
    516     profile_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Profile_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
    517     profile_details_pane.setLayout(new BorderLayout());
    518     //profile_details_pane.add(profile_name_pane, BorderLayout.NORTH);
    519     profile_details_pane.add(profile_attributes_pane, BorderLayout.CENTER);
    520 
     334
     335    //General panes
    521336    details_pane.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
    522337    details_pane.setLayout(card_layout);
     
    524339    details_pane.add(set_details_pane, SET);
    525340    details_pane.add(element_details_pane, ELEMENT);
    526     details_pane.add(subelement_details_pane, SUBELEMENT);
    527     details_pane.add(profile_details_pane, PROFILE);
    528341
    529342    upper_pane.setLayout(new BorderLayout());
    530343    upper_pane.add(mds_tree_pane, BorderLayout.WEST);
    531344    upper_pane.add(details_pane, BorderLayout.CENTER);
    532          
    533     button_label_pane.setLayout(new GridLayout(4,1,0,2));
    534     button_label_pane.setBorder(BorderFactory.createEmptyBorder(0,0,0,2));
    535 
    536     inner_button_pane.setLayout(new GridLayout(4,3,0,2));       
    537          
    538     button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
    539     button_pane.setLayout(new BorderLayout());
    540     //button_pane.add(button_label_pane, BorderLayout.WEST);
    541     //button_pane.add(inner_button_pane, BorderLayout.CENTER);
    542345
    543346    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    544347    content_pane.setLayout(new BorderLayout());
    545348    content_pane.add(upper_pane, BorderLayout.CENTER);
    546     content_pane.add(button_pane, BorderLayout.SOUTH);
    547349
    548350    // initialise the selection
     
    628430        file_save.addActionListener(this);
    629431        file_save.setMnemonic(KeyEvent.VK_S);
    630        // Dictionary.registerText(file_save, "GEMS.Menu.File_Save");
    631432            Dictionary.registerText(file_save, "Menu.File_Save");
    632433           
     
    634435        file_delete.addActionListener(new KeyPressedHandler()); //KeyPressedHandler handles deleting stuff.
    635436        file_delete.setMnemonic(KeyEvent.VK_S);
    636        // Dictionary.registerText(file_delete, "GEMS.Menu.File_Delete");
    637437            Dictionary.registerText(file_delete, "Menu.File_Delete");
    638438           
     
    640440        file_preferences.addActionListener(this);
    641441        file_preferences.setMnemonic(KeyEvent.VK_S);
    642         //Dictionary.registerText(file_preferences, "GEMS.Menu.File_Preferences");
    643442            Dictionary.registerText(file_preferences, "Menu.File_Options");
    644443
     
    678477        edit.add(edit_paste);
    679478
    680         // Help menu
     479        // Help menu. Is not used! --Matthew
    681480        help = new JMenu();
    682481        help.setIcon(Utility.HELP_ICON);
     
    805604    {
    806605        String file_name = file.getName().toLowerCase();
    807         if (file_name.endsWith(".mds") || file_name.indexOf(".") == -1) {
    808         return true;
    809         }
    810 
    811         return false;
     606        return(file_name.endsWith(".mds") || file_name.indexOf(".") == -1);
    812607    }
    813608
     
    860655          exit();
    861656       }
    862        
    863  
    864657   }
    865658   //called from MetadataSetManager...I don't think it should be here anymore, but for now it's ok
     
    889682    element_attributes = null;
    890683    set_attributes = null;
    891     subelement_attributes = null;
    892     element_name = null;
    893684    set_name = null;
    894     element_values = null;
    895685    mds_tree = null;
    896     target = null;
    897686       
    898687        popupListener = null;
     
    916705       Class to handle adding or modifying element attributes.
    917706     */
    918    private class AddOrEditAttributeActionListener
     707    private class AddOrEditAttributeActionListener
    919708    extends ModalDialog
    920709    implements ActionListener, MouseListener {
    921        private boolean add_type = true;
    922        private ComboArea value = null;
    923        private JButton cancel_button = null;
    924        private JButton ok_button = null;
    925        private JComboBox language_box = null;
    926        private GComboBox name = null;
    927        private HashMap name_to_values = null;
    928        private JLabel target = null;
    929        private JLabel target_label = null;
    930        private Vector attributeLists = null;     
    931        
     710    private boolean add_type = true;
     711    private ComboArea value = null;
     712    private JButton cancel_button = null;
     713    private JButton ok_button = null;
     714    private JComboBox language_box = null;
     715    private GComboBox name = null;
     716    private HashMap name_to_values = null;
     717    private JLabel target = null;
     718    private JLabel target_label = null;
     719    private Vector attributeLists = null;     
     720   
    932721        //org.w3c.dom.Document lang = Utility.parse("/home/arosmain/gsdl/gli/classes/xml/languages.xml", false);
    933           org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false);
    934          
     722    org.w3c.dom.Document lang = Utility.parse(Configuration.gsdl_path + "/gli/classes/xml/languages.xml", false);
     723   
    935724    /** Constructor. */
    936725    public AddOrEditAttributeActionListener() {
     
    938727        setModal(true);
    939728            attributeLists = new Vector();
    940             //
    941729            attributeLists.add("identifier");
    942730            attributeLists.add("comment");
    943731            attributeLists.add("definition");
    944732            attributeLists.add("name");
    945            
     733
    946734            attributeLists.add("creator");
    947735            attributeLists.add("date");
     
    1009797        ok_button = new GLIButton();
    1010798        ok_button.setMnemonic(KeyEvent.VK_O);
     799        getRootPane().setDefaultButton(ok_button);
    1011800        Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
    1012801        cancel_button = new GLIButton();
     
    1073862       public void mouseClicked(MouseEvent e)
    1074863    {
    1075         if(e.getSource() == element_attributes || e.getSource() == set_attributes || e.getSource() == subelement_attributes)
     864        if(e.getSource() == element_attributes || e.getSource() == set_attributes)
    1076865        {
    1077866            if(e.getClickCount() == 2) //Double click
     
    1083872        }
    1084873    }
    1085     //required by MouseListener
    1086     public void mouseEntered(MouseEvent e)
    1087     {
    1088     }
    1089     //required by MouseListener
    1090     public void mouseExited(MouseEvent e)
    1091     {
    1092     }
    1093     //required by MouseListener
    1094     public void mousePressed(MouseEvent e)
    1095     {
    1096     }
    1097     //required by MouseListener
    1098     public void mouseReleased(MouseEvent e)
    1099     {
    1100     }
     874    //These methods are required by interface MouseListener
     875    public void mouseEntered(MouseEvent e){}
     876    public void mouseExited(MouseEvent e){}
     877    public void mousePressed(MouseEvent e){}
     878    public void mouseReleased(MouseEvent e){}
    1101879
    1102880    /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to add a new attribute to the selected set or element.
     
    1105883    public void actionPerformed(ActionEvent event) {
    1106884        Object source = event.getSource();
    1107             AttributeTableModel tablemodel = null;
    1108885        AttributeTableModel model = null;
    1109             String prevLang = new String("");
    1110             String prevValue = new String("");
    1111886           
    1112887        if(current_element != null)
     
    1120895            target.setText(current_set.toString());
    1121896            Dictionary.setText(target_label, "GEMS.Target");
    1122         }
    1123         else if(current_subelement != null)
    1124         {
    1125             target.setText(current_subelement.getName());
    1126             Dictionary.setText(target_label, "GEMS.Subelement");
    1127897        }
    1128898       
     
    1135905        boolean success = true;
    1136906
    1137         // Add or edit a collect/set/element attribute
     907        // Add or edit a set/element attribute
    1138908        switch(current_attribute_type) {
    1139         case GEMSNode.COLLECTION:
    1140             model = (AttributeTableModel) profile_attributes.getModel();
    1141             success = addOrEditCollectionAttribute(model);
    1142             break;
    1143909        case GEMSNode.SET:
    1144910            model = (AttributeTableModel) set_attributes.getModel();
    1145             success = addOrEditSetAttribute(model);
    1146                    
     911            success = addOrEditSetAttribute(model);
    1147912            break;
    1148913        case GEMSNode.ELEMENT:
     
    1150915            success = addOrEditElementAttribute(model);
    1151916            break;
    1152            
    1153         case GEMSNode.SUBELEMENT:
    1154             model = (AttributeTableModel) subelement_attributes.getModel();
    1155             success = addOrEditSubelementAttribute(model);
    1156             break;
    1157            
    1158917        }
    1159918                 
    1160919        if (success) {
    1161920            // Hide dialog
    1162                
    1163921            atLeastOneSetChanged = true;
    1164922            setVisible(false);
     
    1180938        if(object != null) {
    1181939            java.util.List values = (java.util.List) name_to_values.get(object.toString());
    1182             if(values == null && current_attribute_type==GEMSNode.COLLECTION) {
    1183             values = msm.getElements();
    1184             }
    1185940                   
    1186941                    if(value != null && values != null){
     
    1192947        }
    1193948        }
    1194         else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeSubelement){
     949        else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement){
    1195950
    1196951        Dictionary.setText(this, "GEMS.AddAttribute");
     
    1199954                   
    1200955        }
    1201 
    1202        
    1203956        name.setEnabled(true);
    1204957        setVisible(true);
    1205958            }
    1206            /* else if (source == popupListener.menuAddAttributeAttribute){
    1207                 System.out.println("add attr\n");
    1208                
    1209                 name.setEnabled(true);
    1210                
    1211             }*/
    1212           /* else{
    1213         // Name combo box is enabled except when attributes are edited
    1214         //name.setEnabled((source != popupListener.menuEditValue));
    1215                 //System.out.println("elsed");
    1216         name_to_values.clear();
    1217         name.clear();
    1218         value.clear();
    1219         value.setText("");
    1220         // Build the correct name_to_values mapping
    1221         // Attributes are slightly tricky as they can come from several sources. Has a collection file been selected...
    1222         if(current_collection_file != null) {
    1223             target.setText(current_collection_file);
    1224             // Name is empty in this one, however values must be the current elements in the collection.                         
    1225             language_box.setEnabled(false);
    1226         }
    1227         // or has an element been selected
    1228         else if(current_element != null) {
    1229             target.setText(current_element.toString());
    1230             // Develop a model for name based on known attributes from all other elements.
    1231             java.util.List elements = msm.getElements();
    1232             for(int i = 0; i < elements.size(); i++) {
    1233             ElementWrapper element = (ElementWrapper) elements.get(i);
    1234             TreeSet attributes = element.getAttributes();
    1235             for(Iterator attribute_iterator = attributes.iterator(); attribute_iterator.hasNext(); ) {
    1236                 Attribute attribute = (Attribute) attribute_iterator.next();
    1237                 java.util.List values = (java.util.List) name_to_values.get(attribute.name);
    1238                 if(values == null) {
    1239                 values = new ArrayList();
    1240                 name_to_values.put(attribute.name, values);
    1241                 }
    1242                 if(!values.contains(attribute.value)) {
    1243                 values.add(attribute.value);
    1244                 }
    1245                 values = null;
    1246                 attribute = null;
    1247             }
    1248             attributes = null;
    1249             element = null;
    1250             }
    1251             elements = null;
    1252             language_box.setEnabled(true);
    1253         }
    1254         else if(current_set != null) {
    1255             target.setText(current_set.toString());
    1256             // Develop a model for name based on known attributes from all other metadata sets. At the same time build a hashmap mapping attribute name to lists of values.
    1257             java.util.List sets = msm.getSets();
    1258             for(int i = 0; i < sets.size(); i++) {
    1259             MetadataSet set = (MetadataSet) sets.get(i);
    1260             NamedNodeMap attributes = set.getAttributes();
    1261             for(int j = 0; j < attributes.getLength(); j++) {
    1262                 Attr attribute = (Attr) attributes.item(j);
    1263                 String name_str = attribute.getName();
    1264                 String value_str = attribute.getValue();
    1265                 java.util.List values = (java.util.List) name_to_values.get(name_str);
    1266                 if(values == null) {
    1267                 values = new ArrayList();
    1268                 name_to_values.put(name_str, values);
    1269                 }
    1270                 if(!values.contains(value_str)) {
    1271                 values.add(value_str);
    1272                 }
    1273                 values = null;
    1274                 value_str = null;
    1275                 name_str = null;
    1276                 attribute = null;
    1277             }
    1278             attributes = null;
    1279             set = null;
    1280             language_box.setEnabled(false);
    1281             }
    1282             sets = null;
    1283             // If this is an add remove all the attributes already present in the current set.
    1284             if(source == add_attribute) {
    1285             name.setEnabled(true);
    1286             NamedNodeMap attributes = current_set.getAttributes();
    1287             for(int i = 0; i < attributes.getLength(); i++) {
    1288                 Attr attribute = (Attr) attributes.item(i);
    1289                 String name_str = attribute.getName();
    1290                 name_to_values.remove(name_str);
    1291                 name_str = null;
    1292                 attribute = null;
    1293             }
    1294             attributes = null;
    1295             }
    1296         }
    1297         // Otherwise we actually disable the name combobox
    1298         else {
    1299             name.setEnabled(false);
    1300         }
    1301         // Now name_to_values should contain a list of unique attribute names each mapping to a list of attribute values.
    1302         for(Iterator name_iterator = name_to_values.keySet().iterator(); name_iterator.hasNext(); ) {
    1303             name.add(name_iterator.next());
    1304         }
    1305         // Now pritty up the dialog depending on the action type
    1306         if(source == add_attribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeAttribute) {
    1307             add_type = true;
    1308             Dictionary.setText(this, "GEMS.AddAttribute");
    1309             if(current_collection_file != null) {
    1310             // Name is empty in this one, however values must be the current elements in the collection.   
    1311             java.util.List values = msm.getElements();
    1312             for(int i = 0; i < values.size(); i++) {
    1313                 value.add(new NameElementWrapperEntry(values.get(i)));
    1314             }
    1315             values = null;
    1316             }
    1317             setVisible(true);
    1318         }*/
    1319                // else if(source == popupListener.menuAddAttributeAttribute){
    1320                    
    1321                 //    System.out.println("fromattrib table");
    1322                // }
    1323                // else if(source == popupListener.menuAddAttributeElement){
    1324                    
    1325                  //   System.out.println("from elements");
    1326                // }*/
     959           
    1327960        else if(current_attribute != -1) {
    1328961            this.editAttribute();
     
    1342975       //grab the table model based on what is currently selected
    1343976       switch(current_attribute_type) {
    1344        case GEMSNode.COLLECTION:
    1345            tablemodel = (AttributeTableModel) profile_attributes.getModel();
    1346            
    1347            break;
    1348977       case GEMSNode.SET:
    1349978           tablemodel = (AttributeTableModel) set_attributes.getModel();
     
    1360989           
    1361990           break;
    1362            
    1363        case GEMSNode.SUBELEMENT:
    1364            tablemodel = (AttributeTableModel) subelement_attributes.getModel();
    1365            //grab values in table
    1366            prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
    1367            prevValue = tablemodel.getValueAt(current_attribute,2).toString();
    1368            break;
    1369            
    1370991       default:
    1371992           //by default grab element_attr's
     
    14071028       
    14081029       switch(current_attribute_type) {
    1409        case GEMSNode.COLLECTION:
    1410            model = (AttributeTableModel) profile_attributes.getModel();
    1411            break;
    14121030       case GEMSNode.ELEMENT:
    14131031           model = (AttributeTableModel) element_attributes.getModel();
    14141032           break;
    1415            
    1416        case GEMSNode.SUBELEMENT:
    1417            model = (AttributeTableModel) subelement_attributes.getModel();
    1418            break;
    1419            
    14201033       case GEMSNode.SET:
    14211034           model = (AttributeTableModel) set_attributes.getModel();
     
    14491062       }
    14501063
    1451        //Is this method ever used? What's a collection attribute? --Matthew
    1452     private boolean addOrEditCollectionAttribute(AttributeTableModel model)
    1453     {
    1454         System.err.println("addOrEditCollectionAttribute was actually used!!"); //if this is ever used!!
    1455         String name_str = name.getSelectedItem().toString();
    1456         String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
    1457 
    1458         // Remove the existing attribute if this is an edit
    1459         if(!add_type && current_attribute != -1) {
    1460         String old_source = (String) model.getValueAt(current_attribute, 0);
    1461         old_source = null;
    1462         model.removeRow(current_attribute);
    1463         }
    1464 
    1465         boolean cont = true;
    1466         // Check that there isn't already an entry for this attribute
    1467         if (!model.contains(name_str, 0)) {
    1468         // Update attribute table
    1469         model.add(new Attribute(name_str, value_str));
    1470         }
    1471         // Otherwise show an error message and do not proceed
    1472         else {
    1473         cont = false;
    1474         JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    1475         }
    1476 
    1477         value_str = null;
    1478         name_str = null;
    1479         return cont;
    1480     }
    1481 
    1482 
    14831064    private boolean addOrEditSetAttribute(AttributeTableModel model)
    14841065    {
     
    15531134
    15541135            // Add the new attribute
     1136            //System.err.println("current_element is: " + current_element.toString()); //debug
    15551137            current_element.addAttribute(new_name_str, language_code, value_str);
    15561138            // Update the attribute table
     
    15711153        return cont;
    15721154    }
    1573        
    1574        //Very similar to addOrEditElementAttribute
    1575        private boolean addOrEditSubelementAttribute(AttributeTableModel model)
    1576        {
    1577        String new_name_str = name.getSelectedItem().toString();
    1578        String old_name_str = null;
    1579        String language_code = (String) language_box.getSelectedItem();
    1580        String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
    1581        String old_value_str = null;
    1582        String old_lang_code = null;
    1583        boolean edit = false;
    1584        boolean cont = false;
    1585 
    1586        if(!add_type && current_attribute != -1) //An edit
    1587            {
    1588            Attribute old_attribute = model.getAttribute(current_attribute);
    1589            old_value_str = old_attribute.value;
    1590            old_lang_code = old_attribute.language;
    1591            old_name_str = (String) subelement_attributes.getValueAt(current_attribute, 0); //get the old name.
    1592            edit = true;
    1593            }
    1594        
    1595        //Check that there isn't already an entry for this attribute
    1596        if (!model.contains(new_name_str, 0) || (edit && new_name_str.equals(old_name_str)))
    1597            {
    1598             if(edit) //If this is an edit, remove the old attribute
    1599             {
    1600                 current_subelement.removeAttribute(old_name_str, old_lang_code, old_value_str);
    1601                 model.removeRow(current_attribute);
    1602             }
    1603 
    1604            // Add the new attribute
    1605            current_subelement.addAttribute(new_name_str, language_code, value_str);
    1606            // Update the attribute table
    1607            int row = model.add(new Attribute(new_name_str, language_code, value_str));
    1608            subelement_attributes.setRowSelectionInterval(row, row);
    1609            cont = true;
    1610            }
    1611        // Otherwise show an error message and do not proceed
    1612        else
    1613            {
    1614            cont = false;
    1615            JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    1616            }
    1617        
    1618        value_str = null;
    1619        language_code = null;
    1620        new_name_str = null;
    1621        return cont;
    1622        }
    1623 
    1624 
    1625     public void dispose() {
    1626         cancel_button = null;
    1627         name = null;
    1628         name_to_values = null;
    1629         ok_button = null;
    1630         target = null;
    1631         value = null;
    1632         super.dispose();
    1633     }
    16341155    }
    16351156
    1636 
    1637     private class AddSubelementActionListener extends ModalDialog implements ActionListener {
    1638     private JButton cancel_button = null;
    1639     private JButton ok_button = null;
    1640     private JLabel element_field = null;
    1641     private NonWhitespaceField name_field = null;
     1157   
     1158    private class AddSubelementActionListener extends AddElementActionListener implements ActionListener {
    16421159
    16431160    public AddSubelementActionListener() {
    1644         super(self);
    1645         setModal(true);
    1646         setSize(ADD_ELEMENT_SIZE);
    1647         // Creation
    1648         JPanel content_pane = (JPanel) getContentPane();
    1649         content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
    1650         JPanel center_pane = new JPanel();
    1651         center_pane.setOpaque(false);
    16521161        Dictionary.setText(this, "GEMS.Popup.menuAddSubelement");
    1653 
    1654         JPanel labels_pane = new JPanel();
    1655         labels_pane.setOpaque(false);
    1656         JLabel element_label = new JLabel();
    1657         element_label.setOpaque(false);
    1658         Dictionary.setText(element_label, "GEMS.Element");
    1659         element_field = new JLabel();
    1660         element_field.setOpaque(false);
    1661 
    1662         JPanel values_pane = new JPanel();
    1663         values_pane.setOpaque(false);
    1664         JLabel name_label = new JLabel();
    1665         name_label.setOpaque(false);
    1666         Dictionary.setText(name_label, "GEMS.Name");
    1667         name_field = new NonWhitespaceField();
    1668         name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
    1669         name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
    1670         name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    1671         name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    16721162        Dictionary.setTooltip(name_field, "GEMS.Subelement_Name_Tooltip");
    1673 
    1674         JPanel button_pane = new JPanel();
    1675         button_pane.setOpaque(false);
    1676 
    1677         ok_button = new GLIButton();
    1678         ok_button.setMnemonic(KeyEvent.VK_O);
    1679         getRootPane().setDefaultButton(ok_button);
    1680         Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
    1681         cancel_button = new GLIButton();
    1682         cancel_button.setMnemonic(KeyEvent.VK_C);
    1683         Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
    1684 
    1685         TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
    1686 
    1687         // Connection
    1688         cancel_button.addActionListener(this);
    1689         ok_button.addActionListener(this);
    1690         ok_button_enabler.add(name_field);
    1691 
    1692         // Layout
    1693         labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    1694         labels_pane.setLayout(new GridLayout(2,1));
    1695         labels_pane.add(element_label);
    1696         labels_pane.add(name_label);
    1697 
    1698         values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    1699         values_pane.setLayout(new GridLayout(2,1));
    1700         values_pane.add(element_field);
    1701         values_pane.add(name_field);
    1702 
    1703         center_pane.setLayout(new BorderLayout(5,5));
    1704         center_pane.add(labels_pane, BorderLayout.WEST);
    1705         center_pane.add(values_pane, BorderLayout.CENTER);
    1706 
    1707         button_pane.setLayout(new GridLayout(1,2,0,5));
    1708         button_pane.add(ok_button);
    1709         button_pane.add(cancel_button);
    1710 
    1711         content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    1712         content_pane.setLayout(new BorderLayout());
    1713         content_pane.add(center_pane, BorderLayout.CENTER);
    1714         content_pane.add(button_pane, BorderLayout.SOUTH);
    1715 
    1716         //use size of Add Element dialog
    1717         setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);
    17181163    }
    17191164
    17201165    public void actionPerformed(ActionEvent event)
    17211166    {
    1722         //System.err.println("You chose to add a new subelement!!\n"); //debug
    17231167        Object source = event.getSource();
    1724         GEMSNode new_node = null;
    17251168        current_element = current_node.getElement(); //current_element here is used generically for a element or subelement.
    17261169
     
    17281171        {
    17291172            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
    1730            
    17311173            current_set = msm.getSet(current_element.getNamespace());
    1732             //System.err.println("current_element.getNamespace(): " + current_element.getNamespace()); //debug
    17331174            if(current_set != null)
    17341175            {
     
    17401181                    ElementWrapper subelement = current_set.addElement(name_str, language_code, current_node);
    17411182
    1742                     // Then update the tree
    1743                     new_node = model.add(current_node, subelement, GEMSNode.SUBELEMENT);
    1744                     //Expand element so can see subelement.
    1745                     mds_tree.expandPath(new TreePath(current_node.getPath()));
    1746                     //Would like to select new subelement, but this doesn't seem to work.
     1183                    final GEMSNode new_node = model.add(current_node, subelement, GEMSNode.ELEMENT); //Then update the tree.
     1184                   
     1185                    //SwingUtilities.invokeLater is used so that expandPath works on new parents.
     1186                    SwingUtilities.invokeLater(new Runnable() {
     1187                        public void run() {
     1188                        mds_tree.expandPath(new TreePath(current_node.getPath())); //Expand element so can see subelement.
     1189                        mds_tree.getSelectionModel().setSelectionPath(new TreePath(new_node)); //works, but node on tree doesn't look hilighted!!
     1190                        }
     1191                    });
    17471192
    17481193                    //Done. Finish up.
     
    17691214        else
    17701215        {
    1771             element_field.setText(current_node.toString()); //set to the name of the element
     1216            set_field.setText(current_node.toString()); //set to the name of the subelement
    17721217            name_field.setText("");
    17731218            setVisible(true);
     
    17801225        ok_button = null;
    17811226        name_field = null;
    1782         element_field = null;
     1227        set_field = null;
    17831228        super.dispose();
    17841229    }
     
    17891234    extends ModalDialog
    17901235    implements ActionListener {
    1791     private JButton cancel_button = null;
    1792     private JButton ok_button = null;
    1793     private JLabel set_field = null;
    1794     private NonWhitespaceField name_field = null;
     1236    protected JButton cancel_button = null;
     1237    protected JButton ok_button = null;
     1238    protected JLabel set_field = null;
     1239    protected NonWhitespaceField name_field = null;
    17951240    public AddElementActionListener() {
    17961241        super(self);
     
    18821327            String language_code = config.getLanguage();
    18831328            ElementWrapper element = current_set.addElement(name_str, language_code, null);
     1329
    18841330            // Then update the tree
    18851331            model.add(current_node, element, GEMSNode.ELEMENT);
    1886             mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set.
    1887 
     1332            //SwingUtilities.invokeLater is used so that expandPath works on new parents.
     1333            SwingUtilities.invokeLater(new Runnable() {
     1334                public void run() {
     1335                mds_tree.expandPath(new TreePath(current_node.getPath())); //expand set.
     1336                }
     1337            });
     1338           
    18881339            // Done
    18891340            element = null;
     
    19291380        name_field = null;
    19301381        set_field = null;
    1931         ///ystem.err.println("Dispose AddElementActionListener");
    19321382        super.dispose();
    19331383    }
    19341384    }
    19351385     
    1936     private class AddFileActionListener
    1937     extends ModalDialog
    1938     implements ActionListener {
    1939     private JButton cancel_button = null;
    1940     private JButton ok_button = null;
    1941     private JTextField name_field = null;
    1942     public AddFileActionListener() {
    1943         super(self);
    1944         setModal(true);
    1945         setSize(ADD_FILE_SIZE);
    1946         // Creation
    1947         JPanel content_pane = (JPanel) getContentPane();
    1948         content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
    1949         JPanel center_pane = new JPanel();
    1950         center_pane.setOpaque(false);
    1951         JPanel profile_pane = new JPanel();
    1952         profile_pane.setOpaque(false);
    1953         JLabel profile_label = new JLabel();
    1954         profile_label.setOpaque(false);
    1955         Dictionary.setText(profile_label, "GEMS.Profile");
    1956 
    1957         JPanel name_pane = new JPanel();
    1958         name_pane.setOpaque(false);
    1959         JLabel name_label = new JLabel();
    1960         name_label.setOpaque(false);
    1961         Dictionary.setText(name_label, "GEMS.Name");
    1962         name_field = new JTextField();
    1963         name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
    1964         name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
    1965         name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    1966         name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    1967         Dictionary.setTooltip(name_field, "GEMS.Profile_Name_Tooltip");
    1968 
    1969         JPanel button_pane = new JPanel();
    1970         button_pane.setOpaque(false);
    1971 
    1972         ok_button = new GLIButton();
    1973         ok_button.setMnemonic(KeyEvent.VK_O);
    1974         Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
    1975         cancel_button = new GLIButton();
    1976         cancel_button.setMnemonic(KeyEvent.VK_C);
    1977         Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
    1978 
    1979         TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
    1980 
    1981         // Connection
    1982         cancel_button.addActionListener(this);
    1983         ok_button.addActionListener(this);
    1984         ok_button_enabler.add(name_field);
    1985 
    1986         // Layout
    1987         profile_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    1988         profile_pane.setLayout(new BorderLayout());
    1989         profile_pane.add(profile_label, BorderLayout.CENTER);
    1990 
    1991         name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
    1992         name_pane.setLayout(new BorderLayout(5,0));
    1993         name_pane.add(name_label, BorderLayout.WEST);
    1994         name_pane.add(name_field, BorderLayout.CENTER);
    1995 
    1996         center_pane.setLayout(new GridLayout(2,1,0,0));
    1997         center_pane.add(profile_pane);
    1998         center_pane.add(name_pane);
    1999 
    2000         button_pane.setLayout(new GridLayout(1,2,0,5));
    2001         button_pane.add(ok_button);
    2002         button_pane.add(cancel_button);
    2003 
    2004         content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    2005         content_pane.setLayout(new BorderLayout());
    2006         content_pane.add(center_pane, BorderLayout.CENTER);
    2007         content_pane.add(button_pane, BorderLayout.SOUTH);
    2008 
    2009         setLocation((config.screen_size.width - ADD_FILE_SIZE.width) / 2, (config.screen_size.height - ADD_FILE_SIZE.height) / 2);
    2010     }
    2011     /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
    2012      * @param event An <strong>ActionEvent</strong> containing information about the event.
    2013      */
    2014     public void actionPerformed(ActionEvent event) {
    2015         Object source = event.getSource();
    2016         if(source == ok_button) {
    2017         String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
    2018         // Ensure that this source doesn't already exist.
    2019 //      if(!msm.profiler.containsSource(name_str)) {
    2020 //          // Add source with empty hashmap of actions.
    2021 //          msm.profiler.addSource(name_str);
    2022 //          // Add to tree
    2023 //          model.add(model.getProfileNode(), name_str, GEMSNode.COLLECTION);
    2024 //          setVisible(false);
    2025 //      }
    2026         // Otherwise warn the user and don't hide the prompt.
    2027         // else {
    2028         JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.File_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    2029         // }
    2030         name_str = null;
    2031         }
    2032         else if(source == cancel_button) {
    2033         setVisible(false);
    2034         }
    2035         else {
    2036         name_field.setText("");
    2037         setVisible(true);
    2038         }
    2039         source = null;
    2040     }
    2041 
    2042     public void dispose() {
    2043         cancel_button = null;
    2044         ok_button = null;
    2045         name_field = null;
    2046         ///ystem.err.println("Dispose AddFileActionListener");
    2047         super.dispose();
    2048     }
    2049     }
    2050 
     1386   
    20511387    private class AddSetActionListener
    20521388    extends ModalDialog
     
    21351471            //add sets to existingSetJComboBox
    21361472           
    2137             //String tempstr = new String();
    21381473            JLabel dummyl = new JLabel();
    21391474            Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
     
    21801515        Object source = event.getSource();
    21811516           
    2182            
    2183           // if(a_set_exists_with_this_namespace(namespace_field.getText()) == false){
    21841517        if(source == ok_button) {
    21851518                //this code below handles whether we inherit from an existing set or not
     
    22891622        ok_button = null;
    22901623        name_field = null;
    2291         ///ystem.err.println("Dispose AddSetActionListener");
    22921624        super.dispose();
    22931625    }
     
    23271659        cancel_button.setMnemonic(KeyEvent.VK_C);
    23281660        Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
    2329         TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
     1661        //TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
    23301662
    23311663        // Connection
     
    23391671            Dictionary.setText(inheritJLabel, "GEMS.inheritMetadataSet");
    23401672       
    2341             int getSetsLen = msm.getSets().toArray().length;
    2342             Vector theSets = msm.getSets();
    23431673            File[] col_dir = new File(Configuration.gsdl_path + "/collect").listFiles();
    23441674           
     
    23581688           
    23591689            existingSetJComboBox.setSelectedIndex(0);
    2360             //String tempstr = new String();
    23611690            JLabel dummyl = new JLabel();
    23621691            Dictionary.setText(dummyl, "GEMS.Add_Set.No_Inherit");
     
    24161745        }
    24171746        else {
    2418         //name_field.setText("");
    24191747        setVisible(true);
    24201748        }
     
    24271755    }
    24281756    }
    2429    
    2430 
    2431 
    2432     /** This listener is responsible for keeping the root node of a value tree expanded where and when possible. */
    2433     private class KeepTreeRootExpandedListener
    2434     implements TreeModelListener {
    2435     /** Invoked after a node (or a set of siblings) has changed in some way. */
    2436     public void treeNodesChanged(TreeModelEvent e) {
    2437     }
    2438         /** Invoked after nodes have been inserted into the tree. */
    2439     public void treeNodesInserted(TreeModelEvent e) {
    2440         //  if(element_values != null && element_values.getModel() != null && element_values.getModel().getRoot() != null) {
    2441         //  element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
    2442         //  }
    2443     }
    2444     /** Invoked after nodes have been removed from the tree. */
    2445     public void treeNodesRemoved(TreeModelEvent e) {
    2446     }
    2447     /** Invoked after the tree has drastically changed structure from a given node down. */
    2448     public void treeStructureChanged(TreeModelEvent e) {
    2449         // element_values.expandPath(new TreePath(element_values.getModel().getRoot()));
    2450     }
    2451     }
    2452 
     1757
     1758    /*
     1759      Class to handle removing set or element attributes.
     1760    */
    24531761    private class RemoveAttributeActionListener
    24541762    implements ActionListener, KeyListener {
     
    24571765       Any implementation of KeyListener must include these mothods.
    24581766       When the DELETE key is pressed, fire the actionPerformed event.
     1767       @param e A <strong>KeyEvent</strong> containing information about the event.
    24591768    */
    24601769    public void keyTyped(KeyEvent e){
     
    24661775            {
    24671776                //DELETE key pressed
    2468                 actionPerformed((ActionEvent)null);
     1777                actionPerformed((ActionEvent)null); //is there a better way?
    24691778            }
    24701779        }
     
    24821791        if(result == 0) {
    24831792            ignore = true;
    2484             // Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected
    2485             // Has a collection file been selected...
    2486             if(current_collection_file != null) {
    2487             // Remove a profile
    2488             String source = (String) profile_attributes.getValueAt(current_attribute, 0);
    2489             // !!! msm.profiler.removeAction(current_collection_file, source);
    2490             source = null;
    2491             // Refresh table
    2492             ((AttributeTableModel)profile_attributes.getModel()).removeRow(current_attribute);
    2493             }
    2494             // or has an element been selected
    2495             else if(current_element != null) {
     1793            //Attributes are tricky little beasties, as they can come from several different places and depend upon what other little beasties have been selected
     1794            //Has an element been selected
     1795            if(current_element != null) {
    24961796            // Remove element attribute
    24971797            String name = (String) element_attributes.getValueAt(current_attribute, 0);
     
    25101810            ((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute);
    25111811            }
    2512             else if(current_subelement != null)
    2513             {
    2514                 //Remove subelement attribute
    2515                 String name = (String)subelement_attributes.getValueAt(current_attribute, 0);
    2516                 String language = (String) subelement_attributes.getValueAt(current_attribute, 1);
    2517                 String value = (String) subelement_attributes.getValueAt(current_attribute, 2);
    2518                 current_subelement.removeAttribute(name, language, value);
    2519 
    2520                 //Refresh table
    2521                 ((AttributeTableModel)subelement_attributes.getModel()).removeRow(current_attribute);
    2522             }
    25231812            ignore = false;
    25241813                   
    2525                      atLeastOneSetChanged= true;
     1814            atLeastOneSetChanged= true;
    25261815        }
    25271816        }
     
    25331822    }
    25341823
    2535     /**
    2536        Class to handle deletion of subelements.
    2537        This class can be created from either PopupHandler or KeyPressedHandler. KeyPressedHandler passes a null ActionEvent!!
    2538        @author: Matthew Whyte
    2539        @Date last modified: 18/01/05
    2540                             25/01/05
    2541     */
    2542     private class RemoveSubelementActionListener implements ActionListener {
    2543     /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
    2544      * @param event An <strong>ActionEvent</strong> containing information about the event.
    2545      */
    2546     public void actionPerformed(ActionEvent event)
    2547     {
    2548         if(current_subelement != null)
    2549         {
    2550             int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Subelement")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
    2551             if(result ==0) //Continue with remove
    2552             {
    2553                 TreeNode selPath = current_node.getParent();
    2554                 GEMSNode parent = (GEMSNode)selPath;
    2555                 current_element = parent.getElement();
    2556 
    2557                 ignore = true;
    2558                 msm.removeElement(current_subelement, current_element); //remove the subelement.
    2559 
    2560                 // Clear selection
    2561                 mds_tree.clearSelection();
    2562                 model.remove(current_node); //This is the new way of doing things :-)
    2563                 card_layout.show(details_pane, BLANK); //Show a blank panel.
    2564                 ignore = false;
    2565                
    2566                 atLeastOneSetChanged = true;
    2567             }
    2568         }
    2569         else
    2570         {
    2571             System.err.println("No subelement is selected."); //This should not happen
    2572         }
    2573     }
    2574 
    2575     }
    2576 
     1824    /*
     1825      Class to handle deletion of elements (including subelements).
     1826
     1827      Last modified 2/02/05 by Matthew Whyte
     1828     */
    25771829    private class RemoveElementActionListener
    25781830    implements ActionListener {
     
    25871839        // Remove this attribute
    25881840        if(result == 0) {
     1841            //Get the parent element
     1842            GEMSNode parent_node = (GEMSNode)current_node.getParent();
     1843            ElementWrapper parent_wrapped = parent_node.getElement();
     1844
    25891845            ignore = true;
    2590             //System.err.println("Current element's getElement: " + current_element.getElement()); //Debug
    2591             msm.removeElement(current_element, null);
     1846            msm.removeElement(current_element, parent_wrapped);
    25921847            // Clear selection
    25931848            mds_tree.clearSelection();
    2594             model.remove(current_element.getName(), GEMSNode.ELEMENT); //Need to use .getName() not .toString!!
    2595 
    2596             // Meanwhile disable/enable controls given we had an element selected, but no longer do.
    2597             //remove_element.setEnabled(false);
     1849            model.remove(current_node);
     1850
    25981851            // Show a blank panel.
    25991852            card_layout.show(details_pane, BLANK);
     
    26041857        }
    26051858        else {
    2606         ///ystem.err.println("No current element selected.");
     1859        System.err.println("No element currently selected."); //This should not happen!
    26071860        }
    26081861    }
    26091862    }
    2610 
    2611  
    2612 
    2613 
    2614     private class RemoveFileActionListener
    2615     implements ActionListener {
    2616     /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to provide an editing prompt.
    2617      * @param event An <strong>ActionEvent</strong> containing information about the event.
    2618      */
    2619     public void actionPerformed(ActionEvent event) {
    2620         if(current_collection_file != null) {
    2621         int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.File")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
    2622         // Remove the current collection file profile from the profiler.
    2623         if(result == 0) {
    2624             ignore = true;
    2625  
    2626             // Clear selection
    2627             mds_tree.clearSelection();
    2628             model.remove(current_collection_file, GEMSNode.COLLECTION);
    2629             card_layout.show(details_pane, BLANK); //Show a blank panel.
    2630             ignore = false;
    2631         }
    2632         }
    2633     }
    2634     }
    2635 
    26361863
    26371864
     
    26391866       Class to handle renaming of a set and/or it's namespace.
    26401867
    2641        Author: Matthew Whyte
     1868       @author: Matthew Whyte
    26421869       Date last modified: 10/01/05
    26431870    */
     
    27361963                }
    27371964            }
    2738            
    27391965            return flag;
    27401966        }
     
    27611987                //Hide the set that are about to rename
    27621988                mds_tree.clearSelection();
    2763                 model.remove(current_set.toString(), GEMSNode.SET);
     1989                model.remove(current_node);
    27641990
    27651991                //Rename set & namespace
     
    28092035    }
    28102036
    2811     /**
    2812        Class to handle renaming of a subelement
    2813 
    2814        Author: Matthew Whyte
    2815        Date last modified: 18/01/05
    2816      */
    2817     private class RenameSubelementActionListener extends RenameElementActionListener implements ActionListener {
    2818    
    2819     /**
    2820        Any implementation of ActionListener must include this method so that we can be informed when an action has occured.
    2821        @param event An <string>ActionEvent</strong> containing information about the event.
    2822     */
    2823     public void actionPerformed(ActionEvent event)
    2824     {
    2825         Object source = event.getSource();
    2826 
    2827         if(source == ok_button)
    2828         {
    2829             TreeNode selPath = current_node.getParent();
    2830             GEMSNode parent = (GEMSNode)selPath;
    2831             current_element = parent.getElement();
    2832             //MetadataSet currentSet = msm.getSet(current_subelement.getNamespace());
    2833             String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
    2834 
    2835             if(!current_element.containsSubelement(name_str)) //Hopefully this works!
    2836                 {   
    2837                 //Hide the element that are about to rename
    2838                 mds_tree.clearSelection();
    2839                 model.remove(current_node);
    2840                
    2841                 msm.renameElement(current_subelement, name_str); //rename the element
    2842                 model.add(parent, current_subelement, GEMSNode.SUBELEMENT);
    2843 
    2844                 //Finish up
    2845                 ignore = false;   
    2846                 atLeastOneSetChanged = true;
    2847                 setVisible(false);
    2848                 }
    2849            
    2850             // Otherwise show an error message and do not proceed.
    2851             else
    2852                 {
    2853                 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Subelement_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    2854                 }
    2855 
    2856             name_str = null;
    2857         }
    2858        
    2859         else if(source == cancel_button)
    2860         {
    2861             setVisible(false); //hide dialog
    2862         }
    2863         else
    2864         {
    2865             Dictionary.setText(this, "GEMS.Popup.menuRenameSubelement"); //Set title of dialog
    2866             name_field.setText(current_subelement.getNameOnly()); //show old name
    2867             setVisible(true); //Show the dialog
    2868         }
    2869            
    2870         source = null;
    2871     }
    2872     }
     2037   
    28732038
    28742039 /**
    28752040       Class to handle renaming of an element.
    28762041
    2877        Author: Matthew Whyte
     2042       @author: Matthew Whyte
    28782043       Date last modified: 10/01/05
    28792044    */
     
    29702135            TreeNode selPath = current_node.getParent();
    29712136            GEMSNode parent = (GEMSNode)selPath;
    2972             GEMSNode new_node = null;
    29732137            MetadataSet currentSet = msm.getSet(current_element.getNamespace());
    29742138            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
    2975             GValueModel value_model = msm.getValueTree(current_element);
    2976  
     2139            GEMSNode new_node = null;
     2140
    29772141            // If this element doesn't already exist.
    29782142            if(!currentSet.containsElement(name_str)) //Do the renaming!
    29792143            {   
    2980                 //Hide the element that are about to rename
    2981                 //mds_tree.clearSelection();
    2982                 model.remove(current_element.getName(), GEMSNode.ELEMENT);
     2144                model.remove(current_node); //Hide the element that are about to rename
     2145                msm.renameElement(current_element, name_str); //rename the element
     2146                //Add the new element
     2147                new_node = model.add(parent, current_element, GEMSNode.ELEMENT);
    29832148               
    2984                 msm.renameElement(current_element, name_str); //rename the element
     2149                //mds_tree.setSelectionPath(new_node_path); //would like to do this but doesn't hilight tree :-(
     2150                card_layout.show(details_pane, BLANK); // Show a blank panel.
    29852151               
    2986                 new_node = model.add(parent, current_element, GEMSNode.ELEMENT);
    2987                 TreePath new_node_path = new TreePath(new_node.getPath());
    2988 
    2989                 value_model.nodeChanged((TreeNode)current_node); //trial!
    2990                 value_model.nodeStructureChanged((TreeNode)current_node);
    2991                 mds_tree.repaint();
    2992 
    2993                 //mds_tree.setSelectionPath(new_node_path);
    2994                 //Could now select the new element, but for now will just clean up ;-)
    2995                 // Disable/enable controls given we had an element selected, but no longer do.
    2996                 //card_layout.show(details_pane, BLANK); // Show a blank panel.
    2997                 //ignore = false;
    2998                
     2152                //finish up
    29992153                currentSet.setSetChanged(true);
    30002154                atLeastOneSetChanged = true;
     
    30372191    /**
    30382192       Class to handle DELETE key presses on the tree.
    3039        The class then fires the appropriate event to remove that subelement/element/set.
     2193       The class then fires the appropriate event to remove that element/set.
    30402194       Attributes in the table are handled directly by the RemoveAttributeActionListener
    30412195
     
    30862240        if(cont)
    30872241        {
    3088            
    30892242            //Check to see if pressed on Set or Element.
    30902243            TreePath selPath = mds_tree.getSelectionPath();
    30912244            GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
    30922245           
    3093             if(t.type == T_SUBELEMENT) //Remove the subelement
     2246            if(t.type == T_ELEMENT) //Remove the element
    30942247            {
    3095                 RemoveSubelementActionListener removeSubelement = new RemoveSubelementActionListener();
    3096                 removeSubelement.actionPerformed((ActionEvent)null);
    3097             }
    3098             else if(t.type == T_ELEMENT) //Remove the element
    3099             {
    3100                 //System.err.println("element");
    31012248                RemoveElementActionListener removeElement = new RemoveElementActionListener();
    31022249                removeElement.actionPerformed((ActionEvent)null);
    31032250            }
    3104            
    3105             else if(t.type == T_ROOT)
    3106             {
    3107                 //Do nothing
    3108                 System.err.println("Tree type of ROOT: this should not happen!");
    3109             }
    31102251            else if(t.type == T_SET) //Remove the whole set
    31112252            {
    3112                 //System.err.println("set");
    31132253                RemoveSetActionListener removeSet = new RemoveSetActionListener();
    31142254                removeSet.actionPerformed((ActionEvent)null);
     
    31182258    }
    31192259   
    3120 
    3121    
    3122 
    31232260
    31242261    private class RemoveSetActionListener
     
    31512288            // Clear selection
    31522289            mds_tree.clearSelection();
    3153             model.remove(current_set.toString(), GEMSNode.SET);
     2290            model.remove(current_node);
    31542291            card_layout.show(details_pane, BLANK); //Show a blank panel.
    31552292            ignore = false;
    31562293 
    3157         }
    3158         }
    3159     }
    3160     }
    3161 
    3162     /** This class will remove the currently selected metadata or profile value when any registered control is actioned. Note that removing a value acts differently from the other removes in that if you remove a value which is still assigned somewhere the values are restored next time said assignment is viewed. This turned out far easier and reasonable to code than attempting to remove all remaining values when you delete its reference in the GValueModel. */
    3163     private class RemoveValueActionListener
    3164     implements ActionListener {
    3165     /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to
    3166      * @param event An <strong>ActionEvent</strong> containing information about the event.
    3167      */
    3168     public void actionPerformed(ActionEvent event) {
    3169         if(current_value_node != null) {   
    3170         int result = JOptionPane.showOptionDialog(self, Dictionary.get("GEMS.Confirm_Removal", Dictionary.get("GEMS.Value")), Dictionary.get("GEMS.Confirm_Removal_Title"), JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, dialog_options, dialog_options[0]);
    3171         // Remove the current selected value
    3172         if(result == 0) {
    3173             ignore = true;
    3174             ignore = false; //What the heck?? --Matthew
    3175                    
    3176                     //does this ever get called?
    3177                     System.out.println("\nGEMS.RemovevalueActionListener called");
    3178                     atLeastOneSetChanged = true;
    31792294        }
    31802295        }
     
    32472362        {
    32482363            current_attribute = table.getSelectedRow();
    3249             /*
    3250             if((current_attribute = table.getSelectedRow()) != -1)
    3251             {           
    3252             }
    3253             else
    3254             {
    3255                 current_attribute = -1;
    3256             }
    3257             */
    3258         }
    3259     }
    3260     }
    3261    
    3262     private class ElementValuesTreeSelectionListener
    3263     implements TreeSelectionListener {
    3264     public void valueChanged(TreeSelectionEvent event) {
    3265         if(element_values.getSelectionCount() > 0) {
    3266         // Retrieve the selected value node.
    3267         TreePath selected_path = element_values.getSelectionPath();
    3268         current_value_node = (GValueNode) selected_path.getLastPathComponent();
    3269         }
    3270         else {
    3271         current_value_node = null;
    3272         }
     2364        }
    32732365    }
    32742366    }
     
    32782370    public void valueChanged(TreeSelectionEvent event) {
    32792371        if(!ignore) {
    3280         GValueModel value_model = null;
    32812372        // Clear all variables based on previous tree selection
    3282         current_collection_file = null;
    32832373        current_element = null;
    32842374        current_set = null;
     
    32912381        current_attribute_type = current_node.getType();
    32922382        switch(current_attribute_type) {
    3293         case GEMSNode.COLLECTION:
    3294             current_collection_file = (String) current_node.getUserObject();
    3295             atm = current_node.getModel();
    3296             if(atm == null) {
    3297             attributes = new TreeSet();
    3298      
    3299             atm = new AttributeTableModel(attributes, Dictionary.get("GEMS.Source"), Dictionary.get("GEMS.Target"), Dictionary.get("GEMS.Ignore"));
    3300             }
    3301             profile_attributes.setModel(atm);
    3302             atm.setScrollPane(profile_attributes_scroll);
    3303             atm.setTable(profile_attributes);
    3304 
    3305             card_layout.show(details_pane, PROFILE);
    3306             break;
    3307 
    3308         case GEMSNode.SUBELEMENT:
    3309             current_subelement = current_node.getSubelement();
    3310            
    3311             atm = current_node.getModel();
    3312             if(atm == null) {
    3313             atm = new AttributeTableModel(current_subelement.getAttributes(), Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Language_Code"), Dictionary.get("GEMS.Value"), "");
    3314             }
    3315 
    3316             subelement_attributes.setModel(atm);
    3317             atm.setScrollPane(subelement_attributes_scroll);
    3318             atm.setTable(subelement_attributes);
    3319             //System.err.println("atm is: " + atm); //debug
    3320 
    3321             card_layout.show(details_pane, SUBELEMENT);
    3322             break;
    33232383
    33242384        case GEMSNode.ELEMENT:
     
    33332393            atm.setTable(element_attributes);
    33342394
    3335             // Be careful not to add the keep_root_expanded_listener over and over!
    3336             value_model = msm.getValueTree(current_element);
    3337             if(value_model != null) {
    3338             value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there
    3339             value_model.addTreeModelListener(keep_root_expanded_listener); // Then add again.
    3340             element_values.setModel(value_model);
    3341             element_values_layout.show(element_values_pane, VALUES);
    3342             }
    3343             else {
    3344             //this shouldn't happen!
    3345             element_values_layout.show(element_values_pane, BLANK);
    3346             }
    33472395            card_layout.show(details_pane, ELEMENT);
    33482396            break;
     
    33712419            attributes = null;
    33722420            break;
    3373         case GEMSNode.PROFILER:
    33742421
    33752422        default:
     
    33952442
    33962443    //PopupListener is our main manager for all right-click popups
    3397   class PopupListener extends MouseAdapter implements ActionListener{
    3398       JPopupMenu setPopup;
    3399       JPopupMenu subelementPopup;
    3400       JPopupMenu elementPopup;
    3401       JPopupMenu attributePopup;
    3402       //all of our popup menu items EVER!
    3403       JMenuItem menuAddSet;
    3404       JMenuItem menuRenameSet;
    3405       JMenuItem menuAddElement;
    3406       JMenuItem menuAddAttributeSet;
    3407 
    3408       JMenuItem menuRenameSubelement;
    3409       JMenuItem menuDeleteSubelement;
    3410       JMenuItem menuAddAttributeSubelement;
    3411       JMenuItem menuRenameElement;
    3412      
    3413       JMenuItem menuDeleteElement;
    3414       JMenuItem menuAddAttributeElement;
    3415       JMenuItem menuAddSubelement;
    3416       JMenuItem menuAddSubelementCopy;
    3417      
    3418       JMenuItem menuEditValue;
    3419       JMenuItem menuDeleteAttribute;
    3420       JMenuItem menuAddAttributeAttribute;
    3421      
    3422       JMenuItem menuRemoveSet;
    3423      
     2444    class PopupListener extends MouseAdapter implements ActionListener{
     2445    JPopupMenu setPopup;
     2446    JPopupMenu elementPopup;
     2447    JPopupMenu attributePopup;
     2448
     2449    //all of our popup menu items EVER!
     2450    JMenuItem menuAddAttributeSet;
     2451    JMenuItem menuAddElement;
     2452    JMenuItem menuRenameSet;
     2453    JMenuItem menuRemoveSet;
     2454
     2455    JMenuItem menuAddAttributeElement;
     2456    JMenuItem menuAddSubelement;
     2457    JMenuItem menuRenameElement;
     2458    JMenuItem menuDeleteElement;
     2459
     2460    JMenuItem menuAddAttributeAttribute;
     2461    JMenuItem menuEditValue;
     2462    JMenuItem menuDeleteAttribute;
     2463   
    34242464        GEMS GEMSRef = null;
    34252465        PopupListener(GEMS g) {
    34262466        setPopup = new JPopupMenu();
    3427         subelementPopup = new JPopupMenu();
    34282467        elementPopup = new JPopupMenu();
    34292468        attributePopup = new JPopupMenu();
     
    34312470            //reference to our parent(GEMS), because some of the actionlisteners would not
    34322471            //work unless they were declared in GEMS, and I need a way to reference GEMS
    3433            
    34342472        GEMSRef = g;
    34352473       
    3436         //create the MenuItems
    3437        
    3438         //set related popups
    3439         menuAddSet = new JMenuItem();
    3440            
     2474        //Create the menu items
     2475        menuAddAttributeSet = new JMenuItem();
     2476        Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");
     2477        menuAddElement =new JMenuItem();
     2478        Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");
    34412479        menuRenameSet = new JMenuItem();
    34422480        Dictionary.setText(menuRenameSet,"GEMS.Popup.menuRenameSet");
    3443        
    3444         menuAddElement =new JMenuItem();
    3445        // Dictionary.setText(menuAddElement,"GEMS.Popup.menuAddElement");
    3446         Dictionary.setText(menuAddElement,"GEMS.Add_Element_Tooltip");
    3447        
    3448         menuAddAttributeSet = new JMenuItem();
    3449        // Dictionary.setText(menuAddAttributeSet, "GEMS.Popup.menuAddAttribute");
    3450         Dictionary.setText(menuAddAttributeSet, "GEMS.Add_Attribute_Tooltip");
    3451        
    3452            
    34532481            menuRemoveSet = new JMenuItem();
    3454        Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip");
    3455        
    3456             //subelement related GEMS.Popups
    3457             menuRenameSubelement = new JMenuItem();
    3458             Dictionary.setText(menuRenameSubelement,"GEMS.Popup.menuRenameSubelement");
    3459            
    3460             menuDeleteSubelement=new JMenuItem();
    3461             Dictionary.setText(menuDeleteSubelement,"GEMS.Popup.menuRemoveSubelement");
    3462            
    3463             menuAddAttributeSubelement=new JMenuItem();
    3464            // Dictionary.setText(menuAddAttributeSubelement,"GEMS.Popup.menuAddAttribute");
    3465              Dictionary.setText(menuAddAttributeSubelement,"GEMS.Add_Attribute_Tooltip");
    3466            
    3467             //element related GEMS.Popups
     2482        Dictionary.setText(menuRemoveSet, "GEMS.Popup.menuRemoveSet");
     2483           
     2484            menuAddAttributeElement=new JMenuItem();
     2485            Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute");
     2486        menuAddSubelement=new JMenuItem();
     2487            Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement");
    34682488            menuRenameElement=new JMenuItem();
    34692489            Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");
    3470         // Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");
    3471            
    34722490            menuDeleteElement=new JMenuItem();
    3473            // Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement");
    3474             Dictionary.setText(menuDeleteElement,"GEMS.Remove_Element_Tooltip");
    3475            
    3476             menuAddAttributeElement=new JMenuItem();
    3477             //Dictionary.setText(menuAddAttributeElement,"GEMS.Popup.menuAddAttribute");
    3478             Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip");
    3479            
    3480             menuAddSubelement=new JMenuItem();
    3481             Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement");
    3482              //Dictionary.setText(menuAddSubelement,"GEMS.Add_Subelement");
    3483         menuAddSubelementCopy = new JMenuItem(); //A copy of menuAddSubelement
    3484         Dictionary.setText(menuAddSubelementCopy, "GEMS.Popup.menuAddSubelement");
    3485        
    3486             //attribute related GEMS.Popups
     2491        Dictionary.setText(menuDeleteElement,"GEMS.Popup.menuRemoveElement");
     2492
     2493        menuAddAttributeAttribute=new JMenuItem();
     2494        Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute");
    34872495            menuEditValue=new JMenuItem();
    3488             //Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue");
    3489             Dictionary.setText(menuEditValue,"GEMS.Edit_Value_Tooltip");
    3490            
     2496            Dictionary.setText(menuEditValue,"GEMS.Popup.menuEditValue");
    34912497            menuDeleteAttribute=new JMenuItem();
    3492            // Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute");
    3493             Dictionary.setText(menuDeleteAttribute,"GEMS.Remove_Attribute_Tooltip");
    3494            
    3495             menuAddAttributeAttribute=new JMenuItem();
    3496            // Dictionary.setText(menuAddAttributeAttribute,"GEMS.Popup.menuAddAttribute");
    3497              Dictionary.setText(menuAddAttributeAttribute,"GEMS.Add_Attribute_Tooltip");
     2498        Dictionary.setText(menuDeleteAttribute,"GEMS.Popup.menuRemoveAttribute");
    34982499             
    3499              //start Associate the menu items with the appropriate popups:
    3500          setPopup.add(menuAddAttributeSet);
    3501          setPopup.add(menuAddElement);
    3502              setPopup.add(menuRenameSet);
    3503          setPopup.add(menuRemoveSet);
    3504            
    3505          elementPopup.add(menuAddAttributeElement);
    3506          elementPopup.add(menuAddSubelement);
    3507              elementPopup.add(menuRenameElement);
    3508              elementPopup.add(menuDeleteElement);
    3509              
    3510          subelementPopup.add(menuAddAttributeSubelement);
    3511          //subelementPopup.add(menuAddSubelementCopy);
    3512              subelementPopup.add(menuRenameSubelement);
    3513              subelementPopup.add(menuDeleteSubelement);
    3514            
    3515          attributePopup.add(menuAddAttributeAttribute);
    3516              attributePopup.add(menuEditValue);
    3517              attributePopup.add(menuDeleteAttribute);
    3518              //end Associate the menu items with the appropriate popups:
    3519              
    3520              menuRemoveSet.addActionListener(new RemoveSetActionListener());
    3521              menuAddElement.addActionListener(new AddElementActionListener());
    3522              menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
    3523              menuRenameSubelement.addActionListener(new RenameSubelementActionListener());
    3524              menuDeleteSubelement.addActionListener(new RemoveSubelementActionListener());
    3525              menuAddAttributeSubelement.addActionListener(new AddOrEditAttributeActionListener());
    3526              
    3527          menuRenameSet.addActionListener(new RenameSetActionListener());
    3528              menuRenameElement.addActionListener(new RenameElementActionListener());
    3529              menuDeleteElement.addActionListener(new RemoveElementActionListener());
    3530              menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
    3531              menuAddSubelement.addActionListener(new AddSubelementActionListener());
    3532          menuAddSubelementCopy.addActionListener(new AddSubelementActionListener());
    3533              menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
    3534              menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener());
    3535              menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener());
    3536            
     2500        //Associate the menu items with the appropriate popups:
     2501        setPopup.add(menuAddAttributeSet);
     2502        setPopup.add(menuAddElement);
     2503        setPopup.add(menuRenameSet);
     2504        setPopup.add(menuRemoveSet);
     2505           
     2506        elementPopup.add(menuAddAttributeElement);
     2507        elementPopup.add(menuAddSubelement);
     2508        elementPopup.add(menuRenameElement);
     2509        elementPopup.add(menuDeleteElement);
     2510           
     2511        attributePopup.add(menuAddAttributeAttribute);
     2512        attributePopup.add(menuEditValue);
     2513        attributePopup.add(menuDeleteAttribute);
     2514       
     2515        //Add appropriate action listeners to the menu items.
     2516        menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
     2517        menuAddElement.addActionListener(new AddElementActionListener());
     2518        menuRenameSet.addActionListener(new RenameSetActionListener());
     2519        menuRemoveSet.addActionListener(new RemoveSetActionListener());
     2520       
     2521        menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
     2522        menuAddSubelement.addActionListener(new AddSubelementActionListener());
     2523        menuRenameElement.addActionListener(new RenameElementActionListener());
     2524        menuDeleteElement.addActionListener(new RemoveElementActionListener());
     2525       
     2526        menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
     2527        menuDeleteAttribute.addActionListener(new RemoveAttributeActionListener());
     2528        menuAddAttributeAttribute.addActionListener(new AddOrEditAttributeActionListener());           
    35372529        }
     2530
    35382531        public void mouseClicked(MouseEvent e) {
    35392532            maybeShowPopup(e);
     
    35412534        public void mousePressed(MouseEvent e){
    35422535        maybeShowPopup(e);
    3543        
    3544    }
     2536    }
    35452537        public void mouseReleased(MouseEvent e) {
    35462538            maybeShowPopup(e);
     
    35482540
    35492541        private void maybeShowPopup(MouseEvent e) {
    3550            
    3551          int selRow = mds_tree.getRowForLocation(e.getX(), e.getY());
    3552      TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY());
    3553      Point p = null;
     2542        TreePath selPath = mds_tree.getPathForLocation(e.getX(), e.getY());
     2543        Point p = null;
    35542544            if (e.isPopupTrigger()) {
    3555                
    3556              if(e.getSource() == mds_tree) {
    3557                 try {
    3558                
    3559                     GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
    3560            
    3561             mds_tree.setSelectionPath(selPath); //Select node right-clicked on
    3562            
    3563             if(t.type == T_ELEMENT){
     2545       
     2546        if(e.getSource() == mds_tree) {
     2547            try {
     2548            GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
    35642549           
    3565             elementPopup.show(e.getComponent(),
    3566                       e.getX(), e.getY());
     2550            mds_tree.setSelectionPath(selPath); //Select node right-clicked on
     2551           
     2552            if(t.type == T_ELEMENT){
     2553                elementPopup.show(e.getComponent(), e.getX(), e.getY());
     2554            }
     2555            else if(t.type == T_SET){
     2556                setPopup.show(e.getComponent(), e.getX(), e.getY());
     2557            }
    35672558            }
    3568 
    3569             else if(t.type == T_SUBELEMENT)
    3570             {
    3571                 subelementPopup.show(e.getComponent(), e.getX(), e.getY());
    3572             }
    3573 
    3574             else if(t.type == T_ROOT){
    3575            
    3576             setPopup.show(e.getComponent(),
    3577                       e.getX(), e.getY());
     2559            catch(Exception NullPointerException) {
     2560            //Right-clicked in tree area, but no item to select. Do nothing.
    35782561            }
    3579             else if(t.type == T_SET){
    3580            
    3581             setPopup.show(e.getComponent(),
    3582                       e.getX(), e.getY());
    3583             }
    3584                 }
    3585         catch(Exception NullPointerException) {
    3586             //Right-clicked in tree area, but no item to select. Do nothing.
    3587         }
    3588 
    3589                 finally {
    3590                     ;
    3591                    
    3592                 }
    3593                
    3594                    
    3595              }
    3596              else if(e.getSource() == set_attributes){ //When right-click on table of set attributes
    3597          
    3598          //Select the table row that was right-clicked on.
    3599          p = e.getPoint();
    3600          set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false);
    3601 
    3602                  attributePopup.show(e.getComponent(),
    3603                            e.getX(), e.getY()); 
    3604              }
    3605              else if(e.getSource() == element_attributes)  { //When right-click on table of element attributes
    3606                
    3607          //Select the table row that was right-clicked on.
    3608          p = e.getPoint();
    3609          element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false);
    3610 
    3611          attributePopup.show(e.getComponent(),
    3612                            e.getX(), e.getY());
    3613              }
    3614          else if(e.getSource() == subelement_attributes)  { //When right-click on table of subelement attributes
    3615          
    3616          //Select the table row that was right-clicked on.
    3617          p = e.getPoint();
    3618          subelement_attributes.changeSelection(subelement_attributes.rowAtPoint(p), subelement_attributes.columnAtPoint(p), false, false);
    3619 
    3620          attributePopup.show(e.getComponent(),
    3621                      e.getX(), e.getY());
    3622              }
     2562        }
     2563        else if(e.getSource() == set_attributes){ //When right-click on table of set attributes
     2564            //Select the table row that was right-clicked on.
     2565            p = e.getPoint();
     2566            set_attributes.changeSelection(set_attributes.rowAtPoint(p), set_attributes.columnAtPoint(p), false, false);
     2567            attributePopup.show(e.getComponent(), e.getX(), e.getY()); 
     2568        }
     2569        else if(e.getSource() == element_attributes)  { //When right-click on table of element attributes
     2570            //Select the table row that was right-clicked on.
     2571            p = e.getPoint();
     2572            element_attributes.changeSelection(element_attributes.rowAtPoint(p), element_attributes.columnAtPoint(p), false, false);
     2573            attributePopup.show(e.getComponent(), e.getX(), e.getY());
     2574        }
    36232575            } 
    36242576        }
    3625      
    3626         public void actionPerformed(ActionEvent e) {
    3627         //This should never happen!!
    3628             System.out.println("NO way hose");
    3629         }
     2577      
     2578      public void actionPerformed(ActionEvent e) {
     2579      //This should never happen!!
     2580      System.err.println("Error: actionPerformed was called in class PopupListener. This should never happen!");
     2581      }
    36302582    }
    36312583 
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSLanguageManager.java

    r8581 r8971  
    1 /*
    2  * GEMSLanguageManager.java
     1 /**
     2 *#########################################################################
    33 *
    4  * Created on October 27, 2004, 3:31 PM
     4 * A component of the Gatherer application, part of the Greenstone digital
     5 * library suite from the New Zealand Digital Library Project at th * University of Waikato, New Zealand.
     6 *
     7 * <BR><BR>
     8 *
     9 * Author: John Thompson, Greenstone Digital Library, University of Waikato
     10 *
     11 * <BR><BR>
     12 *
     13 * Copyright (C) 1999 New Zealand Digital Library Project
     14 *
     15 * <BR><BR>
     16 *
     17 * This program is free software; you can redistribute it and/or modify
     18 * it under the terms of the GNU General Public License as published by
     19 * the Free Software Foundation; either version 2 of the License, or
     20 * (at your option) any later version.
     21 *
     22 * <BR><BR>
     23 *
     24 * This program is distributed in the hope that it will be useful,
     25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     27 * GNU General Public License for more details.
     28 *
     29 * <BR><BR>
     30 *
     31 * You should have received a copy of the GNU General Public License
     32 * along with this program; if not, write to the Free Software
     33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     34 *
     35 *############################################## ##########################
    536 */
    637
     
    3566 * @author John Thompson, Greenstone Digital Library, University of Waikato
    3667 * @version 2.3
     68 * Created on October 27, 2004, 3:31 PM
     69 * Modified 1/02/05 by Matthew Whyte
    3770 */
    3871 public class GEMSLanguageManager {
    39               private Document document;
    40               private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    41               private Vector languageCodes;
    42             public GEMSLanguageManager(String languagexml_location) {
    43                
    44                this.languageCodes = new Vector();
     72     private Document document;
     73     private DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     74     private Vector languageCodes;
     75     private Vector languageCodesAndNames;
     76     public GEMSLanguageManager(String languagexml_location) {
     77     
     78     this.languageCodes = new Vector();
     79     this.languageCodesAndNames = new Vector();
    4580
    46             try {
    47                
    48                File f = new File(languagexml_location);
    49                
    50                DocumentBuilder builder = factory.newDocumentBuilder();
    51                document = builder.parse(f);
    52                org.w3c.dom.Element docelement = document.getDocumentElement();
    53                
    54                //get all language nodes
    55                NodeList mynodelist = docelement.getChildNodes();
    56                
    57                //get a single language text
    58                //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue());
    59                
    60                for(int j = 1; j < mynodelist.getLength(); j++){
    61                    
    62                    //read text value for the element
    63                  
    64                    NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
    65                    
    66                      
    67                    NamedNodeMap nnm = mynodelist.item(j).getAttributes();
    68                
    69                    
    70                     if(childnodesofelement.getLength() == 1){
    71                        
    72                             String code = nnm.item(0).getNodeValue();
    73                             String name = nnm.item(4).getNodeValue();
    74                             String name_value = childnodesofelement.item(0).getNodeValue();
    75                             //language_box.addItem(code.toLowerCase());
    76                             this.languageCodes.add(code.toLowerCase());
    77                     }
    78                    
    79                    
    80                
    81            
    82                    
    83                }//end for
    84        
    85            }
    86            catch(SAXException sxe) {
    87                
    88                System.out.println("sxe exception\n");
    89            }
    90            catch(ParserConfigurationException pce) {
     81     try {
     82         
     83         File f = new File(languagexml_location);
     84         
     85         DocumentBuilder builder = factory.newDocumentBuilder();
     86         document = builder.parse(f);
     87         org.w3c.dom.Element docelement = document.getDocumentElement();
     88         
     89         //get all language nodes
     90         NodeList mynodelist = docelement.getChildNodes();
     91         
     92         //get a single language text
     93         //System.out.println(mynodelist.item(1).getChildNodes().item(0).getNodeValue()); //debug
     94         
     95         for(int j = 1; j < mynodelist.getLength(); j++){
     96         
     97         //read text value for the element
     98         NodeList childnodesofelement = mynodelist.item(j).getChildNodes();
     99         NamedNodeMap nnm = mynodelist.item(j).getAttributes();
     100         
     101         if(childnodesofelement.getLength() == 1)
     102             {
     103             String code = nnm.item(0).getNodeValue();
     104             String name = nnm.item(4).getNodeValue();
     105             String name_value = childnodesofelement.item(0).getNodeValue();
     106             //language_box.addItem(code.toLowerCase());
     107             this.languageCodes.add(code.toLowerCase());
     108             this.languageCodesAndNames.add(name.toLowerCase() + "               \t(" + code.toLowerCase() + ")");
     109             } //end if
     110         }//end for
     111     } //end try
     112     catch(SAXException sxe) {
     113         System.out.println("sxe exception\n");
     114     }
     115     catch(ParserConfigurationException pce) {
    91116             System.out.println("pce exception\n");
    92                
    93            }
    94            catch(IOException ioe){
    95                
    96                System.out.println("ioe exc\n");
    97                
    98            }
    99             
    100             //end create dom object for language_box
    101                
    102             }
    103            public Vector getLanguageCodes() {
    104                return languageCodes;
    105            }
    106            public Object[] getLanguageCodesToArray() {
    107                return languageCodes.toArray();
    108            }
    109            public String getEnabledLanguageCodes() {
    110             String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
    111            return enabled_languages;   
    112            }
    113             public String[] getEnabledLanguageCodesToArray() {
    114             String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
    115             String [] enabled_languages_split = enabled_languages.split(",");
    116            // String [] trimmed_enabled_lang_split = null;
    117            
    118           //  for(int p = 0; p < enabled_languages_split.length; p++) {
    119                 //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim();
    120               //  System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
    121            // }//for p < enabled lang split
    122            
    123             return enabled_languages_split;
    124            }
    125            
    126         }
     117     }
     118     catch(IOException ioe){
     119         System.out.println("ioe exception\n");
     120     }
     121     
     122     //end create dom object for language_box
     123     
     124     }
     125     public Vector getLanguageCodesAndNames() {
     126     return languageCodesAndNames;
     127     }
     128
     129     public Vector getLanguageCodes() {
     130     return languageCodes;
     131     }
     132     public Object[] getLanguageCodesToArray() {
     133     return languageCodes.toArray();
     134     }
     135     public String getEnabledLanguageCodes() {
     136     String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
     137     return enabled_languages;   
     138     }
     139     public String[] getEnabledLanguageCodesToArray() {
     140     String enabled_languages =  Configuration.getString("Gems.Preferences.Selected_Languages", true);
     141     String [] enabled_languages_split = enabled_languages.split(",");
     142     // String [] trimmed_enabled_lang_split = null;
     143     
     144     //  for(int p = 0; p < enabled_languages_split.length; p++) {
     145     //trimmed_enabled_lang_split[p] = enabled_languages_split[p].trim();
     146     //  System.out.println("gemslang: trimm: " + trimmed_enabled_lang_split[p] + " orig: "+ enabled_languages_split[p].trim());
     147     // }//for p < enabled lang split
     148     
     149     return enabled_languages_split;
     150     } 
     151 }
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java

    r8932 r8971  
    6666    }
    6767
    68     public void remove(String name, int type) {
    69     GEMSNode current = (GEMSNode) root;
    70     for(int i = 0; i < current.getChildCount(); i++) {
    71         GEMSNode child = (GEMSNode) current.getChildAt(i);
    72         if(child.toString().equals(name) && type == GEMSNode.SET) {
    73         // Place on AWT event thread to avoid errors.
    74         SynchronizedTreeModelTools.removeNodeFromParent(this, child);
    75         return;
    76         }
    77         // This may be the profiler root node, in which case we descend into its children if we're looking for collection file matches.
    78         else if(type == GEMSNode.COLLECTION && child.getType() == GEMSNode.PROFILER) {
    79         for(int j = 0; j < child.getChildCount(); j++) {
    80             GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
    81             if(inner_child.toString().equals(name)) {
    82             // Place on AWT event thread to avoid errors.
    83             SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
    84             return;
    85             }
    86         }
    87         }
    88         // If this is a set and we are looking for an element or subelement, then iterate through its children. Can't really do this recursively.
    89         else if((type == GEMSNode.ELEMENT || type == GEMSNode.SUBELEMENT) && child.getType() == GEMSNode.SET) {
    90         for(int j = 0; j < child.getChildCount(); j++) {
    91             GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
    92             //Go through looking for element
    93             if(type == GEMSNode.ELEMENT)
    94             {
    95                 if(inner_child.toString().equals(name)) {
    96                 // Place on AWT event thread to avoid errors.
    97                 SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
    98                 return;
    99                 }
    100             }
    101             //Go through element looking for subelement
    102             else if(type == GEMSNode.SUBELEMENT)
    103             {
    104                 for(int k = 0; k < inner_child.getChildCount(); k++)
    105                 {
    106                     //the subelements
    107                     GEMSNode innermost_child = (GEMSNode)inner_child.getChildAt(k);
    108                     if(innermost_child.toString().equals(name))
    109                     {
    110                         // Place on AWT event thread to avoid errors.
    111                         SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
    112                         return;
    113                     }
    114                 }
    115             }
    116         }
    117         }
    118     }
    119 
    120     System.err.println("Tried to remove \'" + name + "\' from the tree, but could not find it!"); //This should not happen!
    121     }
    122 
    12368    /**
    12469       Remove a node from the tree.
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java

    r8932 r8971  
    5151 * @author John Thompson, Greenstone Digital Library, University of Waikato
    5252 * @version 2.3
     53 * Modified 2/02/05 by Matthew Whyte
    5354 */
    5455public class GEMSNode
     
    6263    static final public int ROOT       = 3;
    6364    static final public int SET        = 4;
    64     static final public int SUBELEMENT = 5;
     65    //static final public int SUBELEMENT = 5;
    6566
    6667    public GEMSNode() {
    6768    this.type = ROOT;
    68        
    6969    }
    7070
     
    107107    }
    108108
    109     public ElementWrapper getSubelement() {
    110     ElementWrapper result = null;
    111     if(type == SUBELEMENT) {
    112         result = (ElementWrapper) userObject;
    113     }
    114     return result;
    115     }
    116 
    117109    public int getIndex(TreeNode node) {
    118110    if(children == null) {
     
    147139    }
    148140
    149     public String toString() {
    150     if(text == null) {
    151         if(userObject != null) {
    152         if(userObject instanceof ElementWrapper) {
    153             text = ((ElementWrapper)userObject).getName();
    154         }
    155         // In the case of a 'collection' source path we need to examine the path closely. If it is a descendant of the greenstone collections path then supress everything but the collection name
    156 //      else if(type == COLLECTION) {
    157 //          try {
    158 //          boolean is_descendant = false;
    159 //          File source_path = new File((String)userObject);
    160 //          File collect_path;
    161 //          if (Gatherer.GS3) {
    162 //              collect_path = new File(Utility.getCollectDir(Configuration.gsdl3_path, Configuration.site_name));
    163 //          }  else {
    164 //              collect_path = new File(Utility.getCollectDir(Configuration.gsdl_path));
    165 //          }
    166 //          File current_path = source_path;
    167 //          while(!is_descendant && current_path != null) {
    168 //              is_descendant = current_path.equals(collect_path);
    169 //              current_path = current_path.getParentFile();
    170 //          }
    171 //          current_path = null;
    172 //          collect_path = null;
    173 //          // We've either found we are a descendant, or run out of path
    174 //          if(is_descendant) {
    175 //              // Create a basic config class
    176 //              File config_file = new File(source_path, Utility.CONFIG_FILE);
    177 //              if (config_file.exists()) {
    178 //              BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
    179 //              text = config.toString();
    180 //              config = null;
    181 //              } else {
    182 //              text = source_path.getAbsolutePath();
    183 //              }
    184 //              config_file = null;
    185 //          }
    186 //          else {
    187 //              text = source_path.getAbsolutePath();
    188 //          }
    189 //          }
    190 //          catch(Exception exception) {
    191 //          DebugStream.println("Exception in GEMSNode.toString() - exception is unexpected");
    192 //          DebugStream.printStackTrace(exception);
    193 //          text = userObject.toString();
    194 //          }
    195 //      }
    196         else {
    197             text = userObject.toString();
    198         }
     141    public String toString()
     142    {
     143    if(text == null)
     144        {
     145        if(userObject != null)
     146            {
     147            if(userObject instanceof ElementWrapper)
     148                {
     149                text = ((ElementWrapper)userObject).getName();
     150                }
     151            else
     152                {
     153                text = userObject.toString();
     154                }
     155            }
     156        else
     157            {
     158            text = "error";
     159            }
    199160        }
    200         else {
    201         text = "error";
    202         }
    203     }
    204161    return text;
    205162    }
    206 
    207163
    208164    public void mapChildren()
     
    221177            }
    222178        }
    223     if (type == ELEMENT) //Add subelements. This will need to be changed to cope with multiple levels of subelements.
     179    if (type == ELEMENT) //Add subelements. As elements and subelements are identical, this process continues.
    224180        {
    225181        ArrayList subelements = this.getElement().getSubelements();
    226182        for(int j = 0; j < subelements.size(); j++)
    227183            {
    228             children.add(new GEMSNode(SUBELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
     184            children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element)subelements.get(j)), this));
    229185            }
    230186        }
    231 
    232187    }
    233188   
    234189   class GemsNodeMouseAdapter
    235190    extends MouseAdapter {
    236        
    237        
    238        
     191       
    239192      public void mouseClicked(MouseEvent e) {
    240193        JPopupMenu setPopup = new JPopupMenu("asdf");
    241          if (e.isPopupTrigger()) {
    242                          
    243                      setPopup.show(e.getComponent(),
     194         if (e.isPopupTrigger()) {       
     195         setPopup.show(e.getComponent(),
    244196                           e.getX(), e.getY());
    245                    
    246                
    247             }
     197     }
    248198    }   
    249199   
     
    256206    public void mousePressed(MouseEvent e) {
    257207         JPopupMenu setPopup = new JPopupMenu("asdf");
    258          if (e.isPopupTrigger()) {
    259                          
    260                      setPopup.show(e.getComponent(),
     208         if (e.isPopupTrigger()) {               
     209         setPopup.show(e.getComponent(),
    261210                           e.getX(), e.getY());
    262                    
    263                
    264             }
    265     }
    266    
     211     }
     212    }
     213       
    267214    public void mouseReleased(MouseEvent e) {
    268215         JPopupMenu setPopup = new JPopupMenu("asdf");
    269          if (e.isPopupTrigger()) {
    270                          
    271                      setPopup.show(e.getComponent(),
    272                            e.getX(), e.getY());
    273                    
    274                
    275             }
     216         if (e.isPopupTrigger()) {                 
     217         setPopup.show(e.getComponent(),
     218                           e.getX(), e.getY());     
     219     }
    276220    } 
    277        
    278        
    279221   }
    280    
    281222}
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java

    r8932 r8971  
    3535import javax.swing.*;
    3636import javax.swing.event.*;
     37import javax.swing.border.*;
    3738import org.greenstone.gatherer.Configuration;
    3839import org.greenstone.gatherer.Dictionary;
     
    5152    static final public String CONNECTION_PREFS = "connection";
    5253    static final public String GENERAL_PREFS = "general";
    53 
    54 
    5554    static final private Dimension LABEL_SIZE = new Dimension(280, 25);
    56     static final private Dimension ROW_SIZE = new Dimension(640, 25);
    5755    static final private Dimension SIZE = new Dimension(640, 345);
    58     static final private String TRUE = "true";
    59 
    60     // private CheckList warning_preferences_check_list;
    61     private EmailField email_field;
     56
     57    //private EmailField email_field;
    6258    private JButton apply_button;
    6359    private JButton cancel_button;
    6460    private JButton ok_button;
    65     private JCheckBox use_subfields_checkbox;
    66    
     61
    6762    private JCheckBox use_proxy_checkbox;
    68     private JCheckBox view_extracted_metadata_checkbox;
    69    
    7063    private JCheckBox workflow_create;
    7164    private JCheckBox workflow_mirror;
     
    7467    private JCheckBox workflow_design;
    7568    private JCheckBox workflow_export;
     69
    7670    private JComboBox language_combobox;
    77     private JList language_limited_jlist;
    78    
    79     private JComboBox servlet_combobox; // GS3
    80     private JComboBox site_combobox; // GS3
     71    private JList language_limited_jlist; 
     72    private JList language_code_jlist;
     73    private JComboBox servlet_combobox;
     74    private JComboBox site_combobox;
    8175    private JLabel interface_language_label;
    8276    private JLabel language_label;
    83     private JLabel library_path_label;
    84     private JLabel predefined_label;
    85     private JLabel program_label;
    86     private JLabel proxy_host_label;
    87     private JLabel proxy_port_label;
    88     private JLabel title_label;
    89     private JPanel servlet_pane;
     77
    9078    private JRadioButton assistant_mode_radio_button;
    9179    private JRadioButton expert_mode_radio_button;
    92     private JRadioButton librarian_mode_radio_button;
    9380    private JRadioButton systems_mode_radio_button;
    9481    private JSpinner proxy_port_field;
    9582    private JTabbedPane tab_pane;
    9683    private JTextArea mode_description_textarea;
    97     private JTextField library_path_field;
    98     private JTextField program_field;
    9984    private JTextField proxy_host_field;
    10085    private GEMSPreferences self;
    10186
    10287    private String current_site_selection;
     88
    10389    public GEMSPreferences() {
    104     this(GENERAL_PREFS);
    105     }
    106 
    107     public GEMSPreferences(String initial_view) {
    10890    // Initialize
    10991    super(Gatherer.g_man, true);
     
    118100    JPanel general_preferences = createGeneralPreferences();
    119101    tab_pane.add("Preferences.General", general_preferences);
    120     //tab_pane.add("Preferences.Mode", createModePreferences());
    121     // !! Temporarily disabled for the UNESCO CD-ROM !!
    122     // tab_pane.add("Preferences.Workflow", createWorkflowPreferences());
    123     //JPanel connection_preferences = createConnectionPreferences();
    124     //tab_pane.add("Preferences.Connection", connection_preferences);
    125     //tab_pane.add("Preferences.Warnings", createWarningPreferences());
    126102       
    127103    Dictionary.register(tab_pane);
     
    155131    content_pane.add(button_pane, BorderLayout.SOUTH);
    156132
    157     Dimension frame_size;// = Gatherer.g_man.getSize();
    158     Point frame_location;// = Gatherer.g_man.getLocation();
    159     //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));
    160     //setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));
    161133        setLocation(400, 300);
    162 
    163    
    164134    tab_pane.setSelectedComponent(general_preferences);
    165    
    166 
    167135   
    168136    // Clean up
    169137    general_preferences = null;
    170     //connection_preferences = null;
    171     frame_location = null;
    172     frame_size = null;
    173138    cancel_button = null;
    174139    ok_button = null;
     
    185150    // Build the model of available languages
    186151    ArrayList dictionary_model = new ArrayList();
    187 
    188     // Old method for determining what languages should be available in the combobox
    189     /*
    190     dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));
    191     File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);
    192     File[] possible_dictionaries = classes_folder.listFiles();
    193     for(int i = 0; i < possible_dictionaries.length; i++) {
    194         String filename = possible_dictionaries[i].getName();
    195         if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {
    196         StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);
    197         Locale locale = null;
    198         switch(tokenizer.countTokens()) {
    199         case 1:
    200             locale = new Locale(tokenizer.nextToken().toLowerCase());
    201             break;
    202         case 2:
    203             locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());
    204             break;
    205         }
    206         tokenizer = null;
    207         // Open the file and read the first line
    208         String description = null;
    209         try {
    210             BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));
    211             String first_line = br.readLine();
    212             br.close();
    213             description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);
    214         }
    215         catch(Exception error) {
    216         }
    217         DictionaryEntry entry = new DictionaryEntry(description, locale);
    218         description = null;
    219         locale = null;
    220         if(!dictionary_model.contains(entry)) {
    221             dictionary_model.add(entry);
    222         }
    223         entry = null;
    224         }
    225         filename = null;
    226     }
    227     possible_dictionaries = null;
    228     classes_folder = null;
    229     */
    230152
    231153    // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml
     
    254176    interface_language_label.setPreferredSize(LABEL_SIZE);
    255177       
    256        
    257178    Dictionary.registerText(interface_language_label, "GEMS.Preferences.Selected_Languages_Tooltip");
    258     email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
    259     email_field.setText(Configuration.getEmail());
    260     Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip");
    261 
    262     // Extracted metadata
    263        
    264     //Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip");
    265 
    266    
    267     // Show file sizes
    268     use_subfields_checkbox = new JCheckBox();
    269         JLabel use_subfields_checkbox_label = new JLabel();
    270         use_subfields_checkbox_label.setPreferredSize(new Dimension(225, 30));
    271     use_subfields_checkbox.setSelected(false);
    272         use_subfields_checkbox.setVisible(false);
    273         use_subfields_checkbox_label.setVisible(false);
    274      
    275      //  String blah = Configuration.getString("coloring.workspace_tree_background",true);
    276         //  System.out.println("before"+ blah);
    277          
    278     if (Configuration.get("GEMS.Preferences.Use_Subelements", true)) {
    279             use_subfields_checkbox.setSelected(true);
    280     }
    281     Dictionary.registerBoth(use_subfields_checkbox_label, "GEMS.Preferences.Use_Subelements", "GEMS.Preferences.Use_Subelements_Tooltip");
    282    
     179    //email_field = new EmailField(Configuration.getColor("coloring.error_background", false));
     180    //email_field.setText(Configuration.getEmail());
     181    //Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip");
    283182
    284183    // Language
     
    286185    language_label = new JLabel();
    287186    language_label.setPreferredSize(LABEL_SIZE);
    288        
    289187   
    290188    Dictionary.registerText(language_label, "Preferences.General.Interface_Language");
     
    299197        }
    300198    }
    301    
    302         //create language_limited_jlist
    303         //String [] newer = {"blah", "asfd", "dfjdddd", "blee11" ,"asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","safd", "safd", "safd", "safd"};
    304        
    305        
    306199       
    307200        //create language selected box, and high light the apprpropate ones
    308          int [] selectedLanguages = new int[300];
    309          int selectedLanguagesLength = 0;
    310      
    311            
    312         //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
     201    int [] selectedLanguages = new int[300];
     202    int selectedLanguagesLength = 0;
     203                 
     204    //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
    313205        GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
    314        
    315          
    316          language_limited_jlist = new JList(gemsLangManager.getLanguageCodesToArray());     
     206
     207    //Create the visible JList, and then another one with just the language codes.
     208    language_code_jlist = new JList(gemsLangManager.getLanguageCodesToArray()); 
     209    language_limited_jlist = new JList(gemsLangManager.getLanguageCodesAndNames());
     210
     211    //Set the list up to display tabs properly
     212    TabListCellRenderer renderer = new TabListCellRenderer();
     213    renderer.setTabs(new int[] {50, 200, 300});
     214    language_limited_jlist.setCellRenderer(renderer);
     215
    317216        String enabled_languages =  Configuration.getString("GEMS.Preferences.Selected_Languages", true);
    318     //we have a string : enabled_languages that contains an array of strings delimited by comma's
     217    //we have a string: enabled_languages that contains an array of strings delimited by comma's
    319218        String []enabled_languages_split = enabled_languages.split(",");
    320219        Object []language_codes_array = gemsLangManager.getLanguageCodesToArray();
    321220       
    322         //System.out.println("before: " +enabled_languages_split[0].toString() + " meh: " + enabled_languages);
    323         Vector selected = new Vector();
    324        
    325         //for each enabled_languages_split
    326             //check which languages match, and store the index in selectedLanguages
     221        //for each enabled_languages_split, check which languages match, and store the index in selectedLanguages
    327222        for(int k = 0; k < enabled_languages_split.length; k++) {
    328223           
     
    331226                //if the codes  match, then include the index p into the vector selectedLanguages
    332227                if (language_codes_array[p].toString().toLowerCase().trim().compareTo(enabled_languages_split[k].toLowerCase().trim()) == 0)
    333               {
    334                  // System.out.println(language_codes_array[p].toString().toLowerCase().trim() + " " + enabled_languages_split[k].toLowerCase().trim());
    335              
    336                //  selected.add(p);
    337                    selectedLanguages[selectedLanguagesLength] = p;
    338                    selectedLanguagesLength++;
    339                    language_limited_jlist.addSelectionInterval(p,p);
    340               }
    341              
    342                
    343             }
    344            
    345            
     228            {
     229            selectedLanguages[selectedLanguagesLength] = p;
     230            selectedLanguagesLength++;
     231            language_limited_jlist.addSelectionInterval(p,p);
     232            }   
     233            }   
    346234        }
    347235       
    348         //selectedLanguages should contain the indices of the languages that should be selected as
    349         //stated in enabled_languages
    350      
    351         //language_limited_jlist.setSelectedIndices(selectedLanguages);
    352        // language_limited_jlist.addSelectionInterval(1,1);
    353         //language_limited_jlist.setSelectedIndex(1);
    354                
    355         //because the very first language(index 0) gets chosen no matter what...
    356         //then I unselected the 0 index, and then check the config file to see if that particular language is
    357         //indeed selected
    358      //  language_limited_jlist.set
    359        
    360  
    361        
    362 
    363236    // Connect
    364237    language_combobox.addActionListener(new LanguageComboboxListener());
    365238
    366239    // Layout
    367        
    368240        JScrollPane langScrollPane = new JScrollPane(language_limited_jlist);
    369      
    370         //langScrollPane.getViewport().setView(language_limited_jlist);
    371        
    372        // langScrollPane.setSize(175, 100);
    373241        langScrollPane.setPreferredSize(new Dimension(100, 100));
    374242    lang_limited_pane.setLayout(new GridLayout(1,3));
     
    376244    lang_limited_pane.add(langScrollPane);
    377245       
    378        
    379246    language_pane.setLayout(new BorderLayout());
    380247    language_pane.add(language_label, BorderLayout.WEST);
     
    382249       
    383250    general_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,5,5,5));
    384     //general_pane.setLayout(new GridLayout(4,1,0,5));
    385251    general_pane.setLayout(null);
    386    
    387          general_pane.add(lang_limited_pane);
     252    general_pane.add(lang_limited_pane);
    388253    general_pane.add(language_pane);
    389254    //general_pane.add(view_extracted_metadata_checkbox);
    390     general_pane.add(use_subfields_checkbox);
    391         general_pane.add(use_subfields_checkbox_label);
    392255        Insets general_pane_insets = general_pane.getInsets();
    393256       
     
    397260        language_pane.setBounds(20+general_pane_insets.left, 130+general_pane_insets.top,
    398261                            language_pane.getPreferredSize().width, language_pane.getPreferredSize().height);
    399        
    400         use_subfields_checkbox_label.setBounds(20+general_pane_insets.left, 200+general_pane_insets.top,
    401                             use_subfields_checkbox_label.getPreferredSize().width, use_subfields_checkbox_label.getPreferredSize().height);
    402        
    403         use_subfields_checkbox.setBounds(295+general_pane_insets.left, 200+general_pane_insets.top,
    404                             use_subfields_checkbox.getPreferredSize().width, use_subfields_checkbox.getPreferredSize().height);
    405262       
    406263    return general_pane;
     
    416273    public void actionPerformed(ActionEvent event) {
    417274        // Submit the various changes
    418         // Connection preferences
    419      /*   String program_str = program_field.getText();
    420         if(program_str.length() > 0 && program_str.indexOf("%1") == -1) {
    421         program_str = program_str + " %1";
    422         }
    423         Configuration.setPreviewCommand(program_str);
    424 
    425         boolean site_changed = false;
    426         if (Gatherer.GS3) {
    427         String current_site = Configuration.site_name;
    428         String new_site =(String)site_combobox.getSelectedItem() ;
    429         if (!new_site.equals(current_site)) {
    430             site_changed = true;
    431         }
    432         Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem());
    433         }
    434        
    435         Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected());
    436         Configuration.setString("general.proxy_host", true, proxy_host_field.getText());
    437         Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + "");
    438         Gatherer.setProxy();
    439 
    440         // General preferences
    441         Configuration.setEmail(email_field.getText());
    442 
    443         Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, use_subfields_checkbox.isSelected());
    444         // Force both workspace and collection trees to redraw
    445         if (Gatherer.g_man != null) {
    446         Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED);
    447         Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED);
    448         }
    449 */
    450             //save selected languages list box
    451            
    452             //goes here
    453            
    454             //save subfield checkbox
    455            
    456         Configuration.set("Gems.Preferences.Use_Subelements", true, use_subfields_checkbox.isSelected());
    457       //  Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table
    458 
    459            
     275
    460276            //save interface language
    461277        String current_lang = Configuration.getLanguage();
     
    465281        }
    466282           
    467            
    468            
    469             //////////////////////save language limited jlist selections
    470            
    471              Vector stringVector = new Vector();
    472        
    473              Object[] selectedValues = language_limited_jlist.getSelectedValues();
    474              String concatString = new String();
    475              
    476              for(int k = 0; k < selectedValues.length; k++) {
    477                 // System.out.println(language_limited_jlist.getComponent(0).toString());//allSelectedLanguages[k]
    478                  
    479                  //System.out.println(selectedValues[k]);
    480                  
    481                  if(selectedValues.length-k > 1)
    482                  concatString = concatString.concat(selectedValues[k].toString() +",");
    483                  else
    484                  concatString = concatString.concat(selectedValues[k].toString());
    485                    
     283        //Set language_code_jlist to have the same selections as the language_limited_jlist.
     284        //(before, there was only one JList, and it only contained the language codes).
     285        int[] selection = language_limited_jlist.getSelectedIndices();
     286        language_code_jlist.setSelectedIndices(selection);
     287        Object[] selectedValues = language_code_jlist.getSelectedValues();
     288        String concatString = new String();
     289       
     290        for(int k = 0; k < selectedValues.length; k++) {
     291        if(selectedValues.length-k > 1)
     292            concatString = concatString.concat(selectedValues[k].toString() +",");
     293        else
     294            concatString = concatString.concat(selectedValues[k].toString());
    486295             }
    487296           
    488            
    489            // System.out.println("final cat string: "+ concatString);
    490            
    491        
    492297            Configuration.setString("GEMS.Preferences.Selected_Languages",true, concatString);
    493298           
    494             ///////////////////
    495 /*
    496         // Mode preferences
    497         int current_mode = Configuration.getMode();
    498         int new_mode;
    499         if(assistant_mode_radio_button.isSelected()) {
    500         new_mode = Configuration.ASSISTANT_MODE;
    501         }
    502         else if(systems_mode_radio_button.isSelected()) {
    503         new_mode = Configuration.SYSTEMS_MODE;
    504         }
    505         else if(expert_mode_radio_button.isSelected()) {
    506         new_mode = Configuration.EXPERT_MODE;
    507         }
    508         else  {
    509         new_mode = Configuration.LIBRARIAN_MODE;
    510         }
    511         // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know
    512         if(new_mode != current_mode) {
    513         Configuration.setMode(new_mode);
    514         Collection collection = Gatherer.c_man.getCollection();
    515         if (collection != null) {
    516             collection.cdm.modeChanged(new_mode);
    517         }
    518         Gatherer.g_man.modeChanged(new_mode);
    519         }
    520         // Warning preferences
    521         for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {
    522         Entry entry = warning_preferences_check_list.get(i);
    523         Configuration.set(entry.getProperty(), true, entry.isSelected());
    524         }
    525 
    526         if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {
    527         // shut down the collection
    528         System.err.println("shutting down teh collection");
    529         Gatherer.g_man.closeCurrentCollection();
    530         }
    531 */
    532         // Workflow preferences
    533         // Configuration.set("workflow.mirror", false, workflow_mirror.isSelected());
    534         // Configuration.set("workflow.gather", false, workflow_gather.isSelected());
    535         // Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());
    536         // Configuration.set("workflow.design", false, workflow_design.isSelected());
    537         // Configuration.set("workflow.export", false, workflow_export.isSelected());
    538         // Configuration.set("workflow.create", false, workflow_create.isSelected());
    539         // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());
    540         // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());
    541         // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());
    542         // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));
    543         // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());
    544         // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());
    545 
    546299        // Always save configuration changes immediately (in case the GLI crashes)
    547300        Configuration.save();
     
    592345    }
    593346
    594     /** This listener updates the mode description depending on what mode is selected. */
    595     private class ModeRadioButtonListener
    596     implements ActionListener {
    597     public void actionPerformed(ActionEvent event) {
    598         Object source = event.getSource();
    599         if(source == assistant_mode_radio_button) {
    600         mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));
    601         }
    602         else if(source == expert_mode_radio_button) {
    603         mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));
    604         }
    605         else if(source == systems_mode_radio_button) {
    606         mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));
    607         }
    608         else {
    609         mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));
    610         }
    611         source = null;
    612     }
    613     }
    614 
    615     private class PredefinedActionListener
    616     implements ActionListener {
    617     public void actionPerformed(ActionEvent event) {
    618         JComboBox cb = (JComboBox) event.getSource();
    619         WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();
    620         CheckboxUpdater task = new CheckboxUpdater(element);
    621         SwingUtilities.invokeLater(task);
    622     }
    623 
    624     private class CheckboxUpdater
    625         implements Runnable {
    626         private WorkflowElementWrapper element;
    627         public CheckboxUpdater(WorkflowElementWrapper element) {
    628         this.element = element;
    629         }
    630         public void run() {
    631         workflow_create.setSelected(element.getEnabled("create"));
    632         workflow_mirror.setSelected(element.getEnabled("mirror"));
    633         workflow_gather.setSelected(element.getEnabled("gather"));
    634         workflow_enrich.setSelected(element.getEnabled("enrich"));
    635         workflow_design.setSelected(element.getEnabled("design"));
    636         workflow_export.setSelected(element.getEnabled("export"));
    637         }
    638     }
    639     }
    640347
    641348    private class LanguageComboboxListener
     
    651358    }
    652359    }
    653 
    654     private class SiteComboboxListener
    655     implements ActionListener {
    656     private boolean ignore_event=false;
    657     public void actionPerformed(ActionEvent event) {
    658         System.err.println("event occurred "+event.paramString());
    659         String site = (String) site_combobox.getSelectedItem();
    660         System.err.println("new site = "+site);
    661         if (!site.equals(current_site_selection)) {
    662         current_site_selection = site;
    663         System.err.println("changed the current selection");
    664         ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);
    665         if (servlet_options == null) {
    666             System.err.println("no servlets for this site");
    667             servlet_combobox.setModel(new DefaultComboBoxModel());
    668             Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");
    669             servlet_combobox.setEnabled(false);
    670 
    671         } else {
    672             System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));
    673             servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));
    674             Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");
    675             servlet_combobox.setEnabled(true);
    676         }
    677         }
    678     }   
    679     }
    680 
    681     private class UseProxyListener
    682     implements ActionListener {
    683     public void actionPerformed(ActionEvent event) {
    684         boolean enabled = use_proxy_checkbox.isSelected();
    685         Configuration.set("general.use_proxy", true, enabled);
    686         // Fortunately this is already driven by the event thread.
    687         proxy_host_field.setEnabled(enabled);
    688         proxy_port_field.setEnabled(enabled);
    689     }
    690     }
    691 
    692     private class WorkflowElementWrapper {
    693     private Element element;
    694     private String text;
    695     public WorkflowElementWrapper(Element element) {
    696         this.element = element;
    697     }
    698     public boolean getEnabled(String name) {
    699         boolean result = true;
    700         if(element.getAttribute(name).equalsIgnoreCase("false")) {
    701         result = false;
    702         }
    703         return result;
    704     }
    705     public String toString() {
    706         if(text == null) {
    707         text = element.getFirstChild().getNodeValue();
    708         }
    709         return text;
    710     }
    711     }
    712360}
     361
     362
     363/**
     364   A custom list renderer, to display tabs in the JList properly.
     365
     366   @see http://manning.com/sbe/files/uts2/Chapter10html/Chapter10.htm
     367   Added by Matthew Whyte
     368   Date last modified: 1/02/05
     369 */
     370class TabListCellRenderer extends JLabel implements ListCellRenderer
     371{
     372    protected static Border m_noFocusBorder;
     373    protected FontMetrics m_fm = null;
     374    protected Insets m_insets = new Insets(0, 0, 0, 0);
     375   
     376    protected int m_defaultTab = 50;
     377    protected int[] m_tabs = null;
     378   
     379    public TabListCellRenderer()
     380    {
     381    super();
     382    m_noFocusBorder = new EmptyBorder(1, 1, 1, 1);
     383    setOpaque(true);
     384    setBorder(m_noFocusBorder);
     385    }
     386
     387    public Component getListCellRendererComponent(JList list,
     388                          Object value, int index, boolean isSelected, boolean cellHasFocus)     
     389    {         
     390    setText(value.toString());
     391   
     392    setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
     393    setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
     394   
     395    setFont(list.getFont());
     396    setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder);
     397   
     398    return this;
     399    }
     400   
     401    public void setDefaultTab(int defaultTab) { m_defaultTab = defaultTab; }
     402   
     403    public int getDefaultTab() { return m_defaultTab; }
     404
     405    public void setTabs(int[] tabs) { m_tabs = tabs; }
     406
     407    public int[] getTabs() { return m_tabs; }
     408
     409    public int getTab(int index)
     410    {
     411    if (m_tabs == null)
     412        return m_defaultTab*index;
     413       
     414    int len = m_tabs.length;
     415    if (index >= 0 && index < len)
     416        return m_tabs[index];
     417
     418    return m_tabs[len-1] + m_defaultTab*(index-len+1);
     419    }
     420
     421
     422    public void paint(Graphics g)
     423    {
     424    m_fm = g.getFontMetrics();
     425   
     426    g.setColor(getBackground());
     427    g.fillRect(0, 0, getWidth(), getHeight());
     428    getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());
     429
     430    g.setColor(getForeground());
     431    g.setFont(getFont());
     432    m_insets = getInsets();
     433    int x = m_insets.left;
     434    int y = m_insets.top + m_fm.getAscent();
     435
     436    StringTokenizer st = new StringTokenizer(getText(), "\t");
     437    while (st.hasMoreTokens())
     438    {
     439          String sNext = st.nextToken();
     440          g.drawString(sNext, x, y);
     441        x += m_fm.stringWidth(sNext);
     442
     443        if (!st.hasMoreTokens())
     444            break;
     445        int index = 0;
     446        while (x >= getTab(index))
     447            index++;
     448        x = getTab(index);
     449    }
     450    }   
     451}
  • trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java

    r8932 r8971  
    4444import org.greenstone.gatherer.util.StaticStrings;
    4545import org.greenstone.gatherer.util.Utility;
     46import org.greenstone.gatherer.util.XMLTools;
    4647import org.w3c.dom.*;
    4748/** This class contains a plethora of methods associated with handling the content of <strong>MetadataSet</strong>s and the <strong>Element</strong>s within. For example this is where you will find methods for comparing various parts of two <strong>MetadataSet</strong>s for equality. It also has methods for extracting common and useful data from <strong>Element</strong>s such as the AssignedValue nodes.
     
    9394    attribute_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, attribute_name_str);
    9495    MSMUtils.setValue(attribute_element, value_str);
     96
    9597    // Start off by determining if we have to add this node in the new multilingual optimized way
    9698    if(isAttributeLanguageDependant(document, attribute_name_str)) {
    9799        boolean found = false;
    98100        // Try to retrieve a language element for the given language code
    99         NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
    100         for(int i = 0; i < language_elements.getLength(); i++) {
    101         Element language_element = (Element) language_elements.item(i);
     101        //NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
     102        ArrayList language_elements = XMLTools.getChildElementsByTagName(element_element, StaticStrings.LANGUAGE_ELEMENT);
     103        for(int i = 0; i < language_elements.size(); i++) {
     104        Element language_element = (Element) language_elements.get(i);
    102105        if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equals(language_code_str)) {
    103106            found = true;
     
    736739     * @param attribute_name_str the name of the attribute we a testing as a String
    737740     * @see org.greenstone.gatherer.util.StaticStrings#LANGUAGEDEPENDANT_ATTRIBUTE
     741     * Modified by Matthew Whyte 4/02/05
    738742     */
    739743    static private boolean isAttributeLanguageDependant(Document document, String attribute_name_str)
    740744    {
     745    //gives a list of comma seperated language specific attributes.
    741746    String language_specific_attributes = document.getDocumentElement().getAttribute(StaticStrings.LANGUAGEDEPENDANT_ATTRIBUTE).toLowerCase();
    742     return language_specific_attributes.indexOf(attribute_name_str) != -1;
     747    //System.err.println("lang_specific: " + language_specific_attributes); //debug
     748
     749    //Seperate out language_specific_attributes
     750    String[] attributes_split = language_specific_attributes.split(",");
     751
     752    //Compare each to attribute_name_str
     753    for(int i = 0; i < attributes_split.length; i++)
     754        {
     755        if(attributes_split[i].trim().compareTo(attribute_name_str.toLowerCase()) == 0)
     756            return true;
     757        }
     758    return false;
    743759    }
    744760
     
    802818     */
    803819    static public boolean removeElementAttribute(Element element_element, String attribute_name_str, String language_code_str, String value_str) {
    804     // Multilingual Optimized version
    805     // 1. Determine the if this is one of the language specific attributes
    806     if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str)) {
    807         // Retrieve the language elements, and determine the correct one
    808         NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
    809         for(int i = 0; i < language_elements.getLength(); i++) {
    810         Element language_element = (Element) language_elements.item(i);
    811         if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) {
    812             NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
    813             for(int j = 0; j < attribute_elements.getLength(); j++) {
    814             Element attribute_element = (Element) attribute_elements.item(j);
    815             String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    816             String target_value_str = MSMUtils.getValue(attribute_element);
    817             if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) {
    818                 language_element.removeChild(attribute_element);
    819                 if(attribute_elements.getLength() == 0) {
    820                 element_element.removeChild(language_element);
    821                 }
    822                 target_value_str = null;
    823                 target_name_str = null;
    824                 attribute_element = null;
    825                 attribute_elements = null;
    826                 language_element = null;
    827                 language_elements = null;
    828                 return true;
     820    //Determine the if this is one of the language specific attributes.
     821    //This can sometimes give a false result, if an attribute is made language specific half way through creation of a metadata set (or vice versa).
     822    if(isAttributeLanguageDependant(element_element.getOwnerDocument(), attribute_name_str))
     823        {
     824        /*
     825        Multilingual Optimized version, eg:
     826        <Language code="en">
     827            <Attribute name="identifier">second</Attribute>
     828        </Language>
     829        */
     830        return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, false);
     831        }
     832    else
     833        {
     834        /*
     835        The old way, eg:
     836        <Attribute language="en" name="identifier">second</Attribute>
     837        */
     838        return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, false);
     839        }
     840   
     841    }
     842    static final private boolean removeElementAttributeNew(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once)
     843    {
     844    // Retrieve the language elements, and determine the correct one
     845    NodeList language_elements = element_element.getElementsByTagName(StaticStrings.LANGUAGE_ELEMENT);
     846    for(int i = 0; i < language_elements.getLength(); i++) {
     847        Element language_element = (Element) language_elements.item(i);
     848        if(language_element.getAttribute(StaticStrings.CODE_ATTRIBUTE).equalsIgnoreCase(language_code_str)) {
     849        NodeList attribute_elements = language_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
     850        for(int j = 0; j < attribute_elements.getLength(); j++) {
     851            Element attribute_element = (Element) attribute_elements.item(j);
     852            String target_name_str = attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     853            String target_value_str = MSMUtils.getValue(attribute_element);
     854            if(attribute_name_str.equals(target_name_str) && value_str.equals(target_value_str)) {
     855            language_element.removeChild(attribute_element);
     856            if(attribute_elements.getLength() == 0) {
     857                element_element.removeChild(language_element);
    829858            }
    830859            target_value_str = null;
    831860            target_name_str = null;
    832             attribute_element = null;           
     861            attribute_element = null;
     862            attribute_elements = null;
     863            language_element = null;
     864            language_elements = null;
     865            return true;
    833866            }
    834             attribute_elements = null;
    835         }
    836         language_element = null;
    837         }
    838         language_elements = null;
    839         // Not found
    840         //System.err.println("new optimised way failed."); //debug
    841         return false;
    842     } // end if
    843     // Otherwise just use the old method
    844 
     867            target_value_str = null;
     868            target_name_str = null;
     869            attribute_element = null;           
     870        }
     871        attribute_elements = null;
     872        }
     873        language_element = null;
     874    }
     875    language_elements = null;
     876    // Not found. Try the old way before failing.
     877    if(!run_once)
     878        return removeElementAttributeOld(element_element, attribute_name_str, language_code_str, value_str, true);
     879    return false;
     880    }
     881    static final private boolean removeElementAttributeOld(Element element_element, String attribute_name_str, String language_code_str, String value_str, boolean run_once)
     882    {
    845883    // Find the attribute to remove
    846884    NodeList attribute_elements = element_element.getElementsByTagName(StaticStrings.ATTRIBUTE_ELEMENT);
     
    858896    }
    859897    attribute_elements = null;
    860     // No match found
    861     //System.err.println("Old method failed."); //debug
     898    // No match found. Try the new way before failing.
     899    if(!run_once)
     900        return removeElementAttributeNew(element_element, attribute_name_str, language_code_str, value_str, true);
    862901    return false;
    863902    }
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java

    r8932 r8971  
    496496    /** Method to remove the given element from this metadata set.
    497497     * @param element The <strong>Element</strong> to be removed.
    498      * @param parent The parent element, as an <strong>Element</strong>. If null, the parent is root.
    499      */
    500     public void removeElement(Element element, Element parent) {
    501     // we need to remove the value tree too!!
    502     //System.err.println("removeElement in MetadataSet: element is: " + element); //Debug
    503 
     498     * @param parent The parent element (wrapped, so can access its subelement list), as an <strong>ElementWrapper</strong>. If null, the parent is root.
     499     */
     500    public void removeElement(Element element, ElementWrapper parent) {
    504501    try {
    505502        ElementWrapper element_wrapped = new ElementWrapper(element);
     
    508505        if(parent == null)
    509506        {
    510             parent = root;
     507            elements.remove(element);
     508            root.removeChild(element);
    511509        }
    512        
    513         //Want to remove subelement.
    514         //System.err.println("Wanna remove subelement"); //debug
    515         parent.removeChild(element);
     510        else
     511        {
     512            parent.removeSubelementFromList(element);
     513            parent.getElement().removeChild(element);
     514        }
    516515       
    517516    } catch(Exception DOMException) { //The element does not exist!!
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java

    r8932 r8971  
    405405           if(st.nextToken().compareTo("collect") == 0) {
    406406            colName = st.nextToken(); 
    407         System.err.println("colName is: " + colName); //debug
    408407           // metadata_set.old_filename = metadata_set.getName();
    409408           // metadata_set.setName(new String("(" + colName + ") " + metadata_set.getName()) );
     
    431430       @return void
    432431       Modified by Matthew Whyte 19/01/04
     432
     433       This should really be totally replaced by MetadataSet.removeElement --Matthew
    433434     */
    434435    public void removeElement(ElementWrapper element, ElementWrapper parent) {
     
    439440    if(set != null) {
    440441        //Remove the element
    441         if(parent == null)
    442         {
    443             set.removeElement(element.getElement(), null); //Let's not cause an exception!
    444         }
    445         else
    446         {
    447             set.removeElement(element.getElement(), parent.getElement());
    448         }
     442        set.removeElement(element.getElement(), parent);
    449443    }
    450444    else {
     
    463457    public void renameElement(ElementWrapper oldElement, String newName)
    464458    {
    465     GEMSNode node = null;
    466 
    467459    //Retrive the metadata set this element belongs to.
    468460    String namespace = oldElement.getNamespace();
     
    491483        for(int i = 0; i < all_values.size(); i++) {
    492484        GValueNode node = (GValueNode)all_values.get(i);
    493         TreePath path = new TreePath(node.getPath());
    494485        String full_value = node.getFullPath(false);
    495486        String index = model.getHIndex(full_value);
Note: See TracChangeset for help on using the changeset viewer.