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

Last change on this file since 13595 was 13595, checked in by mdewsnip, 17 years ago

Removed some more occurrences of Gatherer.c_man.

  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 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 ArrayTools.sort(collections);
215 for(int i = 0; collections != null && i < collections.length; i++) {
216 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
217 File config_file = new File(collections[i], Utility.CONFIG_FILE);
218 if (config_file.exists()) {
219 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
220 list_model.addElement(config);
221 config = null;
222 }
223 }
224 }
225 }
226 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
227 }
228
229 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
230 private class CloseButtonListener
231 implements ActionListener {
232 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
233 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
234 */
235 public void actionPerformed(ActionEvent event) {
236 // Done
237 prompt.dispose();
238 }
239 }
240
241 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
242 */
243 private class CollectionListListener
244 implements ListSelectionListener {
245 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
246 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
247 */
248 public void valueChanged(ListSelectionEvent event) {
249 ok_button.setEnabled(false);
250 confirmation.setSelected(false);
251 if(!list.isSelectionEmpty()) {
252 confirmation.setEnabled(true);
253 collection = (BasicCollectionConfiguration) list.getSelectedValue();
254 args = new String[3];
255 args[0] = collection.getCreator();
256 args[1] = collection.getMaintainer();
257 args[2] = collection.getDescription();
258 details.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
259 details.setCaretPosition(0);
260 }
261 else {
262 confirmation.setEnabled(false);
263 details.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
264 }
265 }
266 }
267
268 /** A check box listener so we can tell if the user has confirmed the deletion */
269 private class ConfirmationCheckBoxListener
270 implements ActionListener {
271 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
272 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
273 */
274 public void actionPerformed(ActionEvent event) {
275 // OK button is only enabled if the confirmation check box is ticked
276 ok_button.setEnabled(confirmation.isSelected());
277 }
278 }
279
280 /** The OK button listener implementation. */
281 private class OKButtonListener
282 implements ActionListener {
283 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
284 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
285 * @see org.greenstone.gatherer.Configuration
286 * @see org.greenstone.gatherer.Gatherer
287 * @see org.greenstone.gatherer.util.Utility
288 */
289 public void actionPerformed(ActionEvent event)
290 {
291 // Delete the selected collection.
292 if (Gatherer.c_man.deleteCollection(collection.getShortName())) {
293 // Refresh the collections shown in the workspace tree
294 Gatherer.g_man.refreshWorkspaceTree(WorkspaceTree.LIBRARY_CONTENTS_CHANGED);
295
296 if (collection.getShortName().equals(CollectionManager.getLoadedCollectionName())) {
297 current_coll_deleted = true;
298 }
299 list_model.removeElement(collection);
300
301 resultPrompt(true);
302 details.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
303 confirmation.setEnabled(false);
304 confirmation.setSelected(false);
305 ok_button.setEnabled(false);
306 collection = null;
307 }
308 else {
309 resultPrompt(false);
310 }
311 }
312 }
313}
Note: See TracBrowser for help on using the repository browser.