Changeset 8930 for trunk/gli


Ignore:
Timestamp:
2005-01-25T16:32:41+13:00 (19 years ago)
Author:
mdewsnip
Message:

More GEMS improvements, by Matthew Whyte. Now has subfield support.

Location:
trunk/gli
Files:
8 edited

Legend:

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

    r8882 r8930  
    10871087GEMS.Popup.menuAddElement:Add element
    10881088GEMS.Popup.menuAddSet:Add a new set
    1089 GEMS.Popup.menuAddSubfield:Add subfield
     1089GEMS.Popup.menuAddSubelement:Add subelement
    10901090
    10911091GEMS.Popup.menuEditValue:Edit value
     
    10931093GEMS.Popup.menuRenameElement:Rename element
    10941094GEMS.Popup.menuRenameSet:Rename set
    1095 GEMS.Popup.menuRenameSubfield:Rename subfield
     1095GEMS.Popup.menuRenameSubelement:Rename subelement
    10961096
    10971097GEMS.Popup.menuRemoveAttribute:Remove attribute
    10981098GEMS.Popup.menuRemoveElement:Remove element
    10991099GEMS.Popup.menuRemoveSet:Remove set
    1100 GEMS.Popup.menuRemoveSubfield:Remove subfield
     1100GEMS.Popup.menuRemoveSubelement:Remove subelement
    11011101
    1102 GEMS.Preferences.Use_Subfields: Use Subfields?
    1103 GEMS.Preferences.Use_Subfields_Tooltip: Toggle on or off whether you want to be able to manage subfields.
     1102GEMS.Preferences.Use_Subelements: Use Subelements?
     1103GEMS.Preferences.Use_Subelements_Tooltip: Toggle on or off whether you want to be able to manage subelements.
    11041104GEMS.Preferences.Selected_Languages_Tooltip: Selected languages to display:
    11051105GEMS.Menu.File: File
     
    11221122GEMS.Add_Attribute_Tooltip:Add a new attribute to the selected item
    11231123GEMS.Add_Element_Tooltip:Add a new element to the selected set
     1124GEMS.Add_Subelement_Tooltip:Add a new subelement to the seclect element
    11241125GEMS.Add_File_Tooltip:Add a new importing profile
    11251126GEMS.Add_Set_Tooltip:Add a new metadata set
     
    11661167GEMS.Rename_Element:Rename Element
    11671168GEMS.Rename_Element_Tooltip:The element's new name
     1169GEMS.Rename_Name_Tooltip:The metadata set's new name
     1170GEMS.Rename_Namespace_Tooltip:The metadata set's unique namespace
     1171GEMS.Rename_Set:Rename Set
    11681172GEMS.Set:Set
    11691173GEMS.Set_Details:Metadata Set Details
     
    11721176GEMS.Source:From
    11731177GEMS.Subject:Subject
     1178GEMS.Subelement:Subelement
     1179GEMS.Subelement_Details:Metadata Subelement Details
     1180GEMS.Subelement_Name_Tooltip:The name of the new subelement
     1181GEMS.Subelement_Already_Exists:A subelement with this name already exists.
    11741182GEMS.Target:Element
    11751183GEMS.Title:Greenstone Editor for Metadata Sets
  • trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java

    r8881 r8930  
    6161    private String namespace = "";
    6262
     63    private NodeList subelements = null; //The list of subelements
     64
    6365    private Troolean is_extracted = new Troolean();
    6466    /** Constructor for elements with no namespace necessary.
     
    6971    //System.err.println("ElementWrapper: element is: " + element); //debug
    7072    Element parent =  (Element)element.getParentNode();
    71     if (parent != null) {
    72         this.namespace = parent.getAttribute("namespace");
    73     }
    74 
     73    if (parent != null)
     74        {
     75        this.namespace = parent.getAttribute("namespace");
     76        }
     77   
     78    subelements = element.getElementsByTagName("Subelement");
     79    //Should read in each subelement's value tree?
    7580    }
    7681
     
    8186    public void addAttribute(String name, String language, String value) {
    8287    MSMUtils.addElementAttribute(element, name, language, value);
     88    }
     89
     90
     91    /**
     92       Check to see if the element contains a particular subelement
     93       @return true if element already contains a subelement of name name.
     94       @param name the name of the subelement to check for, as a <strong>String</strong>
     95       @author Matthew Whyte
     96       @date last modified: 19/01/04
     97    */
     98    public boolean containsSubelement(String name)
     99    {
     100    //System.err.println("Want to see if subelement: " + name + " exists."); //debug
     101    for(int i = 0; i < subelements.getLength(); i++)
     102        {
     103        Element sibling = (Element)subelements.item(i);
     104        String sibling_name = sibling.getAttribute("name");
     105        if(sibling_name.equals(name))
     106            {
     107            return true;
     108            }
     109        }
     110       
     111    return false;
     112    }
     113
     114    /**
     115       Method to acquire a list of all the subelements in the element.
     116       @return A <strong>NodeList</strong> containing all of this element's subelements.
     117
     118       @author: Matthew Whyte
     119       @date last modified: 19/01/04
     120     */
     121    public NodeList getSubelements()
     122    {
     123    return subelements;
     124    }
     125
     126    /**
     127       Method to determine if this is a subelement
     128       @return A <strong>boolean</strong> - true if the 'element' is a subelement
     129       @author Matthew Whyte
     130       @date last modified 19/01/04
     131     */
     132    public boolean isSubelement()
     133    {
     134    Element element = this.getElement();
     135    if(element.getTagName().equals("Subelement"))
     136        {
     137        return true;
     138        }
     139    return false;
    83140    }
    84141
     
    137194    return MSMUtils.getIdentifier(element);
    138195    }
     196
     197    /** Retrieve the name of this element. Name is unique.
     198    @return The name (without the namespace) as a <strong>String</strong>.
     199    @see org.greenstone.gatherer.msm.MSMUtils
     200    @author Matthew Whyte
     201    @date last modified: 21/01/04
     202     */
     203    public String getNameOnly() {
     204    return MSMUtils.getNameOnly(element);
     205    }
     206
    139207    /** Retrieve the name of this element. Name is unique.
    140208     * @return The name as a <strong>String</strong>.
     
    142210     */
    143211    public String getName() {
    144     return MSMUtils.getFullName(element, namespace);
    145     }
     212        return MSMUtils.getFullName(element, namespace);
     213    }
     214
     215
    146216    /** Retrieve the namespace prefix for this element wrapper.
    147217     * @return A <strong>String</strong> containing the namespace or "" if there is no namespace for this element.
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java

    r8896 r8930  
    100100    static final private String PROFILE = "profile";
    101101    static final private String SET = "set";
     102    static final private String SUBELEMENT = "subelement";
    102103    static final private String VALUES = "values";
    103104
     
    111112    static final public int T_ROOT       = 3;
    112113    static final public int T_SET        = 4;
     114    static final public int T_SUBELEMENT = 5;
    113115
    114116   // static final public String MAX_LOADED_SETS = 64;
     
    132134    private Dimension screen_size = null;
    133135    private ElementWrapper current_element = null;
     136    private ElementWrapper current_subelement = null;
    134137    private GValueNode current_value_node = null;
    135138    /** A reference to ourselves so our inner classes can dispose of us. */
     
    156159    private JScrollPane profile_attributes_scroll = null;
    157160    private JScrollPane set_attributes_scroll = null;
     161    private JScrollPane subelement_attributes_scroll = null;
    158162    private JPanel details_pane = null;
    159163    private JPanel element_values_pane = null;
     
    164168    private Object target = null;
    165169    public RemoveSetActionListener remove_set_action_listener;
     170    private SmarterTable subelement_attributes = null;
    166171    private SmarterTable element_attributes = null;
    167172    private SmarterTable profile_attributes = null;
     
    366371    element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
    367372    element_values.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    368 
     373       
     374    JPanel subelement_details_pane = new JPanel();
     375    subelement_details_pane.setOpaque(false);
     376    JPanel subelement_name_pane = new JPanel();
     377    subelement_name_pane.setOpaque(false);
     378    JLabel subelement_name_label = new JLabel();
     379    subelement_name_label.setOpaque(false);
     380    JPanel subelement_inner_pane = new JPanel();
     381    subelement_inner_pane.setOpaque(false);
     382
     383    JPanel subelement_attributes_pane = new JPanel();
     384    subelement_attributes_pane.setOpaque(false);
     385    subelement_attributes_scroll = new JScrollPane();
     386    subelement_attributes_scroll.getViewport().setBackground(config.getColor("coloring.collection_tree_background", false));
     387    subelement_attributes_scroll.setOpaque(true);
     388    subelement_attributes = new SmarterTable();
     389    subelement_attributes.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     390    subelement_attributes.setBackground(config.getColor("coloring.collection_tree_background", false));
     391    subelement_attributes.setForeground(config.getColor("coloring.collection_tree_foreground", false));
     392    subelement_attributes.setHeadingBackground(config.getColor("coloring.collection_heading_background", false));
     393    subelement_attributes.setHeadingForeground(config.getColor("coloring.collection_heading_foreground", false));
     394    subelement_attributes.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
     395    subelement_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
     396    subelement_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     397        subelement_attributes.addMouseListener(popupListener);
     398    subelement_attributes.addMouseListener(new AddOrEditAttributeActionListener());
     399    subelement_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
     400   
    369401    JPanel element_novalues_pane = new JPanel();
    370402
     
    499531    remove_value.addActionListener(new RemoveValueActionListener());
    500532    element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes));
     533    subelement_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(subelement_attributes));
    501534    profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes));
    502535    set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes));
     
    547580    //element_details_pane.add(element_name_pane, BorderLayout.NORTH);
    548581    element_details_pane.add(element_inner_pane, BorderLayout.CENTER);
    549 
     582   
     583    subelement_name_pane.setLayout(new BorderLayout());
     584    subelement_attributes_scroll.setViewportView(subelement_attributes);
     585    subelement_attributes_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Attributes")), BorderFactory.createEmptyBorder(2,2,2,2)));
     586    subelement_attributes_pane.setLayout(new BorderLayout());
     587    subelement_attributes_pane.add(subelement_attributes_scroll, BorderLayout.CENTER);
     588   
     589
     590    subelement_inner_pane.setLayout(new BorderLayout());
     591    subelement_inner_pane.add(subelement_attributes_pane);
     592    subelement_details_pane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(Dictionary.get("GEMS.Subelement_Details")), BorderFactory.createEmptyBorder(2,2,2,2)));
     593    subelement_details_pane.setLayout(new BorderLayout());
     594    subelement_details_pane.add(subelement_inner_pane, BorderLayout.CENTER);
     595   
    550596    profile_name_pane.setLayout(new BorderLayout());
    551597    profile_name_pane.add(profile_name_label, BorderLayout.WEST);
     
    568614    details_pane.add(set_details_pane, SET);
    569615    details_pane.add(element_details_pane, ELEMENT);
     616    details_pane.add(subelement_details_pane, SUBELEMENT);
    570617    details_pane.add(profile_details_pane, PROFILE);
    571618
     
    936983    element_attributes = null;
    937984    set_attributes = null;
     985    subelement_attributes = null;
    938986    element_name = null;
    939987    set_name = null;
     
    9781026    }
    9791027
     1028    /**
     1029       Class to handle adding or modifying element attributes.
     1030     */
    9801031   private class AddOrEditAttributeActionListener
    9811032    extends ModalDialog
     
    10361087        target_label = new JLabel();
    10371088        target_label.setOpaque(false);
    1038         Dictionary.setText(target_label, "GEMS.Target");
    10391089        target = new JLabel();
    10401090        target.setOpaque(false);
     
    11471197       public void mouseClicked(MouseEvent e)
    11481198    {
    1149         if(e.getSource() == element_attributes || e.getSource() == set_attributes)
     1199        if(e.getSource() == element_attributes || e.getSource() == set_attributes || e.getSource() == subelement_attributes)
    11501200        {
    11511201            if(e.getClickCount() == 2) //Double click
     
    11871237        {
    11881238            target.setText(current_element.getName());
     1239            Dictionary.setText(target_label, "GEMS.Target");
    11891240        }
    11901241        else if(current_set != null)
     
    11921243            Dictionary.setText(target_label, "GEMS.Set");
    11931244            target.setText(current_set.toString());
     1245            Dictionary.setText(target_label, "GEMS.Target");
     1246        }
     1247        else if(current_subelement != null)
     1248        {
     1249            target.setText(current_subelement.getName());
     1250            Dictionary.setText(target_label, "GEMS.Subelement");
    11941251        }
    11951252       
    1196           //allow user to choose language when they create attr
    1197           /*         
    1198           if(source == popupListener.menuAddAttributeAttribute) { 
    1199             add_type =  true;
    1200         language_box.setEnabled(true);
    1201         System.err.println("source is menuAddAttributeAttribute"); //Debug
    1202           }//end if source== menuaddattributeattribute
    1203           else*/ if (source == popupListener.menuEditValue){
    1204           this.menuEditValue();
    1205              
    1206           }//end if source == popupListener.menuEditValue)
    1207         ///////////////////////////////////////////////
     1253         if (source == popupListener.menuEditValue)
     1254         {
     1255             this.menuEditValue();             
     1256         }
     1257 
    12081258            if(source == ok_button) {
    12091259        boolean success = true;
     
    12241274            success = addOrEditElementAttribute(model);
    12251275            break;
     1276           
     1277        case GEMSNode.SUBELEMENT:
     1278            model = (AttributeTableModel) subelement_attributes.getModel();
     1279            success = addOrEditSubelementAttribute(model);
     1280            break;
     1281           
    12261282        }
    12271283                 
     
    12331289                    return;
    12341290        }
    1235         else //debug
     1291        else
    12361292            {
     1293            //This should not happen.
    12371294            System.err.println("No success by OK button."); //debug
    12381295            }
     
    12611318        //setVisible(true);
    12621319        }
    1263         else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement){
     1320        else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement || source == popupListener.menuAddAttributeSubelement){
    12641321
    12651322        Dictionary.setText(this, "GEMS.AddAttribute");
     
    14311488           
    14321489           break;
     1490           
     1491       case GEMSNode.SUBELEMENT:
     1492           tablemodel = (AttributeTableModel) subelement_attributes.getModel();
     1493           //grab values in table
     1494           prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
     1495           prevValue = tablemodel.getValueAt(current_attribute,2).toString();
     1496           break;
     1497           
    14331498       default:
    14341499           //by default grab element_attr's
     
    14761541           model = (AttributeTableModel) element_attributes.getModel();
    14771542           break;
     1543           
     1544       case GEMSNode.SUBELEMENT:
     1545           model = (AttributeTableModel) subelement_attributes.getModel();
     1546           break;
     1547           
    14781548       case GEMSNode.SET:
    14791549           model = (AttributeTableModel) set_attributes.getModel();
     
    15881658           
    15891659        String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
    1590              
     1660       
    15911661        // Remove the existing attribute if this is an edit
    15921662        if(!add_type && current_attribute != -1) {
     
    16111681    }
    16121682
     1683       //Very similar to addOrEditElementAttribute
     1684       private boolean addOrEditSubelementAttribute(AttributeTableModel model)
     1685       {
     1686       //System.err.println("\ncurrent_attribute is: " + current_attribute + "current_attribute_type is: " + current_attribute_type); //debug
     1687
     1688       String name_str = name.getSelectedItem().toString();
     1689       String language_code = (String) language_box.getSelectedItem();
     1690
     1691       String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM);
     1692
     1693       //Remove the existing attribute if this is an edit.
     1694       if(!add_type && current_attribute != -1)
     1695           {
     1696           Attribute old_attribute = model.getAttribute(current_attribute);
     1697           String old_value_str = old_attribute.value;
     1698           String old_lang_code = old_attribute.language;
     1699           current_subelement.removeAttribute(name_str, old_lang_code, old_value_str);
     1700           //update the attribute table
     1701           model.removeRow(current_attribute);
     1702           }
     1703
     1704       //Add the new attribute
     1705       current_subelement.addAttribute(name_str, language_code, value_str);
     1706       //Update the attribute table
     1707       int row = model.add(new Attribute(name_str, language_code, value_str));
     1708       subelement_attributes.setRowSelectionInterval(row, row);
     1709
     1710       value_str = null;
     1711       language_code = null;
     1712       name_str = null;
     1713       return true;
     1714       }
     1715
    16131716
    16141717    public void dispose() {
     
    16191722        target = null;
    16201723        value = null;
    1621         ///ystem.err.println("Dispose AddOrEditAttributeActionListener");
    16221724        super.dispose();
    16231725    }
    16241726    }
    1625      
     1727
     1728
     1729    private class AddSubelementActionListener extends ModalDialog implements ActionListener {
     1730    private JButton cancel_button = null;
     1731    private JButton ok_button = null;
     1732    private JLabel element_field = null;
     1733    private NonWhitespaceField name_field = null;
     1734
     1735    public AddSubelementActionListener() {
     1736        super(self);
     1737        setModal(true);
     1738        setSize(ADD_ELEMENT_SIZE);
     1739        // Creation
     1740        JPanel content_pane = (JPanel) getContentPane();
     1741        content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
     1742        JPanel center_pane = new JPanel();
     1743        center_pane.setOpaque(false);
     1744        Dictionary.setText(this, "GEMS.Popup.menuAddSubelement");
     1745
     1746        JPanel labels_pane = new JPanel();
     1747        labels_pane.setOpaque(false);
     1748        JLabel element_label = new JLabel();
     1749        element_label.setOpaque(false);
     1750        Dictionary.setText(element_label, "GEMS.Element");
     1751        element_field = new JLabel();
     1752        element_field.setOpaque(false);
     1753
     1754        JPanel values_pane = new JPanel();
     1755        values_pane.setOpaque(false);
     1756        JLabel name_label = new JLabel();
     1757        name_label.setOpaque(false);
     1758        Dictionary.setText(name_label, "GEMS.Name");
     1759        name_field = new NonWhitespaceField();
     1760        name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
     1761        name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
     1762        name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
     1763        name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
     1764        Dictionary.setTooltip(name_field, "GEMS.Subelement_Name_Tooltip");
     1765
     1766        JPanel button_pane = new JPanel();
     1767        button_pane.setOpaque(false);
     1768
     1769        ok_button = new GLIButton();
     1770        ok_button.setMnemonic(KeyEvent.VK_O);
     1771        Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
     1772        cancel_button = new GLIButton();
     1773        cancel_button.setMnemonic(KeyEvent.VK_C);
     1774        Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
     1775
     1776        TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
     1777
     1778        // Connection
     1779        cancel_button.addActionListener(this);
     1780        ok_button.addActionListener(this);
     1781        ok_button_enabler.add(name_field);
     1782
     1783        // Layout
     1784        labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     1785        labels_pane.setLayout(new GridLayout(2,1));
     1786        labels_pane.add(element_label);
     1787        labels_pane.add(name_label);
     1788
     1789        values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
     1790        values_pane.setLayout(new GridLayout(2,1));
     1791        values_pane.add(element_field);
     1792        values_pane.add(name_field);
     1793
     1794        center_pane.setLayout(new BorderLayout(5,5));
     1795        center_pane.add(labels_pane, BorderLayout.WEST);
     1796        center_pane.add(values_pane, BorderLayout.CENTER);
     1797
     1798        button_pane.setLayout(new GridLayout(1,2,0,5));
     1799        button_pane.add(ok_button);
     1800        button_pane.add(cancel_button);
     1801
     1802        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     1803        content_pane.setLayout(new BorderLayout());
     1804        content_pane.add(center_pane, BorderLayout.CENTER);
     1805        content_pane.add(button_pane, BorderLayout.SOUTH);
     1806
     1807        //use size of Add Element dialog
     1808        setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2);
     1809    }
     1810
     1811    public void actionPerformed(ActionEvent event)
     1812    {
     1813        //System.err.println("You chose to add a new subelement!!\n"); //debug
     1814        Object source = event.getSource();
     1815
     1816        if(source == ok_button) //Add then dispose
     1817        {
     1818            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
     1819           
     1820            current_set = msm.getSet(current_element.getNamespace());
     1821            if(current_set != null)
     1822            {
     1823                 // If this subelement doesn't already exist.
     1824                if(!current_element.containsSubelement(name_str))
     1825                {
     1826                    // Add it,
     1827                    String language_code = config.getLanguage();
     1828                    //ElementWrapper subelement = current_set.addSubelementTest(current_element, name_str);
     1829                    ElementWrapper subelement = current_set.addSubelement(current_element, name_str, language_code);
     1830                    // Then update the tree
     1831                    model.add(current_node, subelement, GEMSNode.SUBELEMENT);
     1832                    //System.out.println("current_node is: " + current_node); //debug
     1833                   
     1834                    // Done
     1835                    subelement = null;
     1836                    setVisible(false);
     1837                    //mark as changed
     1838                    atLeastOneSetChanged = true;
     1839                    current_set.setSetChanged(true);
     1840                }
     1841                else
     1842                {
     1843                    //A subelement with the same name exists. Display an error message.
     1844                    JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Subelement_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     1845                }
     1846            }
     1847            else
     1848            {
     1849                //This should not happen.
     1850                System.err.println("current_set is null in AddSubelementActionListener!!");
     1851            }
     1852        }
     1853        else if(source == cancel_button)
     1854        {
     1855            setVisible(false);
     1856        }
     1857        else
     1858        {
     1859            element_field.setText(current_element.getName()); //set to the name of the element
     1860            name_field.setText("");
     1861            setVisible(true);
     1862        }
     1863    }
     1864
     1865    public void dispose()
     1866    {
     1867        cancel_button = null;
     1868        ok_button = null;
     1869        name_field = null;
     1870        element_field = null;
     1871        super.dispose();
     1872    }
     1873    }
     1874
     1875
    16261876    private class AddElementActionListener
    16271877    extends ModalDialog
     
    26582908            ((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute);
    26592909            }
     2910            else if(current_subelement != null)
     2911            {
     2912                //Remove subelement attribute
     2913                String name = (String)subelement_attributes.getValueAt(current_attribute, 0);
     2914                String language = (String) subelement_attributes.getValueAt(current_attribute, 1);
     2915                String value = (String) subelement_attributes.getValueAt(current_attribute, 2);
     2916                current_subelement.removeAttribute(name, language, value);
     2917
     2918                //Refresh table
     2919                ((AttributeTableModel)subelement_attributes.getModel()).removeRow(current_attribute);
     2920            }
    26602921            // Disable buttons
    26612922           // edit_attribute.setEnabled(false);
     
    26662927        }
    26672928        }
    2668     }
     2929        else
     2930        {
     2931            System.err.println("Tried to remove attribute, but current_attribute == -1!!"); //This should not happen
     2932        }
     2933    }
     2934    }
     2935
     2936    /**
     2937       Class to handle deletion of subelements.
     2938       This class can be created from either PopupHandler or KeyPressedHandler. KeyPressedHandler passes a null ActionEvent!!
     2939       @author: Matthew Whyte
     2940       @Date last modified: 18/01/04
     2941    */
     2942    private class RemoveSubelementActionListener implements ActionListener {
     2943    /** 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.
     2944     * @param event An <strong>ActionEvent</strong> containing information about the event.
     2945     */
     2946    public void actionPerformed(ActionEvent event)
     2947    {
     2948        if(current_subelement != null)
     2949        {
     2950            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]);
     2951            if(result ==0) //Continue with remove
     2952            {
     2953                TreeNode selPath = current_node.getParent();
     2954                GEMSNode parent = (GEMSNode)selPath;
     2955                current_element = parent.getElement();
     2956
     2957                ignore = true;
     2958                msm.removeElement(current_subelement, current_element); //remove the subelement.
     2959
     2960                // Clear selection
     2961                mds_tree.clearSelection();
     2962                model.remove(current_node); //This is a new way of doing things.
     2963                // Meanwhile disable/enable controls given we had an element selected, but no longer do.
     2964                remove_element.setEnabled(false);
     2965                // Show a blank panel.
     2966                card_layout.show(details_pane, BLANK);
     2967                ignore = false;
     2968               
     2969                atLeastOneSetChanged = true;
     2970            }
     2971        }
     2972        else
     2973        {
     2974            System.err.println("No subelement is selected."); //This should not happen
     2975        }
     2976    }
     2977
    26692978    }
    26702979
     
    26832992            ignore = true;
    26842993            //System.err.println("Current element's getElement: " + current_element.getElement()); //Debug
    2685             msm.removeElement(current_element);
     2994            msm.removeElement(current_element, null);
    26862995            // Clear selection
    26872996            mds_tree.clearSelection();
     
    28713180                model.add(null, current_set, GEMSNode.SET);
    28723181
     3182
    28733183                //Clean up
    28743184                card_layout.show(details_pane, BLANK); // Show a blank panel.
     
    29133223    }
    29143224
     3225    /**
     3226       Class to handle renaming of a subelement
     3227
     3228       Author: Matthew Whyte
     3229       Date last modified: 18/01/05
     3230     */
     3231    private class RenameSubelementActionListener extends RenameElementActionListener implements ActionListener {
     3232   
     3233    /**
     3234       Any implementation of ActionListener must include this method so that we can be informed when an action has occured.
     3235       @param event An <string>ActionEvent</strong> containing information about the event.
     3236    */
     3237    public void actionPerformed(ActionEvent event)
     3238    {
     3239        Object source = event.getSource();
     3240
     3241        if(source == ok_button)
     3242        {
     3243            TreeNode selPath = current_node.getParent();
     3244            GEMSNode parent = (GEMSNode)selPath;
     3245            current_element = parent.getElement();
     3246            //MetadataSet currentSet = msm.getSet(current_subelement.getNamespace());
     3247
     3248            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
     3249
     3250            if(!current_element.containsSubelement(name_str)) //Hopefully this works!
     3251                {   
     3252                //Hide the element that are about to rename
     3253                mds_tree.clearSelection();
     3254                model.remove(current_node);
     3255               
     3256                msm.renameElement(current_subelement, name_str); //rename the element
     3257               
     3258                model.add(parent, current_subelement, GEMSNode.SUBELEMENT);
     3259               
     3260                //Could now select the new element, but for now will just clean up ;-)
     3261                // Disable/enable controls given we had an element selected, but no longer do.
     3262                remove_element.setEnabled(false);
     3263                card_layout.show(details_pane, BLANK); // Show a blank panel.
     3264                ignore = false;
     3265                   
     3266                atLeastOneSetChanged = true;
     3267                setVisible(false);
     3268                }
     3269           
     3270            // Otherwise show an error message and do not proceed.
     3271            else
     3272                {
     3273                JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Subelement_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     3274                }
     3275
     3276            name_str = null;
     3277        }
     3278       
     3279        else if(source == cancel_button)
     3280        {
     3281            setVisible(false); //hide dialog
     3282        }
     3283        else
     3284        {
     3285            Dictionary.setText(this, "GEMS.Popup.menuRenameSubelement"); //Set title of dialog
     3286            name_field.setText(current_subelement.getNameOnly()); //show old name
     3287            setVisible(true); //Show the dialog
     3288        }
     3289           
     3290        source = null;
     3291    }
     3292    }
     3293
    29153294 /**
    2916        Class to hand renaming of an element.
     3295       Class to handle renaming of an element.
    29173296
    29183297       Author: Matthew Whyte
     
    29213300    private class RenameElementActionListener extends ModalDialog implements ActionListener {
    29223301
    2923     private JButton cancel_button = null;
    2924     private JButton ok_button = null;
     3302    protected JButton cancel_button = null;
     3303    protected JButton ok_button = null;
    29253304    //private JLabel label = null;
    2926     private NonWhitespaceField name_field = null;
     3305    protected NonWhitespaceField name_field = null;
    29273306
    29283307       
     
    30563435        else
    30573436        {
    3058             name_field.setText(current_element.getName()); //show old name
     3437            name_field.setText(current_element.getNameOnly()); //show old name (without namespace)
    30593438            setVisible(true); //Show the dialog
    30603439        }
     
    30803459    /**
    30813460       Class to handle DELETE key presses on the tree.
    3082        The class then fires the appropriate event to remove that element/set.
     3461       The class then fires the appropriate event to remove that subelement/element/set.
    30833462       Attributes in the table are handled directly by the RemoveAttributeActionListener
    30843463
     
    31183497            GEMSNode t = (GEMSNode)selPath.getLastPathComponent();
    31193498           
    3120             if(t.type == T_ELEMENT) //Remove the element
     3499            if(t.type == T_SUBELEMENT) //Remove the subelement
     3500                {
     3501                RemoveSubelementActionListener removeSubelement = new RemoveSubelementActionListener();
     3502                removeSubelement.actionPerformed((ActionEvent)null);
     3503                }
     3504            else if(t.type == T_ELEMENT) //Remove the element
    31213505                {
    31223506                //System.err.println("element");
     
    33223706    public void valueChanged(TreeSelectionEvent event) {
    33233707        if(!ignore) {
     3708        GValueModel value_model = null;
    33243709        // Clear all variables based on previous tree selection
    33253710        current_collection_file = null;
     
    33583743           // setControls(true, false, false, true, false, false, true, false, false, false, false, false);
    33593744            break;
     3745
     3746        case GEMSNode.SUBELEMENT:
     3747            current_subelement = current_node.getSubelement();
     3748           
     3749            atm = current_node.getModel();
     3750            if(atm == null) {
     3751            atm = new AttributeTableModel(current_subelement.getAttributes(), Dictionary.get("GEMS.Name"), Dictionary.get("GEMS.Language_Code"), Dictionary.get("GEMS.Value"), "");
     3752            }
     3753
     3754            subelement_attributes.setModel(atm);
     3755            atm.setScrollPane(subelement_attributes_scroll);
     3756            atm.setTable(subelement_attributes);
     3757            //System.err.println("atm is: " + atm); //debug
     3758
     3759            card_layout.show(details_pane, SUBELEMENT);
     3760            //card_layout.show(details_pane, BLANK);
     3761            break;
     3762
    33603763        case GEMSNode.ELEMENT:
    33613764            current_element = current_node.getElement();
     
    33693772            atm.setTable(element_attributes);
    33703773
     3774            //System.err.println("atm is: " + atm); //debug
     3775
    33713776            // Be careful not to add the keep_root_expanded_listener over and over!
    3372             GValueModel value_model = msm.getValueTree(current_element);
     3777            value_model = msm.getValueTree(current_element);
    33733778            if(value_model != null) {
    33743779            value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there
     
    33803785            }
    33813786            else {
     3787            System.err.println("ELEMENT: value_model is null"); //debug
    33823788            element_values_layout.show(element_values_pane, BLANK);
    33833789            // Meanwhile disable/enable controls depending on this Element selection.
     
    34423848  class PopupListener extends MouseAdapter implements ActionListener{
    34433849        JPopupMenu setPopup;
    3444         JPopupMenu subfieldPopup;
     3850        JPopupMenu subelementPopup;
    34453851        JPopupMenu elementPopup;
    34463852        JPopupMenu attributePopup;
     
    34513857      JMenuItem menuAddAttributeSet;
    34523858
    3453         JMenuItem menuRenameSubfield;
    3454         JMenuItem menuDeleteSubfield;
    3455         JMenuItem menuAddAttributeSubfield;
     3859        JMenuItem menuRenameSubelement;
     3860        JMenuItem menuDeleteSubelement;
     3861        JMenuItem menuAddAttributeSubelement;
    34563862        JMenuItem menuRenameElement;
    34573863       
    34583864        JMenuItem menuDeleteElement;
    34593865        JMenuItem menuAddAttributeElement;
    3460         JMenuItem menuAddSubfield;
     3866        JMenuItem menuAddSubelement;
    34613867       
    34623868        JMenuItem menuEditValue;
     
    34693875        PopupListener(GEMS g) {
    34703876        setPopup = new JPopupMenu();
    3471         subfieldPopup = new JPopupMenu();
     3877        subelementPopup = new JPopupMenu();
    34723878        elementPopup = new JPopupMenu();
    34733879        attributePopup = new JPopupMenu();
     
    35013907       Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip");
    35023908       
    3503             //subfield related GEMS.Popups
    3504             menuRenameSubfield = new JMenuItem();
    3505             Dictionary.setText(menuRenameSubfield,"GEMS.Popup.menuRenameSubfield");
    3506            
    3507             menuDeleteSubfield=new JMenuItem();
    3508             Dictionary.setText(menuDeleteSubfield,"GEMS.Popup.menuRemoveSubfield");
    3509            
    3510             menuAddAttributeSubfield=new JMenuItem();
    3511            // Dictionary.setText(menuAddAttributeSubfield,"GEMS.Popup.menuAddAttribute");
    3512              Dictionary.setText(menuAddAttributeSubfield,"GEMS.Add_Attribute_Tooltip");
     3909            //subelement related GEMS.Popups
     3910            menuRenameSubelement = new JMenuItem();
     3911            Dictionary.setText(menuRenameSubelement,"GEMS.Popup.menuRenameSubelement");
     3912           
     3913            menuDeleteSubelement=new JMenuItem();
     3914            Dictionary.setText(menuDeleteSubelement,"GEMS.Popup.menuRemoveSubelement");
     3915           
     3916            menuAddAttributeSubelement=new JMenuItem();
     3917           // Dictionary.setText(menuAddAttributeSubelement,"GEMS.Popup.menuAddAttribute");
     3918             Dictionary.setText(menuAddAttributeSubelement,"GEMS.Add_Attribute_Tooltip");
    35133919           
    35143920            //element related GEMS.Popups
     
    35253931            Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip");
    35263932           
    3527             menuAddSubfield=new JMenuItem();
    3528             Dictionary.setText(menuAddSubfield,"GEMS.Popup.menuAddSubfield");
    3529              //Dictionary.setText(menuAddSubfield,"GEMS.Add_Subfield");
     3933            menuAddSubelement=new JMenuItem();
     3934            Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement");
     3935             //Dictionary.setText(menuAddSubelement,"GEMS.Add_Subelement");
    35303936       
    35313937            //attribute related GEMS.Popups
     
    35543960        setPopup.add(menuRemoveSet);
    35553961             
    3556              //subfieldPopup.add(menuRenameSubfield);
    3557              subfieldPopup.add(menuDeleteSubfield);
    3558              subfieldPopup.add(menuAddAttributeSubfield);
     3962             subelementPopup.add(menuRenameSubelement);
     3963             subelementPopup.add(menuDeleteSubelement);
     3964             subelementPopup.add(menuAddAttributeSubelement);
     3965         subelementPopup.add(menuAddSubelement);
    35593966             
    35603967             elementPopup.add(menuRenameElement);
    35613968             elementPopup.add(menuDeleteElement);
    35623969             elementPopup.add(menuAddAttributeElement);
    3563              //elementPopup.add(menuAddSubfield);
     3970             elementPopup.add(menuAddSubelement);
    35643971             
    35653972             attributePopup.add(menuEditValue);
     
    35733980             menuAddElement.addActionListener(new AddElementActionListener());
    35743981             menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener());
    3575              menuRenameSubfield.addActionListener(this);
    3576              menuDeleteSubfield.addActionListener(this);
    3577              menuAddAttributeSubfield.addActionListener(this);
     3982             menuRenameSubelement.addActionListener(new RenameSubelementActionListener());
     3983             menuDeleteSubelement.addActionListener(new RemoveSubelementActionListener());
     3984             menuAddAttributeSubelement.addActionListener(new AddOrEditAttributeActionListener());
    35783985             
    35793986         menuRenameSet.addActionListener(new RenameSetActionListener());
     
    35813988             menuDeleteElement.addActionListener(new RemoveElementActionListener());
    35823989             menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener());
    3583              menuAddSubfield.addActionListener(this);
     3990             menuAddSubelement.addActionListener(new AddSubelementActionListener());
    35843991             
    35853992            // menuEditValue.addActionListener(new AddOrEditAttributeActionListener());
     
    36454052            /*  else if(t.type == T_ELEMENT){
    36464053           
    3647             subfieldPopup.show(e.getComponent(),
     4054            subelementPopup.show(e.getComponent(),
    36484055                       e.getX(), e.getY());
    36494056                }
    36504057            */
     4058            else if(t.type == T_SUBELEMENT)
     4059            {
     4060                subelementPopup.show(e.getComponent(), e.getX(), e.getY());
     4061            }
     4062
    36514063            else if(t.type == T_ROOT){
    36524064           
     
    36894101                           e.getX(), e.getY());
    36904102             }
    3691                
     4103         else if(e.getSource() == subelement_attributes)  { //When right-click on table of subelement attributes
     4104         
     4105         //Select the table row that was right-clicked on.
     4106         p = e.getPoint();
     4107         subelement_attributes.changeSelection(subelement_attributes.rowAtPoint(p), subelement_attributes.columnAtPoint(p), false, false);
     4108
     4109         attributePopup.show(e.getComponent(),
     4110                     e.getX(), e.getY());
     4111             }
    36924112             
    36934113               
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java

    r8270 r8930  
    8383        }
    8484        }
    85         // If this is a set and we are looking for an element, then iterate through its children. Can't really do this recursively.
    86         else if(type == GEMSNode.ELEMENT && child.getType() == GEMSNode.SET) {
     85        // If this is a set and we are looking for an element or subelement, then iterate through its children. Can't really do this recursively.
     86        else if((type == GEMSNode.ELEMENT || type == GEMSNode.SUBELEMENT) && child.getType() == GEMSNode.SET) {
    8787        for(int j = 0; j < child.getChildCount(); j++) {
    8888            GEMSNode inner_child = (GEMSNode) child.getChildAt(j);
    89             if(inner_child.toString().equals(name)) {
    90             // Place on AWT event thread to avoid errors.
    91             SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
    92             return;
    93             }
     89            //Go through looking for element
     90            if(type == GEMSNode.ELEMENT)
     91            {
     92                if(inner_child.toString().equals(name)) {
     93                // Place on AWT event thread to avoid errors.
     94                SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
     95                return;
     96                }
     97            }
     98            //Go through element looking for subelement
     99            else if(type == GEMSNode.SUBELEMENT)
     100            {
     101                for(int k = 0; k < inner_child.getChildCount(); k++)
     102                {
     103                    //the subelements
     104                    GEMSNode innermost_child = (GEMSNode)inner_child.getChildAt(k);
     105                    if(innermost_child.toString().equals(name))
     106                    {
     107                        // Place on AWT event thread to avoid errors.
     108                        SynchronizedTreeModelTools.removeNodeFromParent(this, inner_child);
     109                        return;
     110                    }
     111                }
     112            }
    94113        }
    95114        }
    96115    }
     116
     117    System.err.println("Tried to remove \'" + name + "\' from the tree, but could not find it!"); //This should not happen!
     118    }
     119
     120    /**
     121       Remove a node from the tree.
     122       @param node the node to remove, as a <strong>GEMSNode</strong>
     123       @author Matthew Whyte
     124       @date last modified: 21/01/04
     125     */
     126    public void remove(GEMSNode node)
     127    {
     128    SynchronizedTreeModelTools.removeNodeFromParent(this, node);
     129    return;
    97130    }
    98131}
  • trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java

    r8375 r8930  
    6262    static final public int ROOT       = 3;
    6363    static final public int SET        = 4;
     64    static final public int SUBELEMENT = 5;
    6465
    6566    public GEMSNode() {
     
    103104        result = (ElementWrapper) userObject;
    104105    }
     106    return result; 
     107    }
     108
     109    public ElementWrapper getSubelement() {
     110    ElementWrapper result = null;
     111    if(type == SUBELEMENT) {
     112        result = (ElementWrapper) userObject;
     113    }
    105114    return result;
    106115    }
     116
    107117    public int getIndex(TreeNode node) {
    108118    if(children == null) {
     
    201211
    202212    // How we build children depends on the node type
    203     if (type == SET) {
    204         // Add the elements as children
    205         MetadataSet set = (MetadataSet) userObject;
    206         NodeList elements = set.getElements();
    207         for (int i = 0; i < elements.getLength(); i++) {
    208                
    209         children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.item(i)), this));
    210         }
    211     }
     213    if (type == SET)
     214        {
     215        // Add the elements as children
     216        MetadataSet set = (MetadataSet) userObject;
     217        NodeList elements = set.getElements();
     218        for (int i = 0; i < elements.getLength(); i++)
     219            {
     220            children.add(new GEMSNode(ELEMENT, new ElementWrapper((Element) elements.item(i)), this));
     221            }
     222        }
     223    if (type == ELEMENT) //Add subelements
     224        {
     225        NodeList subelements = this.getElement().getSubelements();
     226        for(int j = 0; j < subelements.getLength(); j++)
     227            {
     228            children.add(new GEMSNode(SUBELEMENT, new ElementWrapper((Element)subelements.item(j)), this));
     229            }
     230        }
     231
    212232    }
    213233   
  • trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java

    r8809 r8930  
    128128    }
    129129
     130    /**
     131       @author: Matthew Whyte
     132       @date last modified: 17/01/04
     133
     134       This will need modifications!!!
     135       Maybe this should not be here.
     136    */
     137    static public void addSubelement(Element element_element, String subelement_name)
     138    {
     139    Document document = element_element.getOwnerDocument();
     140    //Create the new subelement
     141    Element subelement = document.createElement("Subelement");
     142    subelement.setAttribute(StaticStrings.NAME_ATTRIBUTE, subelement_name);
     143   
     144    //Add the attribute the old fashioned way.
     145    element_element.appendChild(subelement);
     146
     147    //Clean up
     148    subelement = null;
     149    document = null;
     150    }
     151
    130152    /** A method for comparing two AssignedValues trees. This compares not only the Subject hierarchies but also the values themselves.
    131153     * @param avt A <strong>Node</strong> which is the root of an AssignedValues tree.
     
    298320    TreeSet attribute_tree = new TreeSet();
    299321       
    300        
    301        // GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
     322    // GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
    302323        GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
    303324       
     
    311332            attribute_tree.add(new Attribute(some_element.getAttribute(StaticStrings.NAME_ATTRIBUTE), some_element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE), MSMUtils.getValue(some_element)));
    312333                    // System.out.println(some_element_name +  "<- some_element nodes' value");
    313                  
    314                
    315334                }
    316335        else if(some_element_name.equals(StaticStrings.LANGUAGE_ELEMENT)) {
    317336                    ///Added by Attila on Nov 05 04
    318                    // System.out.println(some_element_name +  "<- some_element nodes' value");
    319                    
    320                    
    321                     ////
     337            //System.out.println(some_element_name +  "<- some_element nodes' value"); //debug
    322338                   
    323339            String language_code = some_element.getAttribute(StaticStrings.CODE_ATTRIBUTE);
     
    326342            for(int i = 0; i < attribute_elements.getLength(); i++) {
    327343            Element attribute_element = (Element) attribute_elements.item(i);
    328                      
    329344                     
    330                             //System.out.println("code is:" + language_code);
    331                        
    332                            
    333345                            for(int k = 0; k < enabled_langs.length; k++){
    334346                               
    335347                               if(enabled_langs[k].trim().compareTo(some_element.getAttributes().item(0).getNodeValue().toString()) == 0){
    336                                    
    337                                
    338                                
     348                     
    339349                                 attribute_tree.add(new Attribute(attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE), language_code, MSMUtils.getValue(attribute_element)));
    340350                     attribute_element = null;
     
    363373        }
    364374    }
    365      //  attribute_tree.
    366375    return attribute_tree;
    367376    }
     
    543552    // Retrieve this elements name
    544553    name_buffer.append(element.getAttribute("name"));
     554
    545555    // Now we check if element has a parent node, other than root. If so we begin building up the full name
     556    //For some reason this doesn't work in specific cases of subelements.
    546557    Element parent_element = (Element) element.getParentNode();
    547     while(parent_element != null && parent_element != root) {
     558    while(parent_element != null && parent_element != root) { 
    548559        name_buffer.insert(0, SF_SEP);
    549560        name_buffer.insert(0, parent_element.getAttribute("name"));
     
    566577    } // static public String getFullName(Element element)
    567578
     579    /**
     580       Method to get an element's name, not including its namespace.
     581       @param element an <strong>Element</strong> whose name we are interested in.
     582       @return A <strong>Strong</strong> representing the given elements name
     583       @author Matthew Whyte
     584       @date last modified: 21/01/04
     585     */
     586    static final public String getNameOnly(Element element)
     587    {
     588    StringBuffer name_buffer = new StringBuffer();
     589    if(element == null) {
     590        return "Error";
     591    }
     592    // Retrieve this elements name
     593    name_buffer.append(element.getAttribute("name"));
     594
     595    return name_buffer.toString();
     596    }
     597
     598
    568599    /** Method to construct an elements name (sic identifier) by retrieving the correct attribute, language specific.
    569600     * @param element the Element whose name we wish to retrieve
     
    579610        identifier = element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
    580611    }
     612
    581613    return identifier;
    582614    }
     615
     616
    583617
    584618    /** Method to retrieve from the node given, a certain child node with the specified name.
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java

    r8898 r8930  
    177177    }
    178178
     179    /**
     180       Add a new subelement with the name given to parent_element in this metadata set.
     181       @param name The name of this element as a <strong>String</strong>.
     182       @param parent_element The <strong>ElementWrapper</strong> that parents the subelement.
     183       @param language The two letter language code as a <strong>String</strong>
     184       @return An <strong>SubelementWrapper</strong> around the newly created subelement.
     185       @author Matthew Whyte
     186       @date last modified: 18/01/05
     187     */
     188    public ElementWrapper addSubelement(ElementWrapper parent_element, String name, String language)
     189    {
     190    //The language-dependent 'label' of the subelement. By default is same as name.
     191    Text text = document.createTextNode(name);
     192    Element label = document.createElementNS("", "Attribute");
     193    label.setAttribute("name", "label");
     194    label.setAttribute("language", language);
     195    label.appendChild(text);
     196
     197    //The subelement.
     198    Element subelement = document.createElementNS("", "Subelement");
     199    subelement.setAttribute("name", name);
     200    subelement.appendChild(label);
     201
     202    Element parent = parent_element.getElement(); //The parent element
     203    parent.appendChild(subelement);
     204    return new ElementWrapper(subelement);
     205    }
     206
     207
    179208    /** Add a new default metadata element with the given name to this metadata set.
    180209     * @param name The name of this element as a <strong>String</strong>.
     
    478507     * @param element The <strong>Element</strong> to be removed.
    479508     */
    480     public void removeElement(Element element) {
     509    public void removeElement(Element element, ElementWrapper parent_wrapped) {
    481510    // we need to remove the value tree too!!
    482511    //System.err.println("removeElement in MetadataSet: element is: " + element); //Debug
    483512
    484513    try {
    485         removeValueTree(new ElementWrapper(element));
    486         root.removeChild(element);
     514        ElementWrapper element_wrapped = new ElementWrapper(element);
     515        removeValueTree(element_wrapped);
     516        if(element_wrapped.isSubelement())
     517        {
     518            //Want to remove subelement.
     519            //System.err.println("Wanna remove subelement"); //debug
     520            Element parent = parent_wrapped.getElement();
     521            parent.removeChild(element);
     522        }
     523        else
     524        {
     525            root.removeChild(element);
     526        }
    487527
    488528    } catch(Exception DOMException) { //The element does not exist!!
     
    508548     */
    509549    public GValueModel removeValueTree(ElementWrapper element) {
    510     for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); ) {
    511         ElementWrapper sibling = (ElementWrapper) keys.nextElement();
    512         if(sibling.equals(element)) {
    513         GValueModel value_tree = (GValueModel) value_trees.get(sibling);
    514         value_trees.remove(sibling);
    515         return value_tree;
    516         }
    517     }
     550    for(Enumeration keys = value_trees.keys(); keys.hasMoreElements(); )
     551        {
     552        ElementWrapper sibling = (ElementWrapper) keys.nextElement();
     553        if(sibling.equals(element))
     554            {
     555            GValueModel value_tree = (GValueModel) value_trees.get(sibling);
     556            value_trees.remove(sibling);
     557            return value_tree;
     558            }
     559        }
    518560    return null;
    519561    }
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java

    r8896 r8930  
    110110       @param: new_name: The new (language-dependent) name for the current_set. Multiple names in different languages is not yet implemented in GEMS, but when it is, this method will need to be updated.
    111111
    112        @Pre: There is not another metadata set with namespace new_namespace. Ie namespaces are unique.
    113        @Post: The Name and namespace in the metadata file will have been updated. The filename will stay the same.
     112       @pre: There is not another metadata set with namespace new_namespace. Ie namespaces are unique.
     113       @post: The Name and namespace in the metadata file will have been updated. The filename will stay the same.
    114114
    115115       @author Matthew Whyte
     
    376376        //already loaded-Attila
    377377        for(Enumeration keys = mds_hashtable.keys(); keys.hasMoreElements(); ) {
    378         tempSet = (MetadataSet)mds_hashtable.get(keys.nextElement()); 
    379            
     378        //System.err.println("keys: " + keys.nextElement() + "\n"); //debug
     379        tempSet = (MetadataSet)mds_hashtable.get(keys.nextElement());       
    380380            all_sets[i] = tempSet.getFile();
    381381            i++;
     
    426426    }
    427427
    428 
    429     public void removeElement(ElementWrapper element) {
     428    /**
     429       Method to remove an element or subelement from a metadata set
     430       @param element the element to remove, as an <strong>ElementWrapper</strong>
     431       @param parent the parent of the element, as an <strong>ElementWrapper</strong> This is required if removing a subelement (can be null otherwise)
     432       @return void
     433       Modified by Matthew Whyte 19/01/04
     434     */
     435    public void removeElement(ElementWrapper element, ElementWrapper parent) {
    430436    // Retrieve the metadata set this element belongs to.
    431437    String namespace = element.getNamespace();
     438    //System.err.println("namespace is: " + namespace); //debug
    432439    MetadataSet set = (MetadataSet) mds_hashtable.get(namespace);
    433440    if(set != null) {
    434441        // Bugger. Get the old name -before- we remove the element from the set.
    435         String old_name = element.toString();
    436         // Remove the element.
    437        
    438         set.removeElement(element.getElement());
     442        //String old_name = element.toString();
     443        set.removeElement(element.getElement(), parent); //Remove the element
    439444    }
    440445    else {
    441         ///ystem.err.println("no such set " + namespace);
    442     }
    443     // No such set. No such element.
    444     }
     446        //This should not happen - no such set, no such element.
     447        System.err.println("Cannot remove element \'" + element + "\' because there is no such set \'" + namespace + "\'");
     448    }
     449    }
     450
    445451
    446452 /**
     
    457463    if(set != null)
    458464        {
     465        //System.err.println("newName is: " + newName); //debug
    459466        set.renameElement(oldElement.getElement(), newName); //Rename the element
    460467        }
Note: See TracChangeset for help on using the changeset viewer.