Changeset 12662
- Timestamp:
- 2006-09-05T11:33:14+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/NewMetadataSetPrompt.java
r12564 r12662 60 60 61 61 private JButton ok_button = null; 62 private JButton c lose_button = null;62 private JButton cancel_button = null; 63 63 private JComboBox base_metadata_combo; 64 64 private NewMetadataSetPrompt self; … … 110 110 111 111 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 112 JLabel description_label = new JLabel(Dictionary.get("GEMS.Set_Description")); 113 description_label.setOpaque(true); 114 115 description_textarea = new JTextArea(); 116 116 description_textarea.setLineWrap(true); 117 117 description_textarea.setWrapStyleWord(true); 118 118 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); 123 123 124 124 … … 136 136 JPanel button_pane = new JPanel(); 137 137 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip")); 138 c lose_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")); 139 139 140 140 … … 142 142 ok_button.addActionListener(new ActionListener() { 143 143 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 146 148 } 147 149 }); 148 150 149 150 c lose_button.addActionListener(new ActionListener() {151 152 cancel_button.addActionListener(new ActionListener() { 151 153 public void actionPerformed(ActionEvent event) { 152 154 self.dispose(); 153 155 } 154 156 }); 155 156 157 158 157 159 button_pane.setLayout(new GridLayout(1,2)); 158 160 button_pane.add(ok_button); 159 button_pane.add(c lose_button);160 161 162 163 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 165 167 content_pane.setLayout(new BorderLayout(5,5)); 166 168 content_pane.add(info_pane, BorderLayout.NORTH); 167 content_pane.add(des _pane, BorderLayout.CENTER);169 content_pane.add(description_pane, BorderLayout.CENTER); 168 170 content_pane.add(bottom_pane, BorderLayout.SOUTH); 169 171 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); … … 173 175 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); 174 176 setVisible(false); 175 176 } 177 178 177 178 } 179 180 179 181 public void display(){ 180 181 182 183 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); 184 186 title_field.setText(""); 185 187 namespace_field.setText(""); 186 188 description_textarea.setText(""); 187 189 base_metadata_combo.setModel(model); 188 190 setVisible(true); 189 191 } 190 192 191 193 public void addMetadataSetListener(MetadataSetListener msl){ 192 194 listeners.add(msl); 193 195 194 196 } 195 197 196 private void notifyListeners(){198 private boolean createNewSet() { 197 199 198 200 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; 227 226 228 229 230 231 232 233 227 if ((selectedValue instanceof MetadataSetInfo)){ 228 meta_info = (MetadataSetInfo)selectedValue; 229 } 230 else{ 231 meta_info = new MetadataSetInfo(); 232 } 234 233 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; 247 242 } 248 243 … … 256 251 } 257 252 258 private class MetadatSetListCellRenderer extends JLabel implements ListCellRenderer { 253 private class MetadatSetListCellRenderer extends JLabel 254 implements ListCellRenderer { 259 255 public MetadatSetListCellRenderer() { 260 256 setOpaque(true); 261 257 } 262 258 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) 269 264 { 270 265 String name= "unknown"; … … 273 268 MetadataSetInfo meta_info = (MetadataSetInfo) value; 274 269 name = meta_info.getMetadataSetName(); //get the name of metadata set 275 276 } 277 else{270 setText(name); 271 } 272 else { 278 273 setText(value.toString()); 279 274 } 280 275 281 276 if (isSelected) { 282 277 setBackground(list.getSelectionBackground()); 283 278 setForeground(list.getSelectionForeground());
Note:
See TracChangeset
for help on using the changeset viewer.