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 | */
|
---|
37 | package org.greenstone.gatherer.gems;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import javax.swing.*;
|
---|
42 | import javax.swing.event.*;
|
---|
43 | import java.util.ArrayList;
|
---|
44 | import java.util.HashMap;
|
---|
45 | import java.util.Collection;
|
---|
46 | import java.util.Vector;
|
---|
47 |
|
---|
48 | import org.greenstone.gatherer.Configuration;
|
---|
49 | import org.greenstone.gatherer.Dictionary;
|
---|
50 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
51 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
52 |
|
---|
53 | public 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 close_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 | public NewMetadataSetPrompt(Frame parent,MetadataSetManager msm) {
|
---|
71 | super(parent, true);
|
---|
72 | self = this;
|
---|
73 | listeners = new ArrayList();
|
---|
74 | meta_manager = msm;
|
---|
75 |
|
---|
76 | setSize(SIZE);
|
---|
77 | setTitle(Dictionary.get("GEMS.NewMetadataSetPrompt.Title"));
|
---|
78 |
|
---|
79 | JPanel content_pane = (JPanel) getContentPane();
|
---|
80 | content_pane.setOpaque(true);
|
---|
81 |
|
---|
82 | JLabel instruction_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Instructions"));
|
---|
83 | instruction_label.setOpaque(true);
|
---|
84 |
|
---|
85 | JLabel title_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Title"));
|
---|
86 | title_label.setOpaque(true);
|
---|
87 |
|
---|
88 | title_field = new JTextField();
|
---|
89 |
|
---|
90 | JPanel title_pane = new JPanel(new BorderLayout(5,5));
|
---|
91 | title_pane.add(title_label,BorderLayout.WEST);
|
---|
92 | title_pane.add(title_field, BorderLayout.CENTER);
|
---|
93 |
|
---|
94 |
|
---|
95 | JLabel namespace_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Metadata_Namespace"));
|
---|
96 | namespace_label.setOpaque(true);
|
---|
97 |
|
---|
98 | namespace_field = new JTextField();
|
---|
99 |
|
---|
100 | JPanel namespace_pane = new JPanel(new BorderLayout(5,5));
|
---|
101 | namespace_pane.add(namespace_label,BorderLayout.WEST);
|
---|
102 | namespace_pane.add(namespace_field, BorderLayout.CENTER);
|
---|
103 |
|
---|
104 |
|
---|
105 | JPanel info_pane = new JPanel();
|
---|
106 | info_pane.setLayout(new BorderLayout(5,5));
|
---|
107 | info_pane.add(instruction_label,BorderLayout.NORTH);
|
---|
108 | info_pane.add(title_pane,BorderLayout.CENTER);
|
---|
109 | info_pane.add(namespace_pane,BorderLayout.SOUTH);
|
---|
110 |
|
---|
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 JTextArea();
|
---|
116 | description_textarea.setLineWrap(true);
|
---|
117 | description_textarea.setWrapStyleWord(true);
|
---|
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);
|
---|
123 |
|
---|
124 |
|
---|
125 | JLabel base_label = new JLabel(Dictionary.get("GEMS.NewMetadataSetPrompt.Base_MetadataSet"));
|
---|
126 | base_label.setOpaque(true);
|
---|
127 |
|
---|
128 | base_metadata_combo = new JComboBox();
|
---|
129 | base_metadata_combo.setRenderer(new MetadatSetListCellRenderer());
|
---|
130 |
|
---|
131 | JPanel base_pane = new JPanel(new BorderLayout(5,5));
|
---|
132 | base_pane.add(base_label,BorderLayout.WEST);
|
---|
133 | base_pane.add(base_metadata_combo, BorderLayout.CENTER);
|
---|
134 |
|
---|
135 |
|
---|
136 | JPanel button_pane = new JPanel();
|
---|
137 | 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"));
|
---|
139 |
|
---|
140 |
|
---|
141 | // Add listeners
|
---|
142 | ok_button.addActionListener(new ActionListener() {
|
---|
143 | public void actionPerformed(ActionEvent event) {
|
---|
144 | notifyListeners();
|
---|
145 | self.dispose();
|
---|
146 | }
|
---|
147 | });
|
---|
148 |
|
---|
149 |
|
---|
150 | close_button.addActionListener(new ActionListener() {
|
---|
151 | public void actionPerformed(ActionEvent event) {
|
---|
152 | self.dispose();
|
---|
153 | }
|
---|
154 | });
|
---|
155 |
|
---|
156 |
|
---|
157 | button_pane.setLayout(new GridLayout(1,2));
|
---|
158 | 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 |
|
---|
165 | content_pane.setLayout(new BorderLayout(5,5));
|
---|
166 | content_pane.add(info_pane, BorderLayout.NORTH);
|
---|
167 | content_pane.add(des_pane, BorderLayout.CENTER);
|
---|
168 | content_pane.add(bottom_pane, BorderLayout.SOUTH);
|
---|
169 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
170 |
|
---|
171 | // Show
|
---|
172 | Dimension screen_size = Configuration.screen_size;
|
---|
173 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
174 | setVisible(false);
|
---|
175 |
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 | 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);
|
---|
184 | title_field.setText("");
|
---|
185 | namespace_field.setText("");
|
---|
186 | description_textarea.setText("");
|
---|
187 | base_metadata_combo.setModel(model);
|
---|
188 | setVisible(true);
|
---|
189 | }
|
---|
190 |
|
---|
191 | public void addMetadataSetListener(MetadataSetListener msl){
|
---|
192 | listeners.add(msl);
|
---|
193 |
|
---|
194 | }
|
---|
195 |
|
---|
196 | private void notifyListeners(){
|
---|
197 |
|
---|
198 | 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;
|
---|
227 |
|
---|
228 | if ((selectedValue instanceof MetadataSetInfo)){
|
---|
229 | meta_info = (MetadataSetInfo)selectedValue;
|
---|
230 | }
|
---|
231 | else{
|
---|
232 | meta_info = new MetadataSetInfo();
|
---|
233 | }
|
---|
234 |
|
---|
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 |
|
---|
247 | }
|
---|
248 |
|
---|
249 |
|
---|
250 | private void notifyListeners(MetadataSetInfo set_info){
|
---|
251 | MetadataSetEvent mse = new MetadataSetEvent(set_info);
|
---|
252 | for(int i=0;i<listeners.size();i++){
|
---|
253 | MetadataSetListener msl = (MetadataSetListener)listeners.get(i);
|
---|
254 | msl.metadataSetChanged(mse);
|
---|
255 | }
|
---|
256 | }
|
---|
257 |
|
---|
258 | private class MetadatSetListCellRenderer extends JLabel implements ListCellRenderer {
|
---|
259 | public MetadatSetListCellRenderer() {
|
---|
260 | setOpaque(true);
|
---|
261 | }
|
---|
262 |
|
---|
263 | public Component getListCellRendererComponent(
|
---|
264 | JList list,
|
---|
265 | Object value,
|
---|
266 | int index,
|
---|
267 | boolean isSelected,
|
---|
268 | boolean cellHasFocus)
|
---|
269 | {
|
---|
270 | String name= "unknown";
|
---|
271 |
|
---|
272 | if (value instanceof MetadataSetInfo){
|
---|
273 | MetadataSetInfo meta_info = (MetadataSetInfo) value;
|
---|
274 | name = meta_info.getMetadataSetName(); //get the name of metadata set
|
---|
275 | setText(name);
|
---|
276 | }
|
---|
277 | else{
|
---|
278 | setText(value.toString());
|
---|
279 | }
|
---|
280 |
|
---|
281 | if (isSelected) {
|
---|
282 | setBackground(list.getSelectionBackground());
|
---|
283 | setForeground(list.getSelectionForeground());
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | setBackground(list.getBackground());
|
---|
287 | setForeground(list.getForeground());
|
---|
288 | }
|
---|
289 |
|
---|
290 | return this;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | }
|
---|