Changeset 12662


Ignore:
Timestamp:
2006-09-05T11:33:14+12:00 (18 years ago)
Author:
kjdon
Message:

close button changed to cancel button; names of some components changed; if cancel during new set creation, e.g. at namespace clash dialog, then the new set prompt remains visible so they can keep going; some coding style changes, incl indenting; description entered at prompt gets set as an attribute

File:
1 edited

Legend:

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

    r12564 r12662  
    6060
    6161    private JButton ok_button = null;
    62     private JButton close_button = null;   
     62    private JButton cancel_button = null;   
    6363    private JComboBox base_metadata_combo;
    6464    private NewMetadataSetPrompt self;
     
    110110       
    111111
    112     JLabel  metadata_set_des_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
    113     metadata_set_des_label.setOpaque(true);
    114 
    115     description_textarea = new  JTextArea();
     112    JLabel description_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
     113    description_label.setOpaque(true);
     114
     115    description_textarea = new JTextArea();
    116116        description_textarea.setLineWrap(true);
    117117        description_textarea.setWrapStyleWord(true);
    118118
    119     JPanel des_pane = new JPanel();
    120         des_pane.setLayout(new BorderLayout());
    121         des_pane.add(metadata_set_des_label,BorderLayout.NORTH);
    122     des_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
     119    JPanel description_pane = new JPanel();
     120        description_pane.setLayout(new BorderLayout());
     121        description_pane.add(description_label,BorderLayout.NORTH);
     122    description_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
    123123
    124124       
     
    136136    JPanel button_pane = new JPanel();
    137137    ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));         
    138     close_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
     138    cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
    139139     
    140140
     
    142142    ok_button.addActionListener(new ActionListener() {
    143143        public void actionPerformed(ActionEvent event) {
    144             notifyListeners();
    145             self.dispose();
     144            if (createNewSet()) {
     145            self.dispose();
     146            } // else if that returned false, then we leave the
     147            // prompt there for them to change their input
    146148        }
    147149        });
    148150
    149 
    150     close_button.addActionListener(new ActionListener() {
     151                   
     152    cancel_button.addActionListener(new ActionListener() {
    151153        public void actionPerformed(ActionEvent event) {
    152154            self.dispose();
    153155        }
    154156        });
    155 
    156 
     157   
     158 
    157159    button_pane.setLayout(new GridLayout(1,2));
    158160    button_pane.add(ok_button);
    159     button_pane.add(close_button);
    160 
    161         JPanel bottom_pane = new JPanel(new GridLayout(2,1,5,5));
    162         bottom_pane.add(base_pane);
    163         bottom_pane.add(button_pane);
    164 
     161    button_pane.add(cancel_button);
     162   
     163    JPanel bottom_pane = new JPanel(new GridLayout(2,1,5,5));
     164    bottom_pane.add(base_pane);
     165    bottom_pane.add(button_pane);
     166   
    165167    content_pane.setLayout(new BorderLayout(5,5));
    166168    content_pane.add(info_pane, BorderLayout.NORTH);
    167     content_pane.add(des_pane, BorderLayout.CENTER);
     169    content_pane.add(description_pane, BorderLayout.CENTER);
    168170    content_pane.add(bottom_pane, BorderLayout.SOUTH);
    169171    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     
    173175    setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
    174176    setVisible(false);
    175 
    176     }
    177 
    178 
     177   
     178    }
     179   
     180   
    179181    public void display(){
    180         available_metadata_sets =  meta_manager.getAvailableMetadataSets();
    181         Vector data = new Vector((Collection)available_metadata_sets);
    182         data.add(0,Dictionary.get("GEMS.NewMetadataSetPrompt.New_Metadata"));
    183         DefaultComboBoxModel  model = new DefaultComboBoxModel(data);
     182    available_metadata_sets =  meta_manager.getAvailableMetadataSets();
     183    Vector data = new Vector((Collection)available_metadata_sets);
     184    data.add(0,Dictionary.get("GEMS.NewMetadataSetPrompt.New_Metadata"));
     185    DefaultComboBoxModel  model = new DefaultComboBoxModel(data);
    184186    title_field.setText("");
    185187    namespace_field.setText("");
    186188    description_textarea.setText("");
    187189    base_metadata_combo.setModel(model);
    188         setVisible(true);         
     190    setVisible(true);         
    189191    }
    190192
    191193    public void addMetadataSetListener(MetadataSetListener msl){
    192         listeners.add(msl);
     194    listeners.add(msl);
    193195   
    194196    }
    195197
    196     private void notifyListeners(){
     198    private boolean createNewSet() {
    197199
    198200    String title = title_field.getText();
    199         String namespace = namespace_field.getText();
    200         String description ="";
    201         description = description_textarea.getText();
    202 
    203         if (title == null || title.trim().equals("")){
    204         JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error"),Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error_MESSAGE"),JOptionPane.ERROR_MESSAGE);
    205 
    206         return;
    207     }
    208 
    209          if (namespace == null || namespace.trim().equals("")){
    210         JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error"),Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error_MESSAGE"),JOptionPane.ERROR_MESSAGE);
    211         return;
    212     }
    213 
    214       //check namespace conflict
    215      if (!meta_manager.checkNamespace(namespace))
    216          {
    217    
    218          int result = JOptionPane.showOptionDialog(null,Dictionary.get("GEMS.Namespace_Conflict_Message"), Dictionary.get("GEMS.Namespace_Conflict"),JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,null,GEMSConstants.DIALOG_OPTIONS,GEMSConstants.DIALOG_OPTIONS[0] );
    219          
    220          if (result !=JOptionPane.OK_OPTION) return;
    221          }
    222 
    223      Object selectedValue =base_metadata_combo.getSelectedItem();
    224        
    225      if (selectedValue !=null ){
    226          MetadataSetInfo meta_info = null;
     201    String namespace = namespace_field.getText();
     202    String description = description_textarea.getText();
     203
     204    if (title == null || title.trim().equals("")){
     205        JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error"), JOptionPane.ERROR_MESSAGE);
     206
     207        return false;
     208    }
     209
     210    if (namespace == null || namespace.trim().equals("")){
     211        JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error"), JOptionPane.ERROR_MESSAGE);
     212        return false;
     213    }
     214
     215    //check namespace conflict
     216    if (meta_manager.isNamespaceAlreadyUsed(namespace)) {
     217        int result = JOptionPane.showOptionDialog(null,Dictionary.get("GEMS.Namespace_Conflict_Message"), Dictionary.get("GEMS.Namespace_Conflict"),JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,null,GEMSConstants.DIALOG_OPTIONS,GEMSConstants.DIALOG_OPTIONS[0] );
     218         
     219        if (result != JOptionPane.OK_OPTION) return false;
     220    }
     221
     222    Object selectedValue = base_metadata_combo.getSelectedItem();
     223       
     224    if (selectedValue != null ){
     225        MetadataSetInfo meta_info = null;
    227226               
    228          if ((selectedValue instanceof MetadataSetInfo)){     
    229          meta_info = (MetadataSetInfo)selectedValue;
    230          }
    231          else{
    232          meta_info = new MetadataSetInfo();                 
    233          }
     227        if ((selectedValue instanceof MetadataSetInfo)){     
     228        meta_info = (MetadataSetInfo)selectedValue;
     229        }
     230        else{
     231        meta_info = new MetadataSetInfo();                 
     232        }
    234233               
    235          meta_info.setNew(true);
    236          meta_info.setMetadataSetName(title);
    237          meta_info.setNamespace(namespace);
    238          meta_info.setCurrentLanguage(meta_manager.getCurrentLanguage());
    239              
    240          MetadataSetEvent mse = new MetadataSetEvent(meta_info);
    241          for(int i=0;i<listeners.size();i++){
    242          MetadataSetListener msl = (MetadataSetListener)listeners.get(i);
    243          msl.metadataSetChanged(mse);         
    244          }
    245         }
    246        
     234        meta_info.setNew(true);
     235        meta_info.setMetadataSetName(title);
     236        meta_info.setMetadataSetDescription(description);
     237        meta_info.setNamespace(namespace);
     238        meta_info.setCurrentLanguage(meta_manager.getCurrentLanguage());
     239        notifyListeners(meta_info);
     240    }
     241    return true;
    247242    }
    248243
     
    256251    }
    257252
    258     private class MetadatSetListCellRenderer extends JLabel implements ListCellRenderer {
     253    private class MetadatSetListCellRenderer extends JLabel
     254    implements ListCellRenderer {
    259255    public  MetadatSetListCellRenderer() {
    260256        setOpaque(true);
    261257    }
    262258   
    263      public Component getListCellRendererComponent(
    264                            JList list,
    265                            Object value,
    266                            int index,
    267                            boolean isSelected,
    268          boolean cellHasFocus)
     259    public Component getListCellRendererComponent(JList list,
     260                              Object value,
     261                              int index,
     262                              boolean isSelected,
     263                              boolean cellHasFocus)
    269264    {
    270265        String name= "unknown";
     
    273268        MetadataSetInfo meta_info = (MetadataSetInfo) value;
    274269        name = meta_info.getMetadataSetName(); //get the name of metadata set
    275                 setText(name);
    276         }
    277             else{
     270        setText(name);
     271        }
     272        else {
    278273        setText(value.toString());
    279274        }
    280275
    281             if (isSelected) {
     276        if (isSelected) {
    282277        setBackground(list.getSelectionBackground());
    283278        setForeground(list.getSelectionForeground());
Note: See TracChangeset for help on using the changeset viewer.