- Timestamp:
- 2005-01-10T14:38:23+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/gems
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/ElementWrapper.java
r8270 r8881 67 67 public ElementWrapper(Element element) { 68 68 this.element = element; 69 //System.err.println("ElementWrapper: element is: " + element); //debug 69 70 Element parent = (Element)element.getParentNode(); 70 71 if (parent != null) { … … 211 212 return getNamespace() + MSMUtils.NS_SEP + getIdentity(); 212 213 } 214 213 215 } -
trunk/gli/src/org/greenstone/gatherer/gems/GEMS.java
r8873 r8881 117 117 private AddFileActionListener add_file_action_listener = null; 118 118 public AddSetActionListener add_set_action_listener = null; 119 // private RenameElementActionListener rename_element_action_listener = null; 119 120 /** The class used to handle add or edit attribute actions has to be globally available so that we can dispose of its dialog properly. */ 120 121 public AddOrEditAttributeActionListener add_or_edit_attribute_action_listener = null; … … 463 464 add_file_action_listener = new AddFileActionListener(); 464 465 add_set_action_listener = new AddSetActionListener(); 465 466 // rename_element_action_listener = new RenameElementActionListener(); 466 467 467 468 … … 1651 1652 // Then update the tree 1652 1653 model.add(current_node, element, GEMSNode.ELEMENT); 1654 //System.out.println("current_node is: " + current_node); //debug 1653 1655 // Signal that the metadata set has changed 1654 1656 // msm.fireSetChanged(current_set); … … 1936 1938 setLocation((config.screen_size.width - ADD_SET_SIZE.width) / 2, (config.screen_size.height - ADD_SET_SIZE.height) / 2); 1937 1939 } 1938 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to 1939 * @param event An <strong>ActionEvent</strong> containing information about the event. 1940 */ 1940 1941 1941 private boolean a_set_exists_with_this_namespace(String namespace){ 1942 1942 Vector p = msm.getSets(); … … 1948 1948 flag = true; 1949 1949 } 1950 1950 1951 1951 1952 } … … 1953 1954 return flag; 1954 1955 } 1956 1957 1958 /** Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component, allowing us to 1959 * @param event An <strong>ActionEvent</strong> containing information about the event. 1960 */ 1955 1961 public void actionPerformed(ActionEvent event) { 1956 1962 Object source = event.getSource(); … … 2003 2009 }//end do not inherit 2004 2010 else { 2011 //Should change this to use XML parsing utilites --Matthew 2005 2012 //lets grab the metadata we want to inherit from... 2006 2013 String anitem = existingSetJComboBox.getSelectedItem().toString(); … … 2014 2021 2015 2022 FileInputStream fstream = new FileInputStream(items[1].trim()); 2016 BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF -8"));2023 BufferedReader in = new BufferedReader(new InputStreamReader(fstream, "UTF8")); 2017 2024 //DataInputStream in = new DataInputStream(fstream); 2018 2025 /////////////// … … 2403 2410 } 2404 2411 } 2405 // If we haven't done so yet, insert the current node .This will coincidently remove from original parent.2412 // If we haven't done so yet, insert the current node This will coincidently remove from original parent. 2406 2413 if(!found) { 2407 2414 Node parent_node = subject_node.getElement(); … … 2656 2663 } 2657 2664 2665 2666 /** 2667 Class to hand renaming of a set. 2668 2669 Author: Matthew Whyte 2670 Date last modified: 22/12/04 2671 */ 2672 private class RenameSetActionListener extends AddSetActionListener implements ActionListener { 2673 /** 2674 To do: everything!!!!! --Matthew 2675 */ 2676 2677 2678 //Constructor 2679 public RenameSetActionListener() 2680 { 2681 } 2682 2683 /** 2684 Any implementation of ActionListener must include this method so that we can be informed when an action has occured. 2685 @param event An <string>ActionEvent</strong> containing information about the event. 2686 */ 2687 public void actionPerformed(ActionEvent event) 2688 { 2689 System.err.println("You chose to rename a set!!"); //debug 2690 } 2691 } 2692 2693 2694 /** 2695 Class to hand renaming of an element. 2696 2697 Author: Matthew Whyte 2698 Date last modified: 10/01/05 2699 */ 2700 private class RenameElementActionListener extends ModalDialog implements ActionListener { 2701 2702 private JButton cancel_button = null; 2703 private JButton ok_button = null; 2704 private JLabel label = null; 2705 private NonWhitespaceField name_field = null; 2706 2707 2708 public RenameElementActionListener() { 2709 super(self); 2710 setModal(true); 2711 setSize(ADD_ELEMENT_SIZE); 2712 // Creation 2713 JPanel content_pane = (JPanel) getContentPane(); 2714 content_pane.setBackground(config.getColor("coloring.collection_heading_background", false)); 2715 JPanel center_pane = new JPanel(); 2716 center_pane.setOpaque(false); 2717 2718 JPanel labels_pane = new JPanel(); 2719 labels_pane.setOpaque(false); 2720 JLabel set_label = new JLabel(); 2721 set_label.setOpaque(false); 2722 Dictionary.setText(set_label, "GEMS.Rename_Element"); 2723 label = new JLabel(); 2724 label.setOpaque(false); 2725 2726 JPanel values_pane = new JPanel(); 2727 values_pane.setOpaque(false); 2728 JLabel name_label = new JLabel(); 2729 name_label.setOpaque(false); 2730 Dictionary.setText(name_label, "GEMS.New_Name"); 2731 name_field = new NonWhitespaceField(); 2732 name_field.setBackground(config.getColor("coloring.collection_tree_background", false)); 2733 name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false)); 2734 name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false)); 2735 name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false)); 2736 Dictionary.setTooltip(name_field, "GEMS.Rename_Element_Tooltip"); 2737 2738 JPanel button_pane = new JPanel(); 2739 button_pane.setOpaque(false); 2740 2741 ok_button = new GLIButton(); 2742 ok_button.setMnemonic(KeyEvent.VK_O); 2743 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip"); 2744 cancel_button = new GLIButton(); 2745 cancel_button.setMnemonic(KeyEvent.VK_C); 2746 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip"); 2747 2748 TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button); 2749 2750 // Connection 2751 cancel_button.addActionListener(this); 2752 ok_button.addActionListener(this); 2753 ok_button_enabler.add(name_field); 2754 2755 // Layout 2756 labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); 2757 labels_pane.setLayout(new GridLayout(2,1)); 2758 labels_pane.add(set_label); 2759 labels_pane.add(name_label); 2760 2761 values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); 2762 values_pane.setLayout(new GridLayout(2,1)); 2763 values_pane.add(label); 2764 values_pane.add(name_field); 2765 2766 center_pane.setLayout(new BorderLayout(5,5)); 2767 center_pane.add(labels_pane, BorderLayout.WEST); 2768 center_pane.add(values_pane, BorderLayout.CENTER); 2769 2770 button_pane.setLayout(new GridLayout(1,2,0,5)); 2771 button_pane.add(ok_button); 2772 button_pane.add(cancel_button); 2773 2774 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 2775 content_pane.setLayout(new BorderLayout()); 2776 content_pane.add(center_pane, BorderLayout.CENTER); 2777 content_pane.add(button_pane, BorderLayout.SOUTH); 2778 2779 setLocation((config.screen_size.width - ADD_ELEMENT_SIZE.width) / 2, (config.screen_size.height - ADD_ELEMENT_SIZE.height) / 2); 2780 } 2781 2782 2783 /** 2784 Any implementation of ActionListener must include this method so that we can be informed when an action has occured. 2785 @param event An <string>ActionEvent</strong> containing information about the event. 2786 */ 2787 public void actionPerformed(ActionEvent event) 2788 { 2789 Object source = event.getSource(); 2790 2791 if(source == ok_button) 2792 { 2793 TreeNode selPath = current_node.getParent(); 2794 GEMSNode parent = (GEMSNode)selPath; 2795 MetadataSet currentSet = msm.getSet(current_element.getNamespace()); 2796 2797 String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM); 2798 2799 // If this element doesn't already exist. 2800 if(!currentSet.containsElement(name_str)) //Do the renaming! 2801 { 2802 //Hide the element that are about to rename 2803 mds_tree.clearSelection(); 2804 model.remove(current_element.getName(), GEMSNode.ELEMENT); 2805 2806 msm.renameElement(current_element, name_str); //rename the element 2807 2808 model.add(parent, current_element, GEMSNode.ELEMENT); 2809 2810 //Could now select the new element, but for now will just clean up ;-) 2811 // Disable/enable controls given we had an element selected, but no longer do. 2812 remove_element.setEnabled(false); 2813 card_layout.show(details_pane, BLANK); // Show a blank panel. 2814 ignore = false; 2815 2816 atLeastOneSetChanged = true; 2817 setVisible(false); 2818 } 2819 2820 // Otherwise show an error message and do not proceed. 2821 else 2822 { 2823 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Element_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 2824 } 2825 name_str = null; 2826 2827 } 2828 2829 else if(source == cancel_button) 2830 { 2831 setVisible(false); //hide dialog 2832 } 2833 else 2834 { 2835 name_field.setText(""); //remove old text 2836 setVisible(true); //Show the dialog 2837 } 2838 2839 source = null; 2840 } 2841 2842 2843 public void dispose() { 2844 cancel_button = null; 2845 ok_button = null; 2846 name_field = null; 2847 label = null; 2848 //System.err.println("Dispose AddElementActionListener"); 2849 super.dispose(); 2850 } 2851 2852 } 2853 2854 2658 2855 /** 2659 2856 Class to handle DELETE key presses on the tree. … … 2721 2918 } 2722 2919 } 2920 2921 2922 2723 2923 2724 2924 … … 3088 3288 //element related GEMS.Popups 3089 3289 menuRenameElement=new JMenuItem(); 3090 //Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement");3091 //Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip");3290 Dictionary.setText(menuRenameElement,"GEMS.Popup.menuRenameElement"); 3291 // Dictionary.setText(menuRenameElement,"GEMS.Rename_Element_Tooltip"); 3092 3292 3093 3293 menuDeleteElement=new JMenuItem(); … … 3117 3317 3118 3318 //start Associate the menu items with the appropriate popups: 3319 setPopup.add(menuRenameSet); 3320 //setPopup.add(menuAddSet); 3321 setPopup.add(menuAddAttributeSet); 3322 setPopup.add(menuAddElement); 3323 setPopup.add(menuRemoveSet); 3119 3324 //setPopup.add(menuRenameSet); 3120 3325 //setPopup.add(menuAddSet); … … 3127 3332 subfieldPopup.add(menuAddAttributeSubfield); 3128 3333 3129 //elementPopup.add(menuRenameElement);3334 elementPopup.add(menuRenameElement); 3130 3335 elementPopup.add(menuDeleteElement); 3131 3336 elementPopup.add(menuAddAttributeElement); … … 3146 3351 menuAddAttributeSubfield.addActionListener(this); 3147 3352 3148 menuRenameElement.addActionListener(this); 3353 menuRenameSet.addActionListener(new RenameSetActionListener()); 3354 menuRenameElement.addActionListener(new RenameElementActionListener()); 3149 3355 menuDeleteElement.addActionListener(new RemoveElementActionListener()); 3150 3356 menuAddAttributeElement.addActionListener(new AddOrEditAttributeActionListener()); -
trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java
r8863 r8881 194 194 return new ElementWrapper(element); 195 195 } 196 196 197 197 198 /** Method to add a new metadata element to this metadata set, if and only if the element is not already present. 198 199 * @param others_element An <strong>Element</strong> we wish to add to this metadata set, that currently belongs to some other set. … … 477 478 } 478 479 } 480 481 /** 482 Rename the metadata element. 483 @param oldElement An <strong>Element</strong> we wish to rename 484 @param newName A <strong>String</strong> which contains the new name of the element. 485 @return An <strong>ElementWrapper</strong> around the newly named element 486 */ 487 public void renameElement(Element oldElement, String newName) 488 { 489 oldElement.setAttribute("name", newName); //Rename the element 490 } 491 492 479 493 /** Used to remove the value tree for a specific element. 480 494 * @param element The <strong>ElementWrapper</strong> whose tree you wish to remove. -
trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java
r8863 r8881 411 411 // No such set. No such element. 412 412 } 413 414 /** 415 Rename the metadata element. 416 @param oldElement An <strong>ElementWrapper</strong> we wish to rename 417 @param newName A <strong>String</strong> which contains the new name of the element. 418 @return An <strong>ElementWrapper</strong> around the newly named element 419 */ 420 public void renameElement(ElementWrapper oldElement, String newName) 421 { 422 //Retrive the metadata set this element belongs to. 423 String namespace = oldElement.getNamespace(); 424 MetadataSet set = (MetadataSet)mds_hashtable.get(namespace); 425 if(set != null) 426 { 427 set.renameElement(oldElement.getElement(), newName); //Rename the element 428 } 429 else 430 { 431 System.err.println("No such set " + namespace); 432 } 433 } 434 413 435 /*Following write() and write() and save() were taken from msm/metadatasetmanager.java and converted to 414 436 *the gems standard
Note:
See TracChangeset
for help on using the changeset viewer.