Changeset 8896 for trunk/gli


Ignore:
Timestamp:
2005-01-13T11:52:44+13:00 (19 years ago)
Author:
mdewsnip
Message:

More GEMS improvements, by Matthew Whyte.

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

Legend:

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

    r8881 r8896  
    1 /**
     1 /**
    22 *#########################################################################
    33 *
     
    8686    /** The default size of the editor dialog. */
    8787    static final private Dimension ADD_ELEMENT_SIZE = new Dimension(400,125);
     88    static final private Dimension RENAME_ELEMENT_SIZE = new Dimension(400, 95);
    8889    static final private Dimension ADD_FILE_SIZE = new Dimension(400,125);
    8990    static final private Dimension ADD_SET_SIZE = new Dimension(400,150);
     91    static final private Dimension RENAME_SET_SIZE = new Dimension(400,120);
    9092    static final private Dimension OPEN_SETS_SIZE = new Dimension(400,135);
    9193    static final private Dimension ADD_OR_EDIT_ATTRIBUTE_SIZE = new Dimension(600,325);
     
    319321    set_attributes.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
    320322    set_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    321     set_attributes.addMouseListener(popupListener);   
     323    set_attributes.addMouseListener(popupListener);
     324    set_attributes.addMouseListener(new AddOrEditAttributeActionListener());
    322325    set_attributes.addKeyListener(new RemoveAttributeActionListener()); //Listen for DELETE key
    323326    JPanel element_details_pane = new JPanel();
     
    351354    element_attributes.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    352355        element_attributes.addMouseListener(popupListener);
     356    element_attributes.addMouseListener(new AddOrEditAttributeActionListener());
    353357    element_attributes.addKeyListener(new RemoveAttributeActionListener()); //For the DELETE key
    354358       
     
    976980   private class AddOrEditAttributeActionListener
    977981    extends ModalDialog
    978     implements ActionListener {
    979     private boolean add_type = true;
    980     private ComboArea value = null;
    981     private JButton cancel_button = null;
    982     private JButton ok_button = null;
    983     private JComboBox language_box = null;
    984     private GComboBox name = null;
    985     private HashMap name_to_values = null;
    986     private JLabel target = null;
    987         private Vector attributeLists = null;
    988        
     982    implements ActionListener, MouseListener {
     983       private boolean add_type = true;
     984       private ComboArea value = null;
     985       private JButton cancel_button = null;
     986       private JButton ok_button = null;
     987       private JComboBox language_box = null;
     988       private GComboBox name = null;
     989       private HashMap name_to_values = null;
     990       private JLabel target = null;
     991       private JLabel target_label = null;
     992       private Vector attributeLists = null;     
    989993       
    990994        //org.w3c.dom.Document lang = Utility.parse("/home/arosmain/gsdl/gli/classes/xml/languages.xml", false);
     
    10301034        JPanel boxes_pane = new JPanel();
    10311035
    1032         JLabel target_label = new JLabel();
     1036        target_label = new JLabel();
    10331037        target_label.setOpaque(false);
    10341038        Dictionary.setText(target_label, "GEMS.Target");
    10351039        target = new JLabel();
    10361040        target.setOpaque(false);
     1041        //Dictionary.setText(target, "this is the target"); //debug
    10371042
    10381043        JLabel name_label = new JLabel();
     
    11251130           // create dom object for language_Box
    11261131            //GEMSLanguageManager GemsLangManager = new GEMSLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml");
    1127         GEMSLanguageManager GemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
     1132        GEMSLanguageManager GemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml");
    11281133       
    11291134            Vector languagecodes = GemsLangManager.getLanguageCodes();
     
    11381143           //System.out.println(code);
    11391144        }
     1145
     1146       //Handle double clicks in the table.
     1147       public void mouseClicked(MouseEvent e)
     1148    {
     1149        if(e.getSource() == element_attributes || e.getSource() == set_attributes)
     1150        {
     1151            if(e.getClickCount() == 2) //Double click
     1152            {
     1153                //Show the Edit Attribute dialog
     1154                this.menuEditValue();
     1155                this.editAttribute();
     1156            }
     1157        }
     1158    }
     1159    //required by MouseListener
     1160    public void mouseEntered(MouseEvent e)
     1161    {
     1162    }
     1163    //required by MouseListener
     1164    public void mouseExited(MouseEvent e)
     1165    {
     1166    }
     1167    //required by MouseListener
     1168    public void mousePressed(MouseEvent e)
     1169    {
     1170    }
     1171    //required by MouseListener
     1172    public void mouseReleased(MouseEvent e)
     1173    {
     1174    }
     1175
    11401176    /** 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 add a new attribute to the selected set or element.
    11411177     * @param event An <strong>ActionEvent</strong> containing information about the event.
    11421178     */
    1143        
    1144        
    11451179    public void actionPerformed(ActionEvent event) {
    11461180        Object source = event.getSource();
    1147             AttributeTableModel tablemodel;
     1181            AttributeTableModel tablemodel = null;
     1182        AttributeTableModel model = null;
    11481183            String prevLang = new String("");
    11491184            String prevValue = new String("");
    11501185           
     1186        if(current_element != null)
     1187        {
     1188            target.setText(current_element.getName());
     1189        }
     1190        else if(current_set != null)
     1191        {
     1192            Dictionary.setText(target_label, "GEMS.Set");
     1193            target.setText(current_set.toString());
     1194        }
     1195       
    11511196          //allow user to choose language when they create attr
    1152          
    1153      
    1154            
    1155            
     1197          /*         
    11561198          if(source == popupListener.menuAddAttributeAttribute) { 
    11571199            add_type =  true;
    1158            language_box.setEnabled(true);
     1200        language_box.setEnabled(true);
     1201        System.err.println("source is menuAddAttributeAttribute"); //Debug
    11591202          }//end if source== menuaddattributeattribute
    1160           else if (source == popupListener.menuEditValue){
    1161               add_type = false;
    1162               //grab the table model based on what is currently selected
    1163                 switch(current_attribute_type) {
    1164         case GEMSNode.COLLECTION:
    1165             tablemodel = (AttributeTableModel) profile_attributes.getModel();
    1166                     //String prevLang =  tablemodel.getValueAt(current_attribute,0).toString();
    1167                     //String prevValue = tablemodel.getValueAt(current_attribute,1).toString();
    1168            
    1169             break;
    1170         case GEMSNode.SET:
    1171             tablemodel = (AttributeTableModel) set_attributes.getModel();
    1172                     //grab value in table(
    1173             prevLang =  tablemodel.getValueAt(current_attribute,0).toString();
    1174                     prevValue = tablemodel.getValueAt(current_attribute,1).toString();
    1175                
    1176             break;
    1177         case GEMSNode.ELEMENT:
    1178             tablemodel = (AttributeTableModel) element_attributes.getModel();
    1179                     //grab values in table( lang and value)
    1180                     prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
    1181                     prevValue = tablemodel.getValueAt(current_attribute,2).toString();
    1182            
    1183             break;
    1184                     default:
    1185                         //by default grab element_attr's
    1186                     tablemodel = (AttributeTableModel) element_attributes.getModel();
    1187                     prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
    1188                     prevValue = tablemodel.getValueAt(current_attribute,2).toString();
    1189            
    1190                     break;
    1191         }         
    1192               language_box.setEnabled(false);
    1193              
    1194            //if a set attr is selected, then do not do any lang operations, other than setting index to -1
    1195               if(current_attribute_type != GEMSNode.SET) {
    1196 
    1197                 //set the current language to show up in language_box(no lang if no lang specified)
    1198                 if(prevLang == null || prevLang.compareTo(" ")==0 || prevLang.compareTo("") == 0 || prevLang.compareTo("  ")==0) {
    1199                     language_box.setSelectedIndex(-1);
    1200              
    1201                 }
    1202                 else {
    1203                     language_box.setSelectedItem(prevLang.toLowerCase());
    1204                 }
    1205               }// end currattr != GEMSnode.set
    1206               else {
    1207                  
    1208                  language_box.setSelectedIndex(-1);
    1209                  
    1210               }// end currattr == GEMSnode.set
    1211              
    1212               value.setText(prevValue);
     1203          else*/ if (source == popupListener.menuEditValue){
     1204          this.menuEditValue();
    12131205             
    12141206          }//end if source == popupListener.menuEditValue)
     
    12161208            if(source == ok_button) {
    12171209        boolean success = true;
    1218         AttributeTableModel model;
    12191210
    12201211        // Add or edit a collect/set/element attribute
     
    12381229            // Hide dialog
    12391230               
     1231            atLeastOneSetChanged = true;
    12401232            setVisible(false);
    12411233                    return;
    12421234        }
     1235        else //debug
     1236            {
     1237            System.err.println("No success by OK button."); //debug
     1238            }
    12431239        }
    12441240        else if(source == cancel_button) {
     
    12481244        }
    12491245        else if(source == name) {
     1246        //System.err.println("source is name");
    12501247                Object object = name.getSelectedItem();
    12511248        if(object != null) {
     
    12621259                    }
    12631260        }
    1264         }
    1265         else if (source == popupListener.menuAddAttributeAttribute){
    1266                  
    1267                    for(int i = 0; i < attributeLists.size(); i++) {
    1268                         name.add(attributeLists.get(i).toString());   
     1261        //setVisible(true);
     1262        }
     1263        else if (source == popupListener.menuAddAttributeAttribute || source == popupListener.menuAddAttributeSet || source == popupListener.menuAddAttributeElement){
     1264
     1265        Dictionary.setText(this, "GEMS.AddAttribute");
     1266        for(int i = 0; i < attributeLists.size(); i++) {
     1267            name.add(attributeLists.get(i).toString());   
    12691268                   
    1270                         }
    1271                  name.setEnabled(true);
     1269        }
     1270
     1271       
     1272        name.setEnabled(true);
     1273        setVisible(true);
    12721274            }
    12731275           /* else if (source == popupListener.menuAddAttributeAttribute){
     
    13931395               // }*/
    13941396        else if(current_attribute != -1) {
    1395                    
    1396                     //System.out.println(source.toString()+"\n");
    1397             AttributeTableModel model = null;
    1398             switch(current_attribute_type) {
    1399             case GEMSNode.COLLECTION:
    1400             model = (AttributeTableModel) profile_attributes.getModel();
    1401             break;
    1402             case GEMSNode.ELEMENT:
    1403             model = (AttributeTableModel) element_attributes.getModel();
    1404             break;
    1405             case GEMSNode.SET:
    1406             model = (AttributeTableModel) set_attributes.getModel();
    1407             break;
    1408             }
    1409             add_type = false;
    1410             Dictionary.setText(this, "GEMS.EditAttribute");
    1411             String name_str = (String) model.getValueAt(current_attribute, 0);
    1412             String value_str = (String) model.getValueAt(current_attribute, model.getColumnCount() - 1);
    1413             model = null;
    1414             // Retrieve the appropriate value model
    1415             java.util.List values = (java.util.List) name_to_values.get(name_str);
    1416             // Only possible for collection file selections.
    1417             if(values == null) {
    1418             values = msm.getElements();
    1419             }
    1420             name.setSelectedItem(name_str);
    1421             name_str = null;
    1422             for(int i = 0; i < values.size(); i++) {
    1423             Object temp_value = values.get(i);
    1424             if(temp_value instanceof ElementWrapper) {
    1425                 value.add(new NameElementWrapperEntry(temp_value));
    1426             }
    1427             else {
    1428                 value.add(temp_value);
    1429             }
    1430             }
    1431             values = null;
    1432             value.setSelectedItem(value_str);
    1433             value_str = null;
    1434            
    1435         }
    1436        // }
    1437             setVisible(true);
     1397            this.editAttribute();
     1398        }
     1399
    14381400        source = null;
    14391401    }
     1402
     1403       private void menuEditValue()
     1404       {
     1405       AttributeTableModel tablemodel = null;
     1406     
     1407       String prevLang = new String("");
     1408       String prevValue = new String("");
     1409
     1410       add_type = false;
     1411       //grab the table model based on what is currently selected
     1412       switch(current_attribute_type) {
     1413       case GEMSNode.COLLECTION:
     1414           tablemodel = (AttributeTableModel) profile_attributes.getModel();
     1415           //String prevLang =  tablemodel.getValueAt(current_attribute,0).toString();
     1416           //String prevValue = tablemodel.getValueAt(current_attribute,1).toString();
     1417           
     1418           break;
     1419       case GEMSNode.SET:
     1420           tablemodel = (AttributeTableModel) set_attributes.getModel();
     1421           //grab value in table(
     1422           prevLang =  tablemodel.getValueAt(current_attribute,0).toString();
     1423           prevValue = tablemodel.getValueAt(current_attribute,1).toString();
     1424           
     1425           break;
     1426       case GEMSNode.ELEMENT:
     1427           tablemodel = (AttributeTableModel) element_attributes.getModel();
     1428           //grab values in table( lang and value)
     1429           prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
     1430           prevValue = tablemodel.getValueAt(current_attribute,2).toString();
     1431           
     1432           break;
     1433       default:
     1434           //by default grab element_attr's
     1435           tablemodel = (AttributeTableModel) element_attributes.getModel();
     1436           prevLang =  tablemodel.getValueAt(current_attribute,1).toString();
     1437           prevValue = tablemodel.getValueAt(current_attribute,2).toString();
     1438           
     1439           break;
     1440       }         
     1441       language_box.setEnabled(false);
     1442       
     1443           //if a set attr is selected, then do not do any lang operations, other than setting index to -1
     1444       if(current_attribute_type != GEMSNode.SET) {
     1445           
     1446           //set the current language to show up in language_box(no lang if no lang specified)
     1447           if(prevLang == null || prevLang.compareTo(" ")==0 || prevLang.compareTo("") == 0 || prevLang.compareTo("  ")==0) {
     1448           language_box.setSelectedIndex(-1);
     1449           
     1450           }
     1451           else {
     1452           language_box.setSelectedItem(prevLang.toLowerCase());
     1453           }
     1454       }// end currattr != GEMSnode.set
     1455       else {
     1456           
     1457           language_box.setSelectedIndex(-1);
     1458           
     1459       }// end currattr == GEMSnode.set
     1460       
     1461       value.setText(prevValue);
     1462       
     1463       }
     1464
     1465       private void editAttribute()
     1466       {
     1467       AttributeTableModel model = null;
     1468       Dictionary.setText(this, "GEMS.EditAttribute");
     1469       //System.out.println(source.toString()+"\n");
     1470       
     1471       switch(current_attribute_type) {
     1472       case GEMSNode.COLLECTION:
     1473           model = (AttributeTableModel) profile_attributes.getModel();
     1474           break;
     1475       case GEMSNode.ELEMENT:
     1476           model = (AttributeTableModel) element_attributes.getModel();
     1477           break;
     1478       case GEMSNode.SET:
     1479           model = (AttributeTableModel) set_attributes.getModel();
     1480           break;
     1481       }
     1482       add_type = false;
     1483       String name_str = (String) model.getValueAt(current_attribute, 0);
     1484       String value_str = (String) model.getValueAt(current_attribute, model.getColumnCount() - 1);
     1485       model = null;
     1486       // Retrieve the appropriate value model
     1487       java.util.List values = (java.util.List) name_to_values.get(name_str);
     1488       // Only possible for collection file selections.
     1489       if(values == null) {
     1490           values = msm.getElements();
     1491       }
     1492       name.setSelectedItem(name_str);
     1493       name_str = null;
     1494       for(int i = 0; i < values.size(); i++) {
     1495           Object temp_value = values.get(i);
     1496           if(temp_value instanceof ElementWrapper) {
     1497           value.add(new NameElementWrapperEntry(temp_value));
     1498           }
     1499           else {
     1500           value.add(temp_value);
     1501           }
     1502       }
     1503       values = null;
     1504       value.setSelectedItem(value_str);
     1505       value_str = null;
     1506       setVisible(true);   
     1507       }
    14401508
    14411509    private boolean addOrEditCollectionAttribute(AttributeTableModel model)
     
    26642732
    26652733
     2734
    26662735    /**
    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.
     2736       Class to handle renaming of a set and/or it's namespace.
    26962737
    26972738       Author: Matthew Whyte
    26982739       Date last modified: 10/01/05
    26992740    */
    2700     private class RenameElementActionListener extends ModalDialog implements ActionListener {
     2741    private class RenameSetActionListener extends ModalDialog implements ActionListener {
    27012742
    27022743    private JButton cancel_button = null;
    27032744    private JButton ok_button = null;
    2704     private JLabel label = null;
    2705     private NonWhitespaceField name_field = null;
    2706 
    2707        
    2708     public RenameElementActionListener() {
     2745    private JTextField name_field = null;
     2746    private JTextField namespace_field = null;
     2747           
     2748    public RenameSetActionListener() {
    27092749        super(self);
    27102750        setModal(true);
    2711         setSize(ADD_ELEMENT_SIZE);
     2751        setSize(RENAME_SET_SIZE);
     2752        Dictionary.setText(this, "GEMS.Rename_Set");
     2753
    27122754        // Creation
    27132755        JPanel content_pane = (JPanel) getContentPane();
     
    27162758        center_pane.setOpaque(false);
    27172759
     2760        JPanel label_pane = new JPanel();
     2761        JPanel boxes_pane = new JPanel();
     2762
     2763        JLabel namespace_label = new JLabel();
     2764        namespace_label.setOpaque(false);
     2765        Dictionary.setText(namespace_label, "GEMS.Namespace");
     2766        namespace_field = TransformCharacterTextField.createNamespaceTextField();
     2767        namespace_field.setBackground(config.getColor("coloring.collection_tree_background", false));
     2768        namespace_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
     2769        namespace_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
     2770        namespace_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
     2771        Dictionary.setTooltip(namespace_field, "GEMS.Rename_Namespace_Tooltip");
     2772
     2773        JLabel name_label = new JLabel();
     2774        name_label.setOpaque(false);
     2775        Dictionary.setText(name_label, "GEMS.Name");
     2776        name_field = new JTextField();
     2777        name_field.setBackground(config.getColor("coloring.collection_tree_background", false));
     2778        name_field.setForeground(config.getColor("coloring.collection_tree_foreground", false));
     2779        name_field.setSelectionColor(config.getColor("coloring.collection_selection_background", false));
     2780        name_field.setSelectedTextColor(config.getColor("coloring.collection_selection_foreground", false));
     2781        Dictionary.setTooltip(name_field, "GEMS.Rename_Name_Tooltip");
     2782
     2783        JPanel button_pane = new JPanel();
     2784        button_pane.setOpaque(false);
     2785
     2786        ok_button = new GLIButton();
     2787        ok_button.setMnemonic(KeyEvent.VK_O);
     2788        Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
     2789        cancel_button = new GLIButton();
     2790        cancel_button.setMnemonic(KeyEvent.VK_C);
     2791        Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip");
     2792        TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
     2793
     2794        // Connection
     2795        cancel_button.addActionListener(this);
     2796        ok_button.addActionListener(this);
     2797        ok_button_enabler.add(name_field);
     2798        ok_button_enabler.add(namespace_field);
     2799
     2800        // Layout
     2801        label_pane.setLayout(new GridLayout(2,1));
     2802        label_pane.add(name_label);
     2803        label_pane.add(namespace_label);
     2804            boxes_pane.setLayout(new GridLayout(2,1));
     2805        boxes_pane.add(name_field);
     2806        boxes_pane.add(namespace_field);
     2807           
     2808        center_pane.setLayout(new BorderLayout(5,0));
     2809        center_pane.add(label_pane, BorderLayout.WEST);
     2810        center_pane.add(boxes_pane, BorderLayout.CENTER);
     2811
     2812        button_pane.setLayout(new GridLayout(1,2,0,5));
     2813        button_pane.add(ok_button);
     2814        button_pane.add(cancel_button);
     2815
     2816        content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     2817        content_pane.setLayout(new BorderLayout());
     2818        content_pane.add(center_pane, BorderLayout.CENTER);
     2819        content_pane.add(button_pane, BorderLayout.SOUTH);
     2820         
     2821        setLocation((config.screen_size.width - RENAME_SET_SIZE.width) / 2, (config.screen_size.height - RENAME_SET_SIZE.height) / 2);
     2822    }
     2823
     2824        private boolean a_set_exists_with_this_namespace(String namespace){
     2825            Vector p = msm.getSets();
     2826            boolean flag = false;
     2827            for(int k = 0; k < p.size(); k++){
     2828                MetadataSet s = (MetadataSet)p.get(k);
     2829               
     2830                if(s.getNamespace().compareTo(namespace) == 0){
     2831                    flag = true;     
     2832                }
     2833
     2834               
     2835            }
     2836           
     2837            return flag;
     2838        }
     2839
     2840
     2841    /**
     2842        Any implementation of ActionListener must include this method so that we can be informed when an action as occured on our registered component,
     2843        allowing us to
     2844     * @param event An <strong>ActionEvent</strong> containing information about the event.
     2845         */
     2846    public void actionPerformed(ActionEvent event) {
     2847        Object source = event.getSource();
     2848           
     2849        if(source == ok_button)
     2850        {
     2851            String namespace_str = namespace_field.getText();
     2852            String name_str = Codec.transform(Codec.transformUnicode(name_field.getText()), Codec.TEXT_TO_DOM);
     2853            //Note: The name in name_str is language dependent. However, currently GEMS does not create new sets with different names for different languages.
     2854            String current_set_namespace = current_set.getNamespace();
     2855
     2856            //System.err.println("namespace_str is: " + namespace_str);
     2857            //System.err.println("name_str is: " + name_str);
     2858            //System.err.println("current_set_namespace is: " + current_set_namespace);
     2859
     2860            //Ensure that the namespace is unique.
     2861            if(!(a_set_exists_with_this_namespace(namespace_str)) || (namespace_str.equals(current_set_namespace)))
     2862            {
     2863                //Hide the set that are about to rename
     2864                mds_tree.clearSelection();
     2865                model.remove(current_set.toString(), GEMSNode.SET);
     2866
     2867                //Rename set & namespace
     2868                msm.renameSet(current_set, namespace_str, name_str);
     2869
     2870                //Add (renamed) set back to tree
     2871                model.add(null, current_set, GEMSNode.SET);
     2872
     2873                //Clean up
     2874                card_layout.show(details_pane, BLANK); // Show a blank panel.
     2875                ignore = false;
     2876                atLeastOneSetChanged = true;
     2877                setVisible(false);
     2878            }
     2879               
     2880            // Otherwise show an error message and do not proceed.
     2881            else
     2882            {
     2883                JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.Set_Already_Exists"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     2884            }
     2885            name_str = null;
     2886           
     2887        }
     2888
     2889        else if(source == cancel_button)
     2890        {
     2891            setVisible(false); //hide dialog
     2892        }
     2893        else
     2894        {
     2895            name_field.setText(current_set.getName()); //getName() doesn't work properly. Need to update MetadataSet.java
     2896            //getName() only doesn't work when the name is exactly the same as the namespace.
     2897            namespace_field.setText(current_set.getNamespace());
     2898            setVisible(true); //Show the dialog
     2899        }
     2900           
     2901        source = null;
     2902    }
     2903   
     2904
     2905    public void dispose() {
     2906        cancel_button = null;
     2907        ok_button = null;
     2908        name_field = null;
     2909        //System.err.println("Dispose AddElementActionListener");
     2910        super.dispose();
     2911    }
     2912
     2913    }
     2914
     2915 /**
     2916       Class to hand renaming of an element.
     2917
     2918       Author: Matthew Whyte
     2919       Date last modified: 10/01/05
     2920    */
     2921    private class RenameElementActionListener extends ModalDialog implements ActionListener {
     2922
     2923    private JButton cancel_button = null;
     2924    private JButton ok_button = null;
     2925    //private JLabel label = null;
     2926    private NonWhitespaceField name_field = null;
     2927
     2928       
     2929    public RenameElementActionListener() {
     2930        super(self);
     2931        setModal(true);
     2932        setSize(RENAME_ELEMENT_SIZE);
     2933        // Creation
     2934        JPanel content_pane = (JPanel) getContentPane();
     2935        content_pane.setBackground(config.getColor("coloring.collection_heading_background", false));
     2936        JPanel center_pane = new JPanel();
     2937        center_pane.setOpaque(false);
     2938
    27182939        JPanel labels_pane = new JPanel();
    27192940        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);
     2941        //JLabel set_label = new JLabel();
     2942        //set_label.setOpaque(false);
     2943        //Dictionary.setText(set_label, "GEMS.Rename_Element");
     2944        //label = new JLabel();
     2945        //label.setOpaque(false);
    27252946
    27262947        JPanel values_pane = new JPanel();
     
    27482969        TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button);
    27492970
     2971        Dictionary.setText(this, "GEMS.Rename_Element");
     2972       
    27502973        // Connection
    27512974        cancel_button.addActionListener(this);
     
    27552978        // Layout
    27562979        labels_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    2757         labels_pane.setLayout(new GridLayout(2,1));
    2758         labels_pane.add(set_label);
     2980        labels_pane.setLayout(new GridLayout(1,1));
     2981        //labels_pane.add(set_label);
    27592982        labels_pane.add(name_label);
    27602983
    27612984        values_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
    2762         values_pane.setLayout(new GridLayout(2,1));
    2763         values_pane.add(label);
     2985        values_pane.setLayout(new GridLayout(1,1));
     2986        //values_pane.add(label);
    27642987        values_pane.add(name_field);
    27652988
     
    28333056        else
    28343057        {
    2835             name_field.setText(""); //remove old text
     3058            name_field.setText(current_element.getName()); //show old name
    28363059            setVisible(true); //Show the dialog
    28373060        }
     
    28453068        ok_button = null;
    28463069        name_field = null;
    2847         label = null;
     3070        //label = null;
    28483071        //System.err.println("Dispose AddElementActionListener");
    28493072        super.dispose();
     
    28513074
    28523075    }
     3076
     3077
    28533078
    28543079
     
    32133438    }
    32143439   
     3440
    32153441    //PopupListener is our main manager for all right-click popups
    32163442  class PopupListener extends MouseAdapter implements ActionListener{
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSet.java

    r8881 r8896  
    407407    return root.getAttribute("lastchanged");
    408408    }
    409     /** Method to get this metadata sets name. Note that this is language specific, so we determine the desired language from the Dictionary. If no such entry exists, first try returning the english version and failing that the first name found.
     409
     410    /** Method to get this metadata sets name. Note that this is language specific, so we determine the desired language from the Dictionary.
     411    If no such entry exists, first try returning the english version and failing that the first name found.
    410412     * @return A <strong>String</strong> which contains its name.
    411413     */
     
    430432    return root.getAttribute("namespace");
    431433    }
     434
     435    /**
     436       Method to change this metadata set's namespace
     437       @param: The new namespace as a <strong>String</strong>
     438     */
     439    public void setNamespace(String new_namespace)
     440    {
     441    root.setAttribute("namespace", new_namespace);
     442    }
     443
    432444    /** Method to retrieve the root element, i.e. the Document Element, of the DOM model behind this metadata set.
    433445     * @return An <strong>Element</strong> which is at the root of the modal.
  • trunk/gli/src/org/greenstone/gatherer/gems/MetadataSetManager.java

    r8881 r8896  
    103103    return mds;
    104104    }
     105
     106    /**
     107       Method to rename a metadata set.
     108       @param: current_set: The metadata set to rename
     109       @param: new_namspace: The new namespace for the current_set
     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
     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
     115       @author Matthew Whyte
     116       Date last modified: 10/01/12
     117    */
     118    public void renameSet(MetadataSet current_set, String new_namespace, String new_name)
     119    {
     120    if(current_set != null)
     121        {
     122        //Update the namespace
     123        current_set.setNamespace(new_namespace);
     124
     125        //Update the name
     126        //Element name = new Element(current_set.getElement(Name));
     127        current_set.setName(new_name);
     128        }
     129
     130    else
     131        {
     132        System.err.println("No such set " + current_set);
     133        }
     134    }
     135
     136
    105137    public Vector getVectorSets() {   
    106138        Vector sets = new Vector();
Note: See TracChangeset for help on using the changeset viewer.