source: trunk/gli/src/org/greenstone/gatherer/gui/DeleteCollectionPrompt.java@ 14045

Last change on this file since 14045 was 14045, checked in by xiao, 17 years ago

Changes made to look for collectionConfig.xml in gs3 mode and collect.cfg in gs2 mode, rather than presumably only for the file collect.cfg.

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