Changeset 8881


Ignore:
Timestamp:
2005-01-10T14:38:23+13:00 (19 years ago)
Author:
mdewsnip
Message:

More GEMS improvements, by Matthew Whyte. Metadata elements can now be renamed.

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

Legend:

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

    r8270 r8881  
    6767    public ElementWrapper(Element element) {
    6868    this.element = element;
     69    //System.err.println("ElementWrapper: element is: " + element); //debug
    6970    Element parent =  (Element)element.getParentNode();
    7071    if (parent != null) {
     
    211212    return getNamespace() + MSMUtils.NS_SEP + getIdentity();
    212213    }
     214
    213215}
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java

    r8873 r8881  
    117117    private AddFileActionListener add_file_action_listener = null;
    118118    public  AddSetActionListener add_set_action_listener = null;
     119    // private RenameElementActionListener rename_element_action_listener = null;
    119120    /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */
    120121    public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null;
     
    463464    add_file_action_listener = new AddFileActionListener();
    464465    add_set_action_listener = new AddSetActionListener();
    465        
     466    //   rename_element_action_listener = new RenameElementActionListener();
    466467       
    467468 
     
    16511652            // Then update the tree
    16521653            model.add(current_node, element, GEMSNode.ELEMENT);
     1654            //System.out.println("current_node is: " + current_node); //debug
    16531655            // Signal that the metadata set has changed
    16541656            // msm.fireSetChanged(current_set);
     
    19361938        setLocation((config.screen_size.width - ADD_SET_SIZE.width) / 2, (config.screen_size.height - ADD_SET_SIZE.height) / 2);
    19371939    }
    1938     /** 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
    1939      * @param event An <strong>ActionEvent</strong> containing information about the event.
    1940      */
     1940
    19411941        private boolean a_set_exists_with_this_namespace(String namespace){
    19421942            Vector p = msm.getSets();
     
    19481948                    flag = true;     
    19491949                }
     1950
    19501951               
    19511952            }
     
    19531954            return flag;
    19541955        }
     1956
     1957
     1958    /** 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
     1959     * @param event An <strong>ActionEvent</strong> containing information about the event.
     1960     */
    19551961    public void actionPerformed(ActionEvent event) {
    19561962        Object source = event.getSource();
     
    20032009                }//end do not inherit
    20042010                else {
     2011            //Should change this to use XML parsing utilites --Matthew
    20052012                    //lets grab the metadata we want to inherit from...
    20062013                    String anitem = existingSetJComboBox.getSelectedItem().toString();
     
    20142021
    20152022            FileInputStream fstream = new FileInputStream(items[1].trim());
    2016             BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF-8"));
     2023            BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8"));
    20172024                        //DataInputStream in = new DataInputStream(fstream);
    20182025                        ///////////////
     
    24032410                }
    24042411            }
    2405             // If we haven't done so yet, insert the current node. This will coincidently remove from original parent.
     2412            // If we haven't done so yet, insert the current node This will coincidently remove from original parent.
    24062413            if(!found) {
    24072414                Node parent_node = subject_node.getElement();
     
    26562663    }
    26572664
     2665
     2666    /**
     2667       Class to hand renaming of a set.
     2668
     2669       Author: Matthew Whyte
     2670       Date last modified: 22/12/04
     2671    */
     2672    private class RenameSetActionListener extends AddSetActionListener implements ActionListener {
     2673    /**
     2674       To do: everything!!!!! --Matthew
     2675    */
     2676
     2677
     2678    //Constructor
     2679    public RenameSetActionListener()
     2680    {
     2681    }
     2682
     2683    /**
     2684       Any implementation of ActionListener must include this method so that we can be informed when an action has occured.
     2685       @param event An <string>ActionEvent</strong> containing information about the event.
     2686    */
     2687    public void actionPerformed(ActionEvent event)
     2688    {
     2689        System.err.println("You chose to rename a set!!"); //debug
     2690    }
     2691    }
     2692
     2693
     2694    /**
     2695       Class to hand renaming of an element.
     2696
     2697       Author: Matthew Whyte
     2698       Date last modified: 10/01/05
     2699    */
     2700    private class RenameElementActionListener extends ModalDialog implements ActionListener {
     2701
     2702    private JButton cancel_button = null;
     2703    private JButton ok_button = null;
     2704    private JLabel label = null;
     2705    private NonWhitespaceField name_field = null;
     2706
     2707       
     2708    public RenameElementActionListener() {
     2709        super(self);
     2710        setModal(true);
     2711        setSize(ADD_ELEMENT_SIZE);
     2712        // Creation
     2713        JPanel content_pane = (JPanel) getContentPane();
     2714        content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
     2715        JPanel center_pane = new JPanel();
     2716        center_pane.setOpaque(false);
     2717
     2718        JPanel labels_pane = new JPanel();
     2719        labels_pane.setOpaque(false);
     2720        JLabel set_label = new JLabel();
     2721        set_label.setOpaque(false);
     2722        Dictionary.setText(set_label, "GEMS.Rename_Element");
     2723        label = new JLabel();
     2724        label.setOpaque(false);
     2725
     2726        JPanel values_pane = new JPanel();
     2727        values_pane.setOpaque(false);
     2728        JLabel name_label = new JLabel();
     2729        name_label.setOpaque(false);
     2730        Dictionary.setText(name_label, "GEMS.New_Name");
     2731        name_field = new NonWhitespaceField();
     2732        name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
     2733        name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
     2734        name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
     2735        name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
     2736        Dictionary.setTooltip(name_field, "GEMS.Rename_Element_Tooltip");
     2737
     2738        JPanel button_pane = new JPanel();
     2739        button_pane.setOpaque(false);
     2740
     2741        ok_button = new GLIButton();
     2742        ok_button.setMnemonic(KeyEvent.VK_O);
     2743        Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
     2744        cancel_button = new GLIButton();
     2745        cancel_button.setMnemonic(KeyEvent.VK_C);
     2746        Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
     2747
     2748        TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
     2749
     2750        // Connection
     2751        cancel_button.addActionListener(this);
     2752        ok_button.addActionListener(this);
     2753        ok_button_enabler.add(name_field);
     2754
     2755        // Layout
     2756        labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     2757        labels_pane.setLayout(new GridLayout(2,1));
     2758        labels_pane.add(set_label);
     2759        labels_pane.add(name_label);
     2760
     2761        values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     2762        values_pane.setLayout(new GridLayout(2,1));
     2763        values_pane.add(label);
     2764        values_pane.add(name_field);
     2765
     2766        center_pane.setLayout(new BorderLayout(5,5));
     2767        center_pane.add(labels_pane, BorderLayout.WEST);
     2768        center_pane.add(values_pane, BorderLayout.CENTER);
     2769
     2770        button_pane.setLayout(new GridLayout(1,2,0,5));
     2771        button_pane.add(ok_button);
     2772        button_pane.add(cancel_button);
     2773
     2774        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     2775        content_pane.setLayout(new BorderLayout());
     2776        content_pane.add(center_pane, BorderLayout.CENTER);
     2777        content_pane.add(button_pane, BorderLayout.SOUTH);
     2778
     2779        setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);
     2780    }
     2781
     2782
     2783    /**
     2784       Any implementation of ActionListener must include this method so that we can be informed when an action has occured.
     2785       @param event An <string>ActionEvent</strong> containing information about the event.
     2786    */
     2787    public void actionPerformed(ActionEvent event)
     2788    {
     2789        Object source = event.getSource();
     2790
     2791        if(source == ok_button)
     2792        {
     2793            TreeNode selPath = current_node.getParent();
     2794            GEMSNode parent = (GEMSNode)selPath;
     2795            MetadataSet currentSet = msm.getSet(current_element.getNamespace());
     2796
     2797            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
     2798 
     2799            // If this element doesn't already exist.
     2800            if(!currentSet.containsElement(name_str)) //Do the renaming!
     2801            {   
     2802                //Hide the element that are about to rename
     2803                mds_tree.clearSelection();
     2804                model.remove(current_element.getName(), GEMSNode.ELEMENT);
     2805               
     2806                msm.renameElement(current_element, name_str); //rename the element
     2807               
     2808                model.add(parent, current_element, GEMSNode.ELEMENT);
     2809               
     2810                //Could now select the new element, but for now will just clean up ;-)
     2811                // Disable/enable controls given we had an element selected, but no longer do.
     2812                remove_element.setEnabled(false);
     2813                card_layout.show(details_pane, BLANK); // Show a blank panel.
     2814                ignore = false;
     2815               
     2816                atLeastOneSetChanged = true;
     2817                setVisible(false);
     2818            }
     2819               
     2820            // Otherwise show an error message and do not proceed.
     2821            else
     2822            {
     2823                JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Element_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     2824            }
     2825            name_str = null;
     2826           
     2827        }
     2828
     2829        else if(source == cancel_button)
     2830        {
     2831            setVisible(false); //hide dialog
     2832        }
     2833        else
     2834        {
     2835            name_field.setText(""); //remove old text
     2836            setVisible(true); //Show the dialog
     2837        }
     2838           
     2839        source = null;
     2840    }
     2841   
     2842
     2843    public void dispose() {
     2844        cancel_button = null;
     2845        ok_button = null;
     2846        name_field = null;
     2847        label = null;
     2848        //System.err.println("Dispose AddElementActionListener");
     2849        super.dispose();
     2850    }
     2851
     2852    }
     2853
     2854
    26582855    /**
    26592856       Class to handle DELETE key presses on the tree.
     
    27212918    }
    27222919    }
     2920
     2921
     2922   
    27232923
    27242924
     
    30883288            //element related GEMS.Popups
    30893289            menuRenameElement=new JMenuItem();
    3090            // Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");
    3091             //Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");
     3290            Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");
     3291        // Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");
    30923292           
    30933293            menuDeleteElement=new JMenuItem();
     
    31173317             
    31183318             //start Associate the menu items with the appropriate popups:
     3319             setPopup.add(menuRenameSet);
     3320         //setPopup.add(menuAddSet);
     3321         setPopup.add(menuAddAttributeSet);
     3322         setPopup.add(menuAddElement);
     3323         setPopup.add(menuRemoveSet);
    31193324             //setPopup.add(menuRenameSet);
    31203325         //setPopup.add(menuAddSet);
     
    31273332             subfieldPopup.add(menuAddAttributeSubfield);
    31283333             
    3129              //elementPopup.add(menuRenameElement);
     3334             elementPopup.add(menuRenameElement);
    31303335             elementPopup.add(menuDeleteElement);
    31313336             elementPopup.add(menuAddAttributeElement);
     
    31463351             menuAddAttributeSubfield.addActionListener(this);
    31473352             
    3148              menuRenameElement.addActionListener(this);
     3353         menuRenameSet.addActionListener(new RenameSetActionListener());
     3354             menuRenameElement.addActionListener(new RenameElementActionListener());
    31493355             menuDeleteElement.addActionListener(new RemoveElementActionListener());
    31503356             menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java

    r8863 r8881  
    194194    return new ElementWrapper(element);
    195195    }
    196    
     196
     197   
    197198    /** Method to add a new metadata element to this metadata set, if and only if the element is not already present.
    198199     * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set.
     
    477478    }
    478479    }
     480
     481 /**
     482       Rename the metadata element.
     483       @param oldElement An <strong>Element</strong> we wish to rename
     484       @param newName A <strong>String</strong> which contains the new name of the element.
     485       @return An <strong>ElementWrapper</strong> around the newly named element
     486    */
     487    public void renameElement(Element oldElement, String newName)
     488    {
     489    oldElement.setAttribute("name", newName); //Rename the element
     490    }
     491   
     492
    479493    /** Used to remove the value tree for a specific element.
    480494     * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove.
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java

    r8863 r8881  
    411411    // No such set. No such element.
    412412    }
     413
     414 /**
     415       Rename the metadata element.
     416       @param oldElement An <strong>ElementWrapper</strong> we wish to rename
     417       @param newName A <strong>String</strong> which contains the new name of the element.
     418       @return An <strong>ElementWrapper</strong> around the newly named element
     419    */
     420    public void renameElement(ElementWrapper oldElement, String newName)
     421    {
     422    //Retrive the metadata set this element belongs to.
     423    String namespace = oldElement.getNamespace();
     424    MetadataSet set = (MetadataSet)mds_hashtable.get(namespace);
     425    if(set != null)
     426        {
     427        set.renameElement(oldElement.getElement(), newName); //Rename the element
     428        }
     429    else
     430        {
     431        System.err.println("No such set " + namespace);
     432        }
     433    }
     434
    413435/*Following write() and write() and save() were taken from msm/metadatasetmanager.java and converted to
    414436 *the gems standard
Note: See TracChangeset for help on using the changeset viewer.