source: trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java@ 5912

Last change on this file since 5912 was 5893, checked in by kjdon, 21 years ago

instead of configuring the server via the preview pane, now we do it via the Gatherer itself

  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 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: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 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.collection;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
43import javax.swing.event.*;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.Gatherer;
46import org.greenstone.gatherer.collection.Collection;
47import org.greenstone.gatherer.gui.ModalDialog;
48import org.greenstone.gatherer.gui.SimpleMenuBar;
49import org.greenstone.gatherer.gui.tree.DragTree;
50import org.greenstone.gatherer.util.ArrayTools;
51import org.greenstone.gatherer.util.GSDLSiteConfig;
52import org.greenstone.gatherer.util.StaticStrings;
53import org.greenstone.gatherer.util.Utility;
54
55/** This class provides the functionality to delete current collections from the GSDLHOME/collect/ directory. The user chooses the collection from a list, where each entry also displays details about itself, confirms the delete of a collection by checking a checkbox then presses the ok button to actually delete the collection.
56 * @author John Thompson, Greenstone Digital Library, University of Waikato
57 * @version 2.3
58 */
59public class DeleteCollectionPrompt
60 extends ModalDialog {
61 /** The currently selected collection for deletion. */
62 private CollectionEntry collection = null;
63 /** The model behind the list. */
64 private DefaultListModel list_model = null;
65 /** A reference to ourself so any inner-classes can dispose of us. */
66 private DeleteCollectionPrompt prompt = null;
67 /** The close button, which exits the prompt without deleting anything. */
68 private JButton close_button = null;
69 /** The ok button which causes the selected collection to be deleted. */
70 private JButton ok_button = null;
71 /** The confirmation check box. */
72 private JCheckBox confirmation = null;
73 /** The label above details. */
74 private JLabel details_label = null;
75 /** The label above the list. */
76 private JLabel list_label = null;
77 /** The list of available collections. */
78 private JList list = null;
79 /** The text area used to display details about the collection selected. */
80 private JTextArea details = null;
81 /** A string array used to pass arguments to the phrase retrieval method. */
82 private String args[] = null;
83
84 private boolean current_coll_deleted = false;
85 /** The size of the delete prompt screen. */
86 public static final Dimension SIZE = new Dimension(500, 500);
87
88 /** Constructor.
89 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CloseButtonListener
90 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CollectionListListener
91 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.ConfirmationCheckBoxListener
92 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.OKButtonListener
93 */
94 public DeleteCollectionPrompt() {
95 super(Gatherer.g_man);
96 close_button = new JButton();
97 close_button.setMnemonic(KeyEvent.VK_C);
98 Dictionary.setBoth(close_button, "General.Close", "General.Close_Tooltip");
99 confirmation = new JCheckBox();
100 Dictionary.setText(confirmation, "DeleteCollectionPrompt.Confirm_Delete");
101 details = new JTextArea();
102 details.setEditable(false);
103 details.setFont(Gatherer.config.getFont("general.tooltip_font", false));
104 Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
105 details_label = new JLabel();
106 Dictionary.setText(details_label, "DeleteCollectionPrompt.Collection_Details");
107 list = new JList();
108 list_label = new JLabel();
109 Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List");
110 list_model = new DefaultListModel();
111 ok_button = new JButton();
112 ok_button.setMnemonic(KeyEvent.VK_D);
113 Dictionary.setBoth(ok_button, "DeleteCollectionPrompt.Delete", "DeleteCollectionPrompt.Delete_Tooltip");
114 prompt = this;
115 setModal(true);
116 setSize(SIZE);
117 Dictionary.setText(this, "DeleteCollectionPrompt.Title");
118
119 setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
120 close_button.addActionListener(new CloseButtonListener());
121 confirmation.addActionListener(new ConfirmationCheckBoxListener());
122 confirmation.setEnabled(false);
123 confirmation.setSelected(false);
124 list.addListSelectionListener(new CollectionListListener());
125 list.clearSelection();
126 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
127 list.setModel(list_model);
128 ok_button.addActionListener(new OKButtonListener());
129 ok_button.setEnabled(false);
130 scanForCollections();
131 }
132
133 /** Destructor. */
134 public void destroy() {
135 list_model.clear();
136 list_model = null;
137 close_button = null;
138 confirmation = null;
139 details = null;
140 details_label = null;
141 list = null;
142 ok_button = null;
143 prompt = null;
144 }
145
146 /** This method causes the modal prompt to be displayed.
147 * returns true if it has deleted the collection that is currently open */
148 public boolean display() {
149 // Central pane
150 JPanel list_pane = new JPanel(new BorderLayout());
151 list_pane.add(list_label, BorderLayout.NORTH);
152 list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
153 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
154
155 JPanel details_pane = new JPanel(new BorderLayout());
156 details_pane.add(details_label, BorderLayout.NORTH);
157 details_pane.add(new JScrollPane(details), BorderLayout.CENTER);
158 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
159
160 JPanel central_pane = new JPanel(new GridLayout(2, 1));
161 central_pane.add(list_pane);
162 central_pane.add(details_pane);
163 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
164
165 // Lower pane
166 JPanel confirmation_pane = new JPanel(new BorderLayout());
167 confirmation_pane.add(confirmation, BorderLayout.CENTER);
168 confirmation_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
169
170 JPanel button_pane = new JPanel(new GridLayout(1, 2));
171 button_pane.add(ok_button);
172 button_pane.add(close_button);
173 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
174
175 JPanel lower_pane = new JPanel(new BorderLayout());
176 lower_pane.add(confirmation_pane, BorderLayout.NORTH);
177 lower_pane.add(button_pane, BorderLayout.SOUTH);
178 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
179
180 // Final.
181 JPanel content_pane = (JPanel)this.getContentPane();
182 content_pane.setLayout(new BorderLayout());
183 content_pane.add(central_pane, BorderLayout.CENTER);
184 content_pane.add(lower_pane, BorderLayout.SOUTH);
185
186 // Center and display.
187 Dimension screen_size = Gatherer.config.screen_size;
188 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
189 this.setVisible(true); // blocks until the dialog is killed
190 return current_coll_deleted;
191
192 }
193
194 /** Shows a delete complete prompt.
195 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
196 * @see org.greenstone.gatherer.collection.Collection
197 */
198 public void resultPrompt(boolean success) {
199 args = new String[1];
200 args[0] = collection.getName();
201 if (success) {
202 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Successful_Delete", args),Dictionary.get("DeleteCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
203 }
204 else {
205 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Failed_Delete", args),Dictionary.get("DeleteCollectionPrompt.Failed_Title"),JOptionPane.WARNING_MESSAGE);
206 }
207 }
208
209 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
210 * @see org.greenstone.gatherer.Configuration
211 * @see org.greenstone.gatherer.Gatherer
212 * @see org.greenstone.gatherer.util.ArrayTools
213 * @see org.greenstone.gatherer.util.Utility
214 */
215 private void scanForCollections() {
216 // Start at the collect dir.
217 String collect_directory_name = Utility.getCollectionDir(Gatherer.config.gsdl_path);
218 File collect_directory = new File(collect_directory_name);
219 if(collect_directory.exists()) {
220 // Now for each child directory see if it contains a .col file and
221 // if so try to load it..
222 File collections[] = collect_directory.listFiles();
223 ArrayTools.sort(collections);
224 for(int i = 0; collections != null && i < collections.length; i++) {
225 if(!collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
226 File config_file = Utility.findConfigFile(collections[i]);
227 if (config_file != null) {
228 CollectionConfiguration config = new CollectionConfiguration(config_file);
229 if (config != null) {
230 CollectionEntry col = new CollectionEntry(collections[i].getName(), config);
231 list_model.addElement(col);
232 }
233 }
234 }
235 }
236 }
237 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
238 }
239
240 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
241 private class CloseButtonListener
242 implements ActionListener {
243 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
244 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
245 */
246 public void actionPerformed(ActionEvent event) {
247 // Done
248 prompt.dispose();
249 }
250 }
251
252 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
253 */
254 private class CollectionListListener
255 implements ListSelectionListener {
256 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
257 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
258 */
259 public void valueChanged(ListSelectionEvent event) {
260 ok_button.setEnabled(false);
261 confirmation.setSelected(false);
262 if(!list.isSelectionEmpty()) {
263 confirmation.setEnabled(true);
264 collection = (CollectionEntry) list.getSelectedValue();
265 args = new String[5];
266 args[0] = collection.getTitle();
267 args[1] = collection.getName();
268 args[2] = collection.getCreator();
269 args[3] = collection.getMaintainer();
270 args[4] = collection.getDescription();
271 Dictionary.setText(details, "DeleteCollectionPrompt.Details", args);
272 details.setCaretPosition(0);
273 }
274 else {
275 confirmation.setEnabled(false);
276 Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
277 }
278 }
279 }
280
281 /** A check box listener so we can tell if the user has confirmed the deletion */
282 private class ConfirmationCheckBoxListener
283 implements ActionListener {
284 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
285 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
286 */
287 public void actionPerformed(ActionEvent event) {
288 // OK button is only enabled if the confirmation check box is ticked
289 ok_button.setEnabled(confirmation.isSelected());
290 }
291 }
292
293 /** The OK button listener implementation. */
294 private class OKButtonListener
295 implements ActionListener {
296 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
297 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
298 * @see org.greenstone.gatherer.Configuration
299 * @see org.greenstone.gatherer.Gatherer
300 * @see org.greenstone.gatherer.util.Utility
301 */
302 public void actionPerformed(ActionEvent event) {
303 // Delete the selected collection.
304
305 // first of all we must release it from the local library
306 if(Gatherer.config.exec_file != null) {
307 ///ystem.err.println("Local Library Found!");
308 //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
309 Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
310 }
311
312 File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getName() + File.separator);
313 if(Utility.delete(delete_me)) {
314 if (Gatherer.c_man.getCollection() != null && collection.getName().equals(Gatherer.c_man.getCollection().getName())) {
315 current_coll_deleted = true;
316 }
317 list_model.removeElement(collection);
318
319 // Refresh the collects shown in the workspace tree
320 Gatherer.g_man.collection_pane.refreshWorkspaceTree(DragTree.LIBRARY_CONTENTS_CHANGED);
321
322 resultPrompt(true);
323 Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
324 confirmation.setEnabled(false);
325 confirmation.setSelected(false);
326 ok_button.setEnabled(false);
327 collection = null;
328 }
329 else {
330 resultPrompt(false);
331 }
332 }
333 }
334
335 private class CollectionEntry {
336
337 private String name = null;
338 private CollectionConfiguration config = null;
339
340 public CollectionEntry(String name, CollectionConfiguration config) {
341 this.name = name;
342 this.config = config;
343 }
344
345 public String getName() {
346 return name;
347 }
348
349 public String getTitle() {
350 return config.getName();
351 }
352
353 public String getCreator() {
354 return config.getCreator();
355 }
356
357 public String getDescription() {
358 return config.getDescription();
359 }
360
361 public String getMaintainer() {
362 return config.getMaintainer();
363 }
364
365 public String toString() {
366 return name + " - \"" + config.getName() + "\"";
367 }
368 }
369}
Note: See TracBrowser for help on using the repository browser.