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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.