- Timestamp:
- 2005-01-25T16:32:41+13:00 (19 years ago)
- Location:
- trunk/gli
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/classes/dictionary.properties
r8882 r8930 1087 1087 GEMS.Popup.menuAddElement:Add element 1088 1088 GEMS.Popup.menuAddSet:Add a new set 1089 GEMS.Popup.menuAddSub field:Add subfield1089 GEMS.Popup.menuAddSubelement:Add subelement 1090 1090 1091 1091 GEMS.Popup.menuEditValue:Edit value … … 1093 1093 GEMS.Popup.menuRenameElement:Rename element 1094 1094 GEMS.Popup.menuRenameSet:Rename set 1095 GEMS.Popup.menuRenameSub field:Rename subfield1095 GEMS.Popup.menuRenameSubelement:Rename subelement 1096 1096 1097 1097 GEMS.Popup.menuRemoveAttribute:Remove attribute 1098 1098 GEMS.Popup.menuRemoveElement:Remove element 1099 1099 GEMS.Popup.menuRemoveSet:Remove set 1100 GEMS.Popup.menuRemoveSub field:Remove subfield1100 GEMS.Popup.menuRemoveSubelement:Remove subelement 1101 1101 1102 GEMS.Preferences.Use_Sub fields: Use Subfields?1103 GEMS.Preferences.Use_Sub fields_Tooltip: Toggle on or off whether you want to be able to manage subfields.1102 GEMS.Preferences.Use_Subelements: Use Subelements? 1103 GEMS.Preferences.Use_Subelements_Tooltip: Toggle on or off whether you want to be able to manage subelements. 1104 1104 GEMS.Preferences.Selected_Languages_Tooltip: Selected languages to display: 1105 1105 GEMS.Menu.File: File … … 1122 1122 GEMS.Add_Attribute_Tooltip:Add a new attribute to the selected item 1123 1123 GEMS.Add_Element_Tooltip:Add a new element to the selected set 1124 GEMS.Add_Subelement_Tooltip:Add a new subelement to the seclect element 1124 1125 GEMS.Add_File_Tooltip:Add a new importing profile 1125 1126 GEMS.Add_Set_Tooltip:Add a new metadata set … … 1166 1167 GEMS.Rename_Element:Rename Element 1167 1168 GEMS.Rename_Element_Tooltip:The element's new name 1169 GEMS.Rename_Name_Tooltip:The metadata set's new name 1170 GEMS.Rename_Namespace_Tooltip:The metadata set's unique namespace 1171 GEMS.Rename_Set:Rename Set 1168 1172 GEMS.Set:Set 1169 1173 GEMS.Set_Details:Metadata Set Details … … 1172 1176 GEMS.Source:From 1173 1177 GEMS.Subject:Subject 1178 GEMS.Subelement:Subelement 1179 GEMS.Subelement_Details:Metadata Subelement Details 1180 GEMS.Subelement_Name_Tooltip:The name of the new subelement 1181 GEMS.Subelement_Already_Exists:A subelement with this name already exists. 1174 1182 GEMS.Target:Element 1175 1183 GEMS.Title:Greenstone Editor for Metadata Sets -
trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java
r8881 r8930 61 61 private String namespace = ""; 62 62 63 private NodeList subelements = null; //The list of subelements 64 63 65 private Troolean is_extracted = new Troolean(); 64 66 /** Constructor for elements with no namespace necessary. … … 69 71 //System.err.println("ElementWrapper: element is: " + element); //debug 70 72 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? 75 80 } 76 81 … … 81 86 public void addAttribute(String name, String language, String value) { 82 87 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; 83 140 } 84 141 … … 137 194 return MSMUtils.getIdentifier(element); 138 195 } 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 139 207 /** Retrieve the name of this element. Name is unique. 140 208 * @return The name as a <strong>String</strong>. … … 142 210 */ 143 211 public String getName() { 144 return MSMUtils.getFullName(element, namespace); 145 } 212 return MSMUtils.getFullName(element, namespace); 213 } 214 215 146 216 /** Retrieve the namespace prefix for this element wrapper. 147 217 * @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 100 100 static final private String PROFILE = "profile"; 101 101 static final private String SET = "set"; 102 static final private String SUBELEMENT = "subelement"; 102 103 static final private String VALUES = "values"; 103 104 … … 111 112 static final public int T_ROOT = 3; 112 113 static final public int T_SET = 4; 114 static final public int T_SUBELEMENT = 5; 113 115 114 116 // static final public String MAX_LOADED_SETS = 64; … … 132 134 private Dimension screen_size = null; 133 135 private ElementWrapper current_element = null; 136 private ElementWrapper current_subelement = null; 134 137 private GValueNode current_value_node = null; 135 138 /** A reference to ourselves so our inner classes can dispose of us. */ … … 156 159 private JScrollPane profile_attributes_scroll = null; 157 160 private JScrollPane set_attributes_scroll = null; 161 private JScrollPane subelement_attributes_scroll = null; 158 162 private JPanel details_pane = null; 159 163 private JPanel element_values_pane = null; … … 164 168 private Object target = null; 165 169 public RemoveSetActionListener remove_set_action_listener; 170 private SmarterTable subelement_attributes = null; 166 171 private SmarterTable element_attributes = null; 167 172 private SmarterTable profile_attributes = null; … … 366 371 element_values.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 367 372 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 369 401 JPanel element_novalues_pane = new JPanel(); 370 402 … … 499 531 remove_value.addActionListener(new RemoveValueActionListener()); 500 532 element_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(element_attributes)); 533 subelement_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(subelement_attributes)); 501 534 profile_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(profile_attributes)); 502 535 set_attributes.getSelectionModel().addListSelectionListener(new AttributesListSelectionListener(set_attributes)); … … 547 580 //element_details_pane.add(element_name_pane, BorderLayout.NORTH); 548 581 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 550 596 profile_name_pane.setLayout(new BorderLayout()); 551 597 profile_name_pane.add(profile_name_label, BorderLayout.WEST); … … 568 614 details_pane.add(set_details_pane, SET); 569 615 details_pane.add(element_details_pane, ELEMENT); 616 details_pane.add(subelement_details_pane, SUBELEMENT); 570 617 details_pane.add(profile_details_pane, PROFILE); 571 618 … … 936 983 element_attributes = null; 937 984 set_attributes = null; 985 subelement_attributes = null; 938 986 element_name = null; 939 987 set_name = null; … … 978 1026 } 979 1027 1028 /** 1029 Class to handle adding or modifying element attributes. 1030 */ 980 1031 private class AddOrEditAttributeActionListener 981 1032 extends ModalDialog … … 1036 1087 target_label = new JLabel(); 1037 1088 target_label.setOpaque(false); 1038 Dictionary.setText(target_label, "GEMS.Target");1039 1089 target = new JLabel(); 1040 1090 target.setOpaque(false); … … 1147 1197 public void mouseClicked(MouseEvent e) 1148 1198 { 1149 if(e.getSource() == element_attributes || e.getSource() == set_attributes )1199 if(e.getSource() == element_attributes || e.getSource() == set_attributes || e.getSource() == subelement_attributes) 1150 1200 { 1151 1201 if(e.getClickCount() == 2) //Double click … … 1187 1237 { 1188 1238 target.setText(current_element.getName()); 1239 Dictionary.setText(target_label, "GEMS.Target"); 1189 1240 } 1190 1241 else if(current_set != null) … … 1192 1243 Dictionary.setText(target_label, "GEMS.Set"); 1193 1244 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"); 1194 1251 } 1195 1252 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 1208 1258 if(source == ok_button) { 1209 1259 boolean success = true; … … 1224 1274 success = addOrEditElementAttribute(model); 1225 1275 break; 1276 1277 case GEMSNode.SUBELEMENT: 1278 model = (AttributeTableModel) subelement_attributes.getModel(); 1279 success = addOrEditSubelementAttribute(model); 1280 break; 1281 1226 1282 } 1227 1283 … … 1233 1289 return; 1234 1290 } 1235 else //debug1291 else 1236 1292 { 1293 //This should not happen. 1237 1294 System.err.println("No success by OK button."); //debug 1238 1295 } … … 1261 1318 //setVisible(true); 1262 1319 } 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){ 1264 1321 1265 1322 Dictionary.setText(this, "GEMS.AddAttribute"); … … 1431 1488 1432 1489 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 1433 1498 default: 1434 1499 //by default grab element_attr's … … 1476 1541 model = (AttributeTableModel) element_attributes.getModel(); 1477 1542 break; 1543 1544 case GEMSNode.SUBELEMENT: 1545 model = (AttributeTableModel) subelement_attributes.getModel(); 1546 break; 1547 1478 1548 case GEMSNode.SET: 1479 1549 model = (AttributeTableModel) set_attributes.getModel(); … … 1588 1658 1589 1659 String value_str = Codec.transform(Codec.transformUnicode(value.getText()), Codec.TEXT_TO_DOM); 1590 1660 1591 1661 // Remove the existing attribute if this is an edit 1592 1662 if(!add_type && current_attribute != -1) { … … 1611 1681 } 1612 1682 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 1613 1716 1614 1717 public void dispose() { … … 1619 1722 target = null; 1620 1723 value = null; 1621 ///ystem.err.println("Dispose AddOrEditAttributeActionListener");1622 1724 super.dispose(); 1623 1725 } 1624 1726 } 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 1626 1876 private class AddElementActionListener 1627 1877 extends ModalDialog … … 2658 2908 ((AttributeTableModel)set_attributes.getModel()).removeRow(current_attribute); 2659 2909 } 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 } 2660 2921 // Disable buttons 2661 2922 // edit_attribute.setEnabled(false); … … 2666 2927 } 2667 2928 } 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 2669 2978 } 2670 2979 … … 2683 2992 ignore = true; 2684 2993 //System.err.println("Current element's getElement: " + current_element.getElement()); //Debug 2685 msm.removeElement(current_element );2994 msm.removeElement(current_element, null); 2686 2995 // Clear selection 2687 2996 mds_tree.clearSelection(); … … 2871 3180 model.add(null, current_set, GEMSNode.SET); 2872 3181 3182 2873 3183 //Clean up 2874 3184 card_layout.show(details_pane, BLANK); // Show a blank panel. … … 2913 3223 } 2914 3224 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 2915 3294 /** 2916 Class to hand renaming of an element.3295 Class to handle renaming of an element. 2917 3296 2918 3297 Author: Matthew Whyte … … 2921 3300 private class RenameElementActionListener extends ModalDialog implements ActionListener { 2922 3301 2923 pr ivateJButton cancel_button = null;2924 pr ivateJButton ok_button = null;3302 protected JButton cancel_button = null; 3303 protected JButton ok_button = null; 2925 3304 //private JLabel label = null; 2926 pr ivateNonWhitespaceField name_field = null;3305 protected NonWhitespaceField name_field = null; 2927 3306 2928 3307 … … 3056 3435 else 3057 3436 { 3058 name_field.setText(current_element.getName ()); //show old name3437 name_field.setText(current_element.getNameOnly()); //show old name (without namespace) 3059 3438 setVisible(true); //Show the dialog 3060 3439 } … … 3080 3459 /** 3081 3460 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. 3083 3462 Attributes in the table are handled directly by the RemoveAttributeActionListener 3084 3463 … … 3118 3497 GEMSNode t = (GEMSNode)selPath.getLastPathComponent(); 3119 3498 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 3121 3505 { 3122 3506 //System.err.println("element"); … … 3322 3706 public void valueChanged(TreeSelectionEvent event) { 3323 3707 if(!ignore) { 3708 GValueModel value_model = null; 3324 3709 // Clear all variables based on previous tree selection 3325 3710 current_collection_file = null; … … 3358 3743 // setControls(true, false, false, true, false, false, true, false, false, false, false, false); 3359 3744 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 3360 3763 case GEMSNode.ELEMENT: 3361 3764 current_element = current_node.getElement(); … … 3369 3772 atm.setTable(element_attributes); 3370 3773 3774 //System.err.println("atm is: " + atm); //debug 3775 3371 3776 // Be careful not to add the keep_root_expanded_listener over and over! 3372 GValueModelvalue_model = msm.getValueTree(current_element);3777 value_model = msm.getValueTree(current_element); 3373 3778 if(value_model != null) { 3374 3779 value_model.removeTreeModelListener(keep_root_expanded_listener); // Remove it if its already there … … 3380 3785 } 3381 3786 else { 3787 System.err.println("ELEMENT: value_model is null"); //debug 3382 3788 element_values_layout.show(element_values_pane, BLANK); 3383 3789 // Meanwhile disable/enable controls depending on this Element selection. … … 3442 3848 class PopupListener extends MouseAdapter implements ActionListener{ 3443 3849 JPopupMenu setPopup; 3444 JPopupMenu sub fieldPopup;3850 JPopupMenu subelementPopup; 3445 3851 JPopupMenu elementPopup; 3446 3852 JPopupMenu attributePopup; … … 3451 3857 JMenuItem menuAddAttributeSet; 3452 3858 3453 JMenuItem menuRenameSub field;3454 JMenuItem menuDeleteSub field;3455 JMenuItem menuAddAttributeSub field;3859 JMenuItem menuRenameSubelement; 3860 JMenuItem menuDeleteSubelement; 3861 JMenuItem menuAddAttributeSubelement; 3456 3862 JMenuItem menuRenameElement; 3457 3863 3458 3864 JMenuItem menuDeleteElement; 3459 3865 JMenuItem menuAddAttributeElement; 3460 JMenuItem menuAddSub field;3866 JMenuItem menuAddSubelement; 3461 3867 3462 3868 JMenuItem menuEditValue; … … 3469 3875 PopupListener(GEMS g) { 3470 3876 setPopup = new JPopupMenu(); 3471 sub fieldPopup = new JPopupMenu();3877 subelementPopup = new JPopupMenu(); 3472 3878 elementPopup = new JPopupMenu(); 3473 3879 attributePopup = new JPopupMenu(); … … 3501 3907 Dictionary.setText(menuRemoveSet,"GEMS.Remove_Set_Tooltip"); 3502 3908 3503 //sub fieldrelated GEMS.Popups3504 menuRenameSub field= new JMenuItem();3505 Dictionary.setText(menuRenameSub field,"GEMS.Popup.menuRenameSubfield");3506 3507 menuDeleteSub field=new JMenuItem();3508 Dictionary.setText(menuDeleteSub field,"GEMS.Popup.menuRemoveSubfield");3509 3510 menuAddAttributeSub field=new JMenuItem();3511 // Dictionary.setText(menuAddAttributeSub field,"GEMS.Popup.menuAddAttribute");3512 Dictionary.setText(menuAddAttributeSub field,"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"); 3513 3919 3514 3920 //element related GEMS.Popups … … 3525 3931 Dictionary.setText(menuAddAttributeElement,"GEMS.Add_Attribute_Tooltip"); 3526 3932 3527 menuAddSub field=new JMenuItem();3528 Dictionary.setText(menuAddSub field,"GEMS.Popup.menuAddSubfield");3529 //Dictionary.setText(menuAddSub field,"GEMS.Add_Subfield");3933 menuAddSubelement=new JMenuItem(); 3934 Dictionary.setText(menuAddSubelement,"GEMS.Popup.menuAddSubelement"); 3935 //Dictionary.setText(menuAddSubelement,"GEMS.Add_Subelement"); 3530 3936 3531 3937 //attribute related GEMS.Popups … … 3554 3960 setPopup.add(menuRemoveSet); 3555 3961 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); 3559 3966 3560 3967 elementPopup.add(menuRenameElement); 3561 3968 elementPopup.add(menuDeleteElement); 3562 3969 elementPopup.add(menuAddAttributeElement); 3563 //elementPopup.add(menuAddSubfield);3970 elementPopup.add(menuAddSubelement); 3564 3971 3565 3972 attributePopup.add(menuEditValue); … … 3573 3980 menuAddElement.addActionListener(new AddElementActionListener()); 3574 3981 menuAddAttributeSet.addActionListener(new AddOrEditAttributeActionListener()); 3575 menuRenameSub field.addActionListener(this);3576 menuDeleteSub field.addActionListener(this);3577 menuAddAttributeSub field.addActionListener(this);3982 menuRenameSubelement.addActionListener(new RenameSubelementActionListener()); 3983 menuDeleteSubelement.addActionListener(new RemoveSubelementActionListener()); 3984 menuAddAttributeSubelement.addActionListener(new AddOrEditAttributeActionListener()); 3578 3985 3579 3986 menuRenameSet.addActionListener(new RenameSetActionListener()); … … 3581 3988 menuDeleteElement.addActionListener(new RemoveElementActionListener()); 3582 3989 menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener()); 3583 menuAddSub field.addActionListener(this);3990 menuAddSubelement.addActionListener(new AddSubelementActionListener()); 3584 3991 3585 3992 // menuEditValue.addActionListener(new AddOrEditAttributeActionListener()); … … 3645 4052 /* else if(t.type == T_ELEMENT){ 3646 4053 3647 sub fieldPopup.show(e.getComponent(),4054 subelementPopup.show(e.getComponent(), 3648 4055 e.getX(), e.getY()); 3649 4056 } 3650 4057 */ 4058 else if(t.type == T_SUBELEMENT) 4059 { 4060 subelementPopup.show(e.getComponent(), e.getX(), e.getY()); 4061 } 4062 3651 4063 else if(t.type == T_ROOT){ 3652 4064 … … 3689 4101 e.getX(), e.getY()); 3690 4102 } 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 } 3692 4112 3693 4113 -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSModel.java
r8270 r8930 83 83 } 84 84 } 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) { 87 87 for(int j = 0; j < child.getChildCount(); j++) { 88 88 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 } 94 113 } 95 114 } 96 115 } 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; 97 130 } 98 131 } -
trunk/gli/src/org/greenstone/gatherer/gems/GEMSNode.java
r8375 r8930 62 62 static final public int ROOT = 3; 63 63 static final public int SET = 4; 64 static final public int SUBELEMENT = 5; 64 65 65 66 public GEMSNode() { … … 103 104 result = (ElementWrapper) userObject; 104 105 } 106 return result; 107 } 108 109 public ElementWrapper getSubelement() { 110 ElementWrapper result = null; 111 if(type == SUBELEMENT) { 112 result = (ElementWrapper) userObject; 113 } 105 114 return result; 106 115 } 116 107 117 public int getIndex(TreeNode node) { 108 118 if(children == null) { … … 201 211 202 212 // 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 212 232 } 213 233 -
trunk/gli/src/org/greenstone/gatherer/gems/MSMUtils.java
r8809 r8930 128 128 } 129 129 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 130 152 /** A method for comparing two AssignedValues trees. This compares not only the Subject hierarchies but also the values themselves. 131 153 * @param avt A <strong>Node</strong> which is the root of an AssignedValues tree. … … 298 320 TreeSet attribute_tree = new TreeSet(); 299 321 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"); 302 323 GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml"); 303 324 … … 311 332 attribute_tree.add(new Attribute(some_element.getAttribute(StaticStrings.NAME_ATTRIBUTE), some_element.getAttribute(StaticStrings.LANGUAGE_ATTRIBUTE), MSMUtils.getValue(some_element))); 312 333 // System.out.println(some_element_name + "<- some_element nodes' value"); 313 314 315 334 } 316 335 else if(some_element_name.equals(StaticStrings.LANGUAGE_ELEMENT)) { 317 336 ///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 322 338 323 339 String language_code = some_element.getAttribute(StaticStrings.CODE_ATTRIBUTE); … … 326 342 for(int i = 0; i < attribute_elements.getLength(); i++) { 327 343 Element attribute_element = (Element) attribute_elements.item(i); 328 329 344 330 //System.out.println("code is:" + language_code);331 332 333 345 for(int k = 0; k < enabled_langs.length; k++){ 334 346 335 347 if(enabled_langs[k].trim().compareTo(some_element.getAttributes().item(0).getNodeValue().toString()) == 0){ 336 337 338 348 339 349 attribute_tree.add(new Attribute(attribute_element.getAttribute(StaticStrings.NAME_ATTRIBUTE), language_code, MSMUtils.getValue(attribute_element))); 340 350 attribute_element = null; … … 363 373 } 364 374 } 365 // attribute_tree.366 375 return attribute_tree; 367 376 } … … 543 552 // Retrieve this elements name 544 553 name_buffer.append(element.getAttribute("name")); 554 545 555 // 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. 546 557 Element parent_element = (Element) element.getParentNode(); 547 while(parent_element != null && parent_element != root) { 558 while(parent_element != null && parent_element != root) { 548 559 name_buffer.insert(0, SF_SEP); 549 560 name_buffer.insert(0, parent_element.getAttribute("name")); … … 566 577 } // static public String getFullName(Element element) 567 578 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 568 599 /** Method to construct an elements name (sic identifier) by retrieving the correct attribute, language specific. 569 600 * @param element the Element whose name we wish to retrieve … … 579 610 identifier = element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 580 611 } 612 581 613 return identifier; 582 614 } 615 616 583 617 584 618 /** 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 177 177 } 178 178 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 179 208 /** Add a new default metadata element with the given name to this metadata set. 180 209 * @param name The name of this element as a <strong>String</strong>. … … 478 507 * @param element The <strong>Element</strong> to be removed. 479 508 */ 480 public void removeElement(Element element ) {509 public void removeElement(Element element, ElementWrapper parent_wrapped) { 481 510 // we need to remove the value tree too!! 482 511 //System.err.println("removeElement in MetadataSet: element is: " + element); //Debug 483 512 484 513 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 } 487 527 488 528 } catch(Exception DOMException) { //The element does not exist!! … … 508 548 */ 509 549 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 } 518 560 return null; 519 561 } -
trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java
r8896 r8930 110 110 @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. 111 111 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. 114 114 115 115 @author Matthew Whyte … … 376 376 //already loaded-Attila 377 377 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()); 380 380 all_sets[i] = tempSet.getFile(); 381 381 i++; … … 426 426 } 427 427 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) { 430 436 // Retrieve the metadata set this element belongs to. 431 437 String namespace = element.getNamespace(); 438 //System.err.println("namespace is: " + namespace); //debug 432 439 MetadataSet set = (MetadataSet) mds_hashtable.get(namespace); 433 440 if(set != null) { 434 441 // 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 439 444 } 440 445 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 445 451 446 452 /** … … 457 463 if(set != null) 458 464 { 465 //System.err.println("newName is: " + newName); //debug 459 466 set.renameElement(oldElement.getElement(), newName); //Rename the element 460 467 }
Note:
See TracChangeset
for help on using the changeset viewer.