source: trunk/gli/src/org/greenstone/gatherer/gems/NewMetadataSetPrompt.java@ 12701

Last change on this file since 12701 was 12701, checked in by kjdon, 18 years ago

when creating a new set based on an old one, we want to delete all lang dependent attributes belonging to the set

  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: Shaoqun Wu, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 2006 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gems;
38
39import java.awt.*;
40import java.awt.event.*;
41import javax.swing.*;
42import javax.swing.event.*;
43import java.util.ArrayList;
44import java.util.HashMap;
45import java.util.Collection;
46import java.util.Vector;
47
48import org.greenstone.gatherer.Configuration;
49import org.greenstone.gatherer.Dictionary;
50import org.greenstone.gatherer.gui.ModalDialog;
51import org.greenstone.gatherer.gui.GLIButton;
52
53public class NewMetadataSetPrompt
54 extends ModalDialog {
55
56 static private Dimension SIZE = new Dimension(500, 320);
57
58 private ArrayList available_metadata_sets;
59 private ArrayList listeners;
60
61 private JButton ok_button = null;
62 private JButton cancel_button = null;
63 private JComboBox base_metadata_combo;
64 private NewMetadataSetPrompt self;
65 private MetadataSetManager meta_manager;
66 private JTextArea description_textarea = null;
67 private JTextField title_field;
68 private JTextField namespace_field;
69
70 private boolean cancelled = false;
71
72 public NewMetadataSetPrompt(Frame parent,MetadataSetManager msm) {
73 super(parent, true);
74 self = this;
75 listeners = new ArrayList();
76 meta_manager = msm;
77
78 setSize(SIZE);
79 setTitle(Dictionary.get("GEMS.NewMetadataSetPrompt.Title"));
80
81 JPanel content_pane = (JPanel) getContentPane();
82 content_pane.setOpaque(true);
83
84 JLabel instruction_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Instructions"));
85 instruction_label.setOpaque(true);
86
87 JLabel title_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Title"));
88 title_label.setOpaque(true);
89
90 title_field = new JTextField();
91
92 JPanel title_pane = new JPanel(new BorderLayout(5,5));
93 title_pane.add(title_label,BorderLayout.WEST);
94 title_pane.add(title_field, BorderLayout.CENTER);
95
96
97 JLabel namespace_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Namespace"));
98 namespace_label.setOpaque(true);
99
100 namespace_field = new JTextField();
101
102 JPanel namespace_pane = new JPanel(new BorderLayout(5,5));
103 namespace_pane.add(namespace_label,BorderLayout.WEST);
104 namespace_pane.add(namespace_field, BorderLayout.CENTER);
105
106
107 JPanel info_pane = new JPanel();
108 info_pane.setLayout(new BorderLayout(5,5));
109 info_pane.add(instruction_label,BorderLayout.NORTH);
110 info_pane.add(title_pane,BorderLayout.CENTER);
111 info_pane.add(namespace_pane,BorderLayout.SOUTH);
112
113
114 JLabel description_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
115 description_label.setOpaque(true);
116
117 description_textarea = new JTextArea();
118 description_textarea.setLineWrap(true);
119 description_textarea.setWrapStyleWord(true);
120
121 JPanel description_pane = new JPanel();
122 description_pane.setLayout(new BorderLayout());
123 description_pane.add(description_label,BorderLayout.NORTH);
124 description_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
125
126
127 JLabel base_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Base_MetadataSet"));
128 base_label.setOpaque(true);
129
130 base_metadata_combo = new JComboBox();
131 base_metadata_combo.setRenderer(new MetadatSetListCellRenderer());
132
133 JPanel base_pane = new JPanel(new BorderLayout(5,5));
134 base_pane.add(base_label,BorderLayout.WEST);
135 base_pane.add(base_metadata_combo, BorderLayout.CENTER);
136
137
138 JPanel button_pane = new JPanel();
139 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
140 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
141
142
143 // Add listeners
144 ok_button.addActionListener(new ActionListener() {
145 public void actionPerformed(ActionEvent event) {
146 if (createNewSet()) {
147 self.dispose();
148 } // else if that returned false, then we leave the
149 // prompt there for them to change their input
150 }
151 });
152
153
154 cancel_button.addActionListener(new ActionListener() {
155 public void actionPerformed(ActionEvent event) {
156 cancelled = true;
157 self.dispose();
158 }
159 });
160
161
162 button_pane.setLayout(new GridLayout(1,2));
163 button_pane.add(ok_button);
164 button_pane.add(cancel_button);
165
166 JPanel bottom_pane = new JPanel(new GridLayout(2,1,5,5));
167 bottom_pane.add(base_pane);
168 bottom_pane.add(button_pane);
169
170 content_pane.setLayout(new BorderLayout(5,5));
171 content_pane.add(info_pane, BorderLayout.NORTH);
172 content_pane.add(description_pane, BorderLayout.CENTER);
173 content_pane.add(bottom_pane, BorderLayout.SOUTH);
174 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
175
176 // Show
177 Dimension screen_size = Configuration.screen_size;
178 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
179 setVisible(false);
180
181 }
182
183
184 public void display(){
185 cancelled = false;
186 available_metadata_sets = meta_manager.getAvailableMetadataSets();
187 Vector data = new Vector((Collection)available_metadata_sets);
188 data.add(0,Dictionary.get("GEMS.NewMetadataSetPrompt.New_Metadata"));
189 DefaultComboBoxModel model = new DefaultComboBoxModel(data);
190 title_field.setText("");
191 namespace_field.setText("");
192 description_textarea.setText("");
193 base_metadata_combo.setModel(model);
194 setVisible(true);
195 }
196
197 public boolean isCancelled() {
198 return cancelled;
199 }
200
201 public void addMetadataSetListener(MetadataSetListener msl){
202 listeners.add(msl);
203
204 }
205
206 private boolean createNewSet() {
207
208 String title = title_field.getText();
209 String namespace = namespace_field.getText();
210 String description = description_textarea.getText();
211
212 if (title == null || title.trim().equals("")){
213 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error"), JOptionPane.ERROR_MESSAGE);
214
215 return false;
216 }
217
218 if (namespace == null || namespace.trim().equals("")){
219 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error"), JOptionPane.ERROR_MESSAGE);
220 return false;
221 }
222
223 //check namespace conflict
224 if (meta_manager.isNamespaceAlreadyUsed(namespace)) {
225 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] );
226
227 if (result != JOptionPane.OK_OPTION) return false;
228 }
229
230 Object selectedValue = base_metadata_combo.getSelectedItem();
231
232 if (selectedValue != null ){
233 MetadataSetInfo meta_info = null;
234
235 if ((selectedValue instanceof MetadataSetInfo)){
236 meta_info = (MetadataSetInfo)selectedValue;
237 }
238 else{
239 meta_info = new MetadataSetInfo();
240 }
241
242 meta_info.setNew(true);
243 // clear all the language dependent attributes
244 meta_info.setLanguageDependentAttributes(new ArrayList());
245 meta_info.setMetadataSetName(title);
246 meta_info.setMetadataSetDescription(description);
247 meta_info.setNamespace(namespace);
248 meta_info.setCurrentLanguage(meta_manager.getCurrentLanguage());
249 notifyListeners(meta_info);
250 }
251 return true;
252 }
253
254
255 private void notifyListeners(MetadataSetInfo set_info){
256 MetadataSetEvent mse = new MetadataSetEvent(set_info);
257 for(int i=0;i<listeners.size();i++){
258 MetadataSetListener msl = (MetadataSetListener)listeners.get(i);
259 msl.metadataSetChanged(mse);
260 }
261 }
262
263 private class MetadatSetListCellRenderer extends JLabel
264 implements ListCellRenderer {
265 public MetadatSetListCellRenderer() {
266 setOpaque(true);
267 }
268
269 public Component getListCellRendererComponent(JList list,
270 Object value,
271 int index,
272 boolean isSelected,
273 boolean cellHasFocus)
274 {
275 String name= "unknown";
276
277 if (value instanceof MetadataSetInfo){
278 MetadataSetInfo meta_info = (MetadataSetInfo) value;
279 name = meta_info.getMetadataSetName(); //get the name of metadata set
280 setText(name);
281 }
282 else {
283 setText(value.toString());
284 }
285
286 if (isSelected) {
287 setBackground(list.getSelectionBackground());
288 setForeground(list.getSelectionForeground());
289 }
290 else {
291 setBackground(list.getBackground());
292 setForeground(list.getForeground());
293 }
294
295 return this;
296 }
297 }
298
299}
Note: See TracBrowser for help on using the repository browser.