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

Last change on this file since 18412 was 18412, checked in by kjdon, 15 years ago

more modifications for RTL GLI, thanks to Amin Hedjazi

  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 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 content_pane.setComponentOrientation(Dictionary.getOrientation());
84
85 JLabel instruction_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Instructions"));
86 instruction_label.setOpaque(true);
87 instruction_label.setComponentOrientation(Dictionary.getOrientation());
88
89 JLabel title_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Title"));
90 title_label.setOpaque(true);
91 title_label.setComponentOrientation(Dictionary.getOrientation());
92
93 title_field = new JTextField();
94 title_field.setComponentOrientation(Dictionary.getOrientation());
95
96 JPanel title_pane = new JPanel(new BorderLayout(5,5));
97 title_pane.setComponentOrientation(Dictionary.getOrientation());
98 title_pane.add(title_label,BorderLayout.LINE_START);
99 title_pane.add(title_field, BorderLayout.CENTER);
100
101
102 JLabel namespace_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Namespace"));
103 namespace_label.setComponentOrientation(Dictionary.getOrientation());
104 namespace_label.setOpaque(true);
105
106 namespace_field = new JTextField();
107 namespace_field.setComponentOrientation(Dictionary.getOrientation());
108
109 JPanel namespace_pane = new JPanel(new BorderLayout(5,5));
110 namespace_pane.setComponentOrientation(Dictionary.getOrientation());
111 namespace_pane.add(namespace_label,BorderLayout.LINE_START);
112 namespace_pane.add(namespace_field, BorderLayout.CENTER);
113
114
115 JPanel info_pane = new JPanel();
116 info_pane.setComponentOrientation(Dictionary.getOrientation());
117 info_pane.setLayout(new BorderLayout(5,5));
118 info_pane.add(instruction_label,BorderLayout.NORTH);
119 info_pane.add(title_pane,BorderLayout.CENTER);
120 info_pane.add(namespace_pane,BorderLayout.SOUTH);
121
122
123 JLabel description_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
124 description_label.setOpaque(true);
125 description_label.setComponentOrientation(Dictionary.getOrientation());
126
127 description_textarea = new JTextArea();
128 description_textarea.setComponentOrientation(Dictionary.getOrientation());
129 description_textarea.setLineWrap(true);
130 description_textarea.setWrapStyleWord(true);
131
132 JPanel description_pane = new JPanel();
133 description_pane.setComponentOrientation(Dictionary.getOrientation());
134 description_pane.setLayout(new BorderLayout());
135 description_pane.add(description_label,BorderLayout.NORTH);
136 description_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
137
138
139 JLabel base_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Base_MetadataSet"));
140 base_label.setOpaque(true);
141 base_label.setComponentOrientation(Dictionary.getOrientation());
142
143 base_metadata_combo = new JComboBox();
144 base_metadata_combo.setRenderer(new MetadatSetListCellRenderer());
145 base_metadata_combo.setComponentOrientation(Dictionary.getOrientation());
146
147 JPanel base_pane = new JPanel(new BorderLayout(5,5));
148 base_pane.setComponentOrientation(Dictionary.getOrientation());
149 base_pane.add(base_label,BorderLayout.LINE_START);
150 base_pane.add(base_metadata_combo, BorderLayout.CENTER);
151
152
153 JPanel button_pane = new JPanel();
154 button_pane.setComponentOrientation(Dictionary.getOrientation());
155 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
156 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
157
158
159 // Add listeners
160 ok_button.addActionListener(new ActionListener() {
161 public void actionPerformed(ActionEvent event) {
162 if (createNewSet()) {
163 self.dispose();
164 } // else if that returned false, then we leave the
165 // prompt there for them to change their input
166 }
167 });
168
169
170 cancel_button.addActionListener(new ActionListener() {
171 public void actionPerformed(ActionEvent event) {
172 cancelled = true;
173 self.dispose();
174 }
175 });
176
177
178 button_pane.setLayout(new GridLayout(1,2));
179 button_pane.add(ok_button);
180 button_pane.add(cancel_button);
181
182 JPanel bottom_pane = new JPanel(new GridLayout(2,1,5,5));
183 bottom_pane.add(base_pane);
184 bottom_pane.add(button_pane);
185
186 content_pane.setLayout(new BorderLayout(5,5));
187 content_pane.add(info_pane, BorderLayout.NORTH);
188 content_pane.add(description_pane, BorderLayout.CENTER);
189 content_pane.add(bottom_pane, BorderLayout.SOUTH);
190 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
191
192 // Show
193 Dimension screen_size = Configuration.screen_size;
194 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
195 setVisible(false);
196
197 }
198
199
200 public void display(){
201 cancelled = false;
202 available_metadata_sets = meta_manager.getAvailableMetadataSets();
203 Vector data = new Vector((Collection)available_metadata_sets);
204 data.add(0,Dictionary.get("GEMS.NewMetadataSetPrompt.New_Metadata"));
205 DefaultComboBoxModel model = new DefaultComboBoxModel(data);
206 title_field.setText("");
207 namespace_field.setText("");
208 description_textarea.setText("");
209 base_metadata_combo.setModel(model);
210 setVisible(true);
211 }
212
213 public boolean isCancelled() {
214 return cancelled;
215 }
216
217 public void addMetadataSetListener(MetadataSetListener msl){
218 listeners.add(msl);
219
220 }
221
222 private boolean createNewSet() {
223
224 String title = title_field.getText();
225 String namespace = namespace_field.getText();
226 String description = description_textarea.getText();
227
228 if (title == null || title.trim().equals("")){
229 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Title_Error"), JOptionPane.ERROR_MESSAGE);
230
231 return false;
232 }
233
234 if (namespace == null || namespace.trim().equals("")){
235 JOptionPane.showMessageDialog(self, Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error_Message"), Dictionary.get("GEMS.NewMetadataSetPrompt.Namespace_Error"), JOptionPane.ERROR_MESSAGE);
236 return false;
237 }
238
239 //check namespace conflict
240 if (meta_manager.isNamespaceAlreadyUsed(namespace)) {
241 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] );
242
243 if (result != JOptionPane.OK_OPTION) return false;
244 }
245
246 Object selectedValue = base_metadata_combo.getSelectedItem();
247
248 if (selectedValue != null ){
249 MetadataSetInfo meta_info = null;
250
251 if ((selectedValue instanceof MetadataSetInfo)){
252 meta_info = (MetadataSetInfo)selectedValue;
253 }
254 else{
255 meta_info = new MetadataSetInfo();
256 }
257
258 meta_info.setNew(true);
259 // clear all the language dependent attributes
260 meta_info.setLanguageDependentAttributes(new ArrayList());
261 meta_info.setMetadataSetName(title);
262 meta_info.setMetadataSetDescription(description);
263 meta_info.setNamespace(namespace);
264 meta_info.setCurrentLanguage(meta_manager.getCurrentLanguage());
265 notifyListeners(meta_info);
266 }
267 return true;
268 }
269
270
271 private void notifyListeners(MetadataSetInfo set_info){
272 MetadataSetEvent mse = new MetadataSetEvent(set_info);
273 for(int i=0;i<listeners.size();i++){
274 MetadataSetListener msl = (MetadataSetListener)listeners.get(i);
275 msl.metadataSetChanged(mse);
276 }
277 }
278
279 private class MetadatSetListCellRenderer extends JLabel
280 implements ListCellRenderer {
281 public MetadatSetListCellRenderer() {
282 setOpaque(true);
283 }
284
285 public Component getListCellRendererComponent(JList list,
286 Object value,
287 int index,
288 boolean isSelected,
289 boolean cellHasFocus)
290 {
291 String name= "unknown";
292
293 if (value instanceof MetadataSetInfo){
294 MetadataSetInfo meta_info = (MetadataSetInfo) value;
295 name = meta_info.getMetadataSetName(); //get the name of metadata set
296 setText(name);
297 }
298 else {
299 setText(value.toString());
300 }
301
302 if (isSelected) {
303 setBackground(list.getSelectionBackground());
304 setForeground(list.getSelectionForeground());
305 }
306 else {
307 setBackground(list.getBackground());
308 setForeground(list.getForeground());
309 }
310
311 return this;
312 }
313 }
314
315}
Note: See TracBrowser for help on using the repository browser.