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

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

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 13.0 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.LocalLibraryServer;
50import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
51import org.greenstone.gatherer.file.WorkspaceTree; // !!! Don't like this here
52import org.greenstone.gatherer.remote.RemoteGreenstoneServer;
53import org.greenstone.gatherer.util.ArrayTools;
54import org.greenstone.gatherer.util.StaticStrings;
55import org.greenstone.gatherer.util.Utility;
56
57/** 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.
58 * @author John Thompson, Greenstone Digital Library, University of Waikato
59 * @version 2.3
60 */
61public class DeleteCollectionPrompt
62 extends ModalDialog {
63 /** The currently selected collection for deletion. */
64 private BasicCollectionConfiguration collection = null;
65 /** The model behind the list. */
66 private DefaultListModel list_model = null;
67 /** A reference to ourself so any inner-classes can dispose of us. */
68 private DeleteCollectionPrompt prompt = null;
69 /** The close button, which exits the prompt without deleting anything. */
70 private JButton close_button = null;
71 /** The ok button which causes the selected collection to be deleted. */
72 private JButton ok_button = null;
73 /** The confirmation check box. */
74 private JCheckBox confirmation = null;
75 /** The label above details. */
76 private JLabel details_label = null;
77 /** The label above the list. */
78 private JLabel list_label = null;
79 /** The list of available collections. */
80 private JList list = null;
81 /** The text area used to display details about the collection selected. */
82 private JTextArea details = null;
83 /** A string array used to pass arguments to the phrase retrieval method. */
84 private String args[] = null;
85
86 private boolean current_coll_deleted = false;
87 /** The size of the delete prompt screen. */
88 public static final Dimension SIZE = new Dimension(500, 500);
89
90 /** Constructor.
91 */
92 public DeleteCollectionPrompt() {
93 super(Gatherer.g_man);
94 close_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
95
96 confirmation = new JCheckBox(Dictionary.get("DeleteCollectionPrompt.Confirm_Delete"));
97 details = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
98 details.setEditable(false);
99 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
100
101 list = new JList();
102 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
103
104 list_model = new DefaultListModel();
105 ok_button = new GLIButton(Dictionary.get("DeleteCollectionPrompt.Delete"), Dictionary.get("DeleteCollectionPrompt.Delete_Tooltip"));
106
107 prompt = this;
108 setModal(true);
109 setSize(SIZE);
110 setTitle(Dictionary.get("DeleteCollectionPrompt.Title"));
111
112 setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
113 close_button.addActionListener(new CloseButtonListener());
114 confirmation.addActionListener(new ConfirmationCheckBoxListener());
115 confirmation.setEnabled(false);
116 confirmation.setSelected(false);
117 list.addListSelectionListener(new CollectionListListener());
118 list.clearSelection();
119 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
120 list.setModel(list_model);
121 ok_button.addActionListener(new OKButtonListener());
122 ok_button.setEnabled(false);
123 scanForCollections();
124 }
125
126 /** Destructor. */
127 public void destroy() {
128 list_model.clear();
129 list_model = null;
130 close_button = null;
131 confirmation = null;
132 details = null;
133 details_label = null;
134 list = null;
135 ok_button = null;
136 prompt = null;
137 }
138
139 /** This method causes the modal prompt to be displayed.
140 * returns true if it has deleted the collection that is currently open */
141 public boolean display() {
142 // Central pane
143 JPanel list_pane = new JPanel(new BorderLayout());
144 list_pane.add(list_label, BorderLayout.NORTH);
145 list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
146 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
147
148 JPanel details_pane = new JPanel(new BorderLayout());
149 details_pane.add(details_label, BorderLayout.NORTH);
150 details_pane.add(new JScrollPane(details), BorderLayout.CENTER);
151 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
152
153 JPanel central_pane = new JPanel(new GridLayout(2, 1));
154 central_pane.add(list_pane);
155 central_pane.add(details_pane);
156 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
157
158 // Lower pane
159 JPanel confirmation_pane = new JPanel(new BorderLayout());
160 confirmation_pane.add(confirmation, BorderLayout.CENTER);
161 confirmation_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
162
163 JPanel button_pane = new JPanel(new GridLayout(1, 2));
164 button_pane.add(ok_button);
165 button_pane.add(close_button);
166 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
167
168 JPanel lower_pane = new JPanel(new BorderLayout());
169 lower_pane.add(confirmation_pane, BorderLayout.NORTH);
170 lower_pane.add(button_pane, BorderLayout.SOUTH);
171 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
172
173 // Final.
174 JPanel content_pane = (JPanel)this.getContentPane();
175 content_pane.setLayout(new BorderLayout());
176 content_pane.add(central_pane, BorderLayout.CENTER);
177 content_pane.add(lower_pane, BorderLayout.SOUTH);
178
179 // Center and display.
180 Dimension screen_size = Configuration.screen_size;
181 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
182 this.setVisible(true); // blocks until the dialog is killed
183 return current_coll_deleted;
184 }
185
186
187 /** Shows a delete complete prompt.
188 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
189 * @see org.greenstone.gatherer.collection.Collection
190 */
191 public void resultPrompt(boolean success) {
192 args = new String[1];
193 args[0] = collection.getName();
194 if (success) {
195 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Successful_Delete", args),Dictionary.get("DeleteCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
196 }
197 else {
198 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Failed_Delete", args),Dictionary.get("DeleteCollectionPrompt.Failed_Title"),JOptionPane.WARNING_MESSAGE);
199 }
200 }
201
202 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
203 * @see org.greenstone.gatherer.Configuration
204 * @see org.greenstone.gatherer.Gatherer
205 * @see org.greenstone.gatherer.util.ArrayTools
206 * @see org.greenstone.gatherer.util.Utility
207 */
208 private void scanForCollections() {
209 // Start at the collect dir.
210 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
211 if (collect_directory.exists()) {
212 // Now for each child directory see if it contains a .col file and
213 // if so try to load it..
214 File collections[] = collect_directory.listFiles();
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], Utility.CONFIG_FILE);
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 // Delete the selected collection.
292 // !! This should all go into CollectionManager !!
293
294 // First we must release it from the local library
295 if (LocalLibraryServer.isRunning() == true) {
296 LocalLibraryServer.releaseCollection(collection.getShortName());
297 }
298
299 if (Gatherer.isGsdlRemote) {
300 RemoteGreenstoneServer.deleteCollection(collection.getShortName());
301 }
302
303 if (Gatherer.c_man.deleteCollection(collection.getShortName())) {
304 // Refresh the collections shown in the workspace tree
305 Gatherer.g_man.refreshWorkspaceTree(WorkspaceTree.LIBRARY_CONTENTS_CHANGED);
306
307 if (Gatherer.c_man.getCollection() != null && collection.getShortName().equals(Gatherer.c_man.getCollection().getName())) {
308 current_coll_deleted = true;
309 }
310 list_model.removeElement(collection);
311
312 resultPrompt(true);
313 details.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
314 confirmation.setEnabled(false);
315 confirmation.setSelected(false);
316 ok_button.setEnabled(false);
317 collection = null;
318 }
319 else {
320 resultPrompt(false);
321 }
322 }
323 }
324}
Note: See TracBrowser for help on using the repository browser.