Changeset 8873


Ignore:
Timestamp:
2004-12-22T09:18:23+13:00 (19 years ago)
Author:
kjdon
Message:

added Matthews changes - fixed a bug regarding deleting elements, and enabled use of the delete key

File:
1 edited

Legend:

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

    r8864 r8873  
    102102    static final public String METADATA_SET_TEMPLATE = "xml/template.mds";
    103103    static final public String METADATA_VALUE_TEMPLATE = "xml/template.mdv";
     104
     105    //all of our popup menu items
     106    static final public int T_COLLECTION = 0;
     107    static final public int T_ELEMENT    = 1;
     108    static final public int T_PROFILER   = 2;
     109    static final public int T_ROOT       = 3;
     110    static final public int T_SET        = 4;
    104111
    105112   // static final public String MAX_LOADED_SETS = 64;
     
    165172    //event was performed
    166173    private PopupListener popupListener = new PopupListener(this);
     174
     175    /**KeyPressedListener is a centralized manager for all key pressed action */
     176    //    private KeyPressedListener keyPressedListener = new KeyPressedListener();
     177 
    167178    /** A tree that represents the current metadata sets associated with this collection. */
    168179    private SmarterTree mds_tree = null;
     
    275286     
    276287        mds_tree.addMouseListener(popupListener);
     288    mds_tree.addKeyListener(new KeyPressedHandler());
    277289    details_pane = new JPanel();
    278290    details_pane.setOpaque(false);
     
    307319    set_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    308320    set_attributes.addMouseListener(popupListener);   
     321    set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key
    309322    JPanel element_details_pane = new JPanel();
    310323    element_details_pane.setOpaque(false);
     
    337350    element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    338351        element_attributes.addMouseListener(popupListener);
     352    element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
    339353       
    340     element_values_layout = new CardLayout();
     354    element_values_layout = new CardLayout();
    341355    element_values_pane = new JPanel();
    342356    element_values_pane.setOpaque(false);
     
    598612
    599613
     614   
    600615    private class GEMSMenuBar
    601616    extends JMenuBar
     
    14601475        String name_str = name.getSelectedItem().toString();
    14611476        String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
     1477        boolean cont = false;
    14621478
    14631479        // Remove the existing attribute if this is an edit
     
    14721488        // Update the attribute table
    14731489        model.add(new Attribute(name_str, value_str));
    1474         boolean cont = true;
     1490        cont = true;
    14751491         
    1476       /*  // Check that there isn't already an entry for this attribute
    1477            *
    1478            
     1492        /*
     1493        // Check that there isn't already an entry for this attribute
    14791494        if (!model.contains(name_str, 0)) {
    14801495        // Add the new attribute
     
    14821497        // Update the attribute table
    14831498        model.add(new Attribute(name_str, value_str));
     1499        cont = true;
    14841500        }
    14851501        // Otherwise show an error message and do not proceed
     
    14871503        cont = false;
    14881504        JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Attribute_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    1489         }*/
     1505        }
     1506        */
    14901507
    14911508        value_str = null;
     
    25082525
    25092526    private class RemoveAttributeActionListener
    2510     implements ActionListener {
     2527    implements ActionListener, KeyListener {
     2528
     2529    /**
     2530       Any implementation of KeyListener must include these mothods.
     2531       When the DELETE key is pressed, fire the actionPerformed event.
     2532    */
     2533    public void keyTyped(KeyEvent e){
     2534        //Do nothing
     2535    }
     2536        public void keyPressed(KeyEvent e)
     2537        {
     2538            if(e.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE)
     2539            {
     2540                //DELETE key pressed
     2541                actionPerformed((ActionEvent)null);
     2542            }
     2543        }
     2544        public void keyReleased(KeyEvent e) {
     2545        //Do nothing
     2546        }
     2547           
    25112548    /** 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
    25122549     * @param event An <strong>ActionEvent</strong> containing information about the event.
     
    25592596    private class RemoveElementActionListener
    25602597    implements ActionListener {
     2598
    25612599    /** 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.
    25622600     * @param event An <strong>ActionEvent</strong> containing information about the event.
     
    25732611            // Clear selection
    25742612            mds_tree.clearSelection();
    2575             model.remove(current_element.toString(), GEMSNode.ELEMENT);
     2613            model.remove(current_element.getName(), GEMSNode.ELEMENT); //Need to use .getName() not .toString!!
     2614
    25762615            // Meanwhile disable/enable controls given we had an element selected, but no longer do.
    25772616            remove_element.setEnabled(false);
     
    25882627    }
    25892628    }
     2629
     2630 
     2631
    25902632
    25912633    private class RemoveFileActionListener
     
    26142656    }
    26152657
     2658    /**
     2659       Class to handle DELETE key presses on the tree.
     2660       The class then fires the appropriate event to remove that element/set.
     2661       Attributes in the table are handled directly by the RemoveAttributeActionListener
     2662
     2663       Author: Matthew Whyte
     2664       Date last modified: 21/12/04
     2665    */
     2666    private class KeyPressedHandler implements KeyListener {   
     2667
     2668    // All implementations of KeyListener requires these methods
     2669    public void keyTyped(KeyEvent e){
     2670        //Do nothing
     2671    }
     2672    public void keyPressed(KeyEvent e)
     2673    {
     2674
     2675        if(e.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE) //DELETE key pressed
     2676        {
     2677        boolean cont = true;
     2678
     2679        /**
     2680           Check to see if more than one tree node/leaf is selected. If so don't continue.
     2681
     2682           This could be updated to delete multiple nodes/leaves in the futere.
     2683           But not me and not today!!
     2684        */
     2685        TreePath[] multiSelectionCheck = mds_tree.getSelectionPaths();
     2686        if(multiSelectionCheck.length > 1)
     2687            {
     2688            cont = false;
     2689            Toolkit.getDefaultToolkit().beep();
     2690            }
     2691
     2692        if(cont)
     2693            {
     2694            //Check to see if pressed on Set or Element.
     2695            TreePath selPath = mds_tree.getSelectionPath();
     2696            GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
     2697           
     2698            if(t.type == T_ELEMENT) //Remove the element
     2699                {
     2700                //System.err.println("element");
     2701                RemoveElementActionListener removeElement = new RemoveElementActionListener();
     2702                removeElement.actionPerformed((ActionEvent)null);
     2703                }
     2704           
     2705            else if(t.type == T_ROOT)
     2706                {
     2707                //Do nothing
     2708                System.err.println("Tree type of ROOT: this should not happen!");
     2709                }
     2710            else if(t.type == T_SET) //Remove the whole set
     2711                {
     2712                //System.err.println("set");
     2713                RemoveSetActionListener removeSet = new RemoveSetActionListener();
     2714                removeSet.actionPerformed((ActionEvent)null);
     2715                }
     2716            }
     2717        }
     2718    }
     2719    public void keyReleased(KeyEvent e) {
     2720        //Do nothing
     2721    }
     2722    }
     2723
     2724
    26162725    private class RemoveSetActionListener
    26172726    implements ActionListener {
     2727
    26182728    /** 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
    26192729     * @param event An <strong>ActionEvent</strong> containing information about the event.
     
    26252735                //not let anyone remove them --Attila
    26262736               // System.out.println(current_set.getName());
    2627                //
    26282737               
    26292738                File current_set_filename = current_set.getFile();
     
    29303039       
    29313040        JMenuItem menuRemoveSet;
    2932         //all of our popup menu items above
    2933         static final public int COLLECTION = 0;
    2934         static final public int ELEMENT    = 1;
    2935         static final public int PROFILER   = 2;
    2936         static final public int ROOT       = 3;
    2937         static final public int SET        = 4;
    29383041       
    29393042        GEMS GEMSRef = null;
     
    29693072           
    29703073            menuRemoveSet = new JMenuItem();
    2971         //Dictionary.setText(menuRemoveSet,"GEMS.Popup.menuRemoveSet");
     3074    //Dictionary.setText(menuRemoveSet,"GEMS.Popup.menuRemoveSet");
    29723075       Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip");
    29733076       
     
    30153118             //start Associate the menu items with the appropriate popups:
    30163119             //setPopup.add(menuRenameSet);
    3017             setPopup.add(menuAddSet);
     3120         //setPopup.add(menuAddSet);
    30183121        setPopup.add(menuAddAttributeSet);
    30193122        setPopup.add(menuAddElement);
     
    30363139             
    30373140             menuRemoveSet.addActionListener(new RemoveSetActionListener());
    3038              menuAddSet.addActionListener(new AddSetActionListener());
     3141             //menuAddSet.addActionListener(new AddSetActionListener());
    30393142             menuAddElement.addActionListener(new AddElementActionListener());
    30403143             menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
     
    31023205            mds_tree.setSelectionPath(selPath); //Select node right-clicked on
    31033206           
    3104             if(t.type == ELEMENT){
     3207            if(t.type == T_ELEMENT){
    31053208           
    31063209            elementPopup.show(e.getComponent(),
    31073210                      e.getX(), e.getY());
    31083211            }
    3109             else if(t.type == ELEMENT){
     3212
     3213            /*  else if(t.type == T_ELEMENT){
    31103214           
    31113215            subfieldPopup.show(e.getComponent(),
    31123216                       e.getX(), e.getY());
    3113             }
    3114             else if(t.type == ROOT){
     3217                }
     3218            */
     3219            else if(t.type == T_ROOT){
    31153220           
    31163221            setPopup.show(e.getComponent(),
    31173222                      e.getX(), e.getY());
    31183223            }
    3119             else if(t.type == SET){
     3224            else if(t.type == T_SET){
    31203225           
    31213226            setPopup.show(e.getComponent(),
Note: See TracChangeset for help on using the changeset viewer.