source: trunk/gli/src/org/greenstone/gatherer/gems/DeleteMetadataSetPrompt.java@ 12679

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

removed some double spaces

  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 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.Collection;
45import java.util.Vector;
46import java.util.HashMap;
47
48
49import org.greenstone.gatherer.Configuration;
50import org.greenstone.gatherer.Dictionary;
51import org.greenstone.gatherer.gui.ModalDialog;
52import org.greenstone.gatherer.gui.GLIButton;
53
54public class DeleteMetadataSetPrompt
55 extends ModalDialog {
56
57 static private Dimension SIZE = new Dimension(500, 500);
58
59 private ArrayList available_metadata_sets;
60 private ArrayList listeners;
61
62 private JCheckBox confirmation = null;
63 private JButton delete_button = null;
64 private JButton close_button = null;
65 private JList available_set_list = null;
66 /** The model behind the list. */
67 private DefaultListModel list_model = null;
68 private JTextArea description_textarea = null;
69 private DeleteMetadataSetPrompt self;
70 private MetadataSetManager meta_manager;
71
72 public DeleteMetadataSetPrompt(Frame parent,MetadataSetManager msm) {
73 super(parent, true);
74
75 self = this;
76 meta_manager = msm;
77 listeners = new ArrayList();
78
79 setSize(SIZE);
80 setTitle(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Title"));
81
82 JPanel content_pane = (JPanel) getContentPane();
83 content_pane.setOpaque(true);
84
85
86 JLabel available_metadata_sets_label = new JLabel(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Available_Sets"));
87 available_metadata_sets_label.setOpaque(true);
88
89 list_model = new DefaultListModel();
90
91 available_set_list = new JList();
92 available_set_list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
93 available_set_list.setModel(list_model);
94 available_set_list.setCellRenderer(new MetadatSetListCellRenderer());
95 available_set_list.setFixedCellHeight(20);
96 available_set_list.addListSelectionListener(new MetadataSetListSelectionListener());
97
98 JPanel set_pane = new JPanel();
99 set_pane.setLayout(new BorderLayout());
100 set_pane.add(available_metadata_sets_label,BorderLayout.NORTH);
101 set_pane.add(new JScrollPane(available_set_list),BorderLayout.CENTER);
102
103
104 JLabel metadata_set_des_label = new JLabel(Dictionary.get("GEMS.Set_Description"));
105 metadata_set_des_label.setOpaque(true);
106
107 description_textarea = new JTextArea();
108 description_textarea.setOpaque(true);
109 description_textarea.setEditable(false);
110 description_textarea.setLineWrap(true);
111 description_textarea.setWrapStyleWord(true);
112
113 JPanel des_pane = new JPanel();
114 des_pane.setLayout(new BorderLayout());
115 des_pane.add(metadata_set_des_label,BorderLayout.NORTH);
116 des_pane.add(new JScrollPane(description_textarea),BorderLayout.CENTER);
117
118 JPanel button_pane = new JPanel();
119 delete_button = new GLIButton(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Delete"), Dictionary.get("GEMS.DeleteMetadataSetPrompt.Delete_Tooltip"));
120 delete_button.setEnabled(false);
121
122
123 confirmation = new JCheckBox(Dictionary.get("GEMS.DeleteMetadataSetPrompt.Confirm_Delete"));
124 confirmation.setEnabled(false);
125 confirmation.setSelected(false);
126
127 close_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
128 close_button.setEnabled(true);
129
130 confirmation.addActionListener(new ActionListener() {
131 public void actionPerformed(ActionEvent event) {
132 delete_button.setEnabled(confirmation.isSelected());
133 //confirmation.setEnabled(false);
134 //confirmation.setSelected(false);
135 }
136 });
137
138 // Add listeners
139 delete_button.addActionListener(new DeleteButtonListener());
140
141 close_button.addActionListener(new ActionListener() {
142 public void actionPerformed(ActionEvent event) {
143 self.dispose();
144 }
145 });
146
147
148 button_pane.setLayout(new GridLayout(1,2));
149 button_pane.add(delete_button);
150 button_pane.add(close_button);
151
152 JPanel bottom_pane = new JPanel();
153 bottom_pane.setLayout(new BorderLayout());
154 bottom_pane.add(confirmation,BorderLayout.NORTH);
155 bottom_pane.add(button_pane, BorderLayout.CENTER);
156
157
158 content_pane.setLayout(new BorderLayout());
159 content_pane.add(set_pane, BorderLayout.NORTH);
160 content_pane.add(des_pane, BorderLayout.CENTER);
161 content_pane.add(bottom_pane, BorderLayout.SOUTH);
162
163 // Show
164 Dimension screen_size = Configuration.screen_size;
165 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
166 setVisible(false);
167 }
168
169
170 public void display() {
171 available_metadata_sets = meta_manager.getAvailableMetadataSets();
172 for (int i=0; i<available_metadata_sets.size(); i++) {
173 list_model.addElement(available_metadata_sets.get(i));
174 }
175 //available_set_list.setListData(new Vector((Collection)available_metadata_sets));
176 delete_button.setEnabled(false);
177 confirmation.setEnabled(false);
178 confirmation.setSelected(false);
179 setVisible(true);
180
181 }
182
183
184 /** The Delete button listener implementation. */
185 private class DeleteButtonListener
186 implements ActionListener {
187 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
188 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
189 * @see org.greenstone.gatherer.Configuration
190 * @see org.greenstone.gatherer.Gatherer
191 * @see org.greenstone.gatherer.util.Utility
192 */
193 public void actionPerformed(ActionEvent event) {
194 // Delete the selected MetadataSet.
195 Object selectedValue = available_set_list.getSelectedValue();
196
197 if (selectedValue !=null && (selectedValue instanceof MetadataSetInfo)){
198 ((MetadataSetInfo)selectedValue).deleteMetadataSet();
199 list_model.removeElement(selectedValue);
200 }
201 delete_button.setEnabled(false);
202 confirmation.setEnabled(false);
203 confirmation.setSelected(false);
204 description_textarea.setText(Dictionary.get("GEMS.DeleteMetadataSetPrompt.No_Set"));
205 //self.dispose();
206 }
207
208 }
209
210
211 private class MetadatSetListCellRenderer extends JLabel implements ListCellRenderer {
212 public MetadatSetListCellRenderer() {
213 setOpaque(true);
214 }
215
216 public Component getListCellRendererComponent(JList list,
217 Object value,
218 int index,
219 boolean isSelected,
220 boolean cellHasFocus)
221 {
222 String name= "unknown";
223
224 if (value instanceof MetadataSetInfo){
225 MetadataSetInfo meta_info = (MetadataSetInfo) value;
226 name = meta_info.getMetadataSetName();
227 }
228
229 setText(name);
230 if (isSelected) {
231 setBackground(list.getSelectionBackground());
232 setForeground(list.getSelectionForeground());
233 }
234 else {
235 setBackground(list.getBackground());
236 setForeground(list.getForeground());
237 }
238
239 return this;
240 }
241 }
242
243
244 private class MetadataSetListSelectionListener implements ListSelectionListener {
245 public void valueChanged(ListSelectionEvent lse){
246 if (lse.getValueIsAdjusting()) return;
247
248 delete_button.setEnabled(false);
249
250 Object selectedValue = available_set_list.getSelectedValue();
251
252 if (selectedValue !=null && (selectedValue instanceof MetadataSetInfo)){
253 MetadataSetInfo meta_info = (MetadataSetInfo)selectedValue;
254 description_textarea.setText(meta_info.getMetadataSetDescription());
255 confirmation.setEnabled(true);
256 confirmation.setSelected(false);
257 }
258 else {
259 confirmation.setEnabled(false);
260 description_textarea.setText(Dictionary.get("GEMS.DeleteMetadataSetPrompt.No_Set"));
261 }
262
263 }
264 }
265
266
267
268 public void addMetadataSetListener(MetadataSetListener msl){
269 listeners.add(msl);
270 }
271
272
273}
Note: See TracBrowser for help on using the repository browser.