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

Last change on this file since 6224 was 6146, checked in by jmt12, 21 years ago

Changed how a collection name appears. It now displays the collection title, followed by the shorter filename in curved brackets. Accomplished this by removing crazy CollectionEntry class

  • Property svn:keywords set to Author Date Id Revision
File size: 13.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: 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.BasicCollectionConfiguration;
47import org.greenstone.gatherer.collection.Collection;
48import org.greenstone.gatherer.gui.ModalDialog;
49import org.greenstone.gatherer.gui.SimpleMenuBar;
50import org.greenstone.gatherer.gui.tree.DragTree;
51import org.greenstone.gatherer.util.ArrayTools;
52import org.greenstone.gatherer.util.GSDLSiteConfig;
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 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CloseButtonListener
91 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CollectionListListener
92 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.ConfirmationCheckBoxListener
93 * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.OKButtonListener
94 */
95 public DeleteCollectionPrompt() {
96 super(Gatherer.g_man);
97 close_button = new JButton();
98 close_button.setMnemonic(KeyEvent.VK_C);
99 Dictionary.setBoth(close_button, "General.Close", "General.Close_Tooltip");
100 confirmation = new JCheckBox();
101 Dictionary.setText(confirmation, "DeleteCollectionPrompt.Confirm_Delete");
102 details = new JTextArea();
103 details.setEditable(false);
104 details.setFont(Gatherer.config.getFont("general.tooltip_font", false));
105 Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
106 details_label = new JLabel();
107 Dictionary.setText(details_label, "DeleteCollectionPrompt.Collection_Details");
108 list = new JList();
109 list_label = new JLabel();
110 Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List");
111 list_model = new DefaultListModel();
112 ok_button = new JButton();
113 ok_button.setMnemonic(KeyEvent.VK_D);
114 Dictionary.setBoth(ok_button, "DeleteCollectionPrompt.Delete", "DeleteCollectionPrompt.Delete_Tooltip");
115 prompt = this;
116 setModal(true);
117 setSize(SIZE);
118 Dictionary.setText(this, "DeleteCollectionPrompt.Title");
119
120 setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
121 close_button.addActionListener(new CloseButtonListener());
122 confirmation.addActionListener(new ConfirmationCheckBoxListener());
123 confirmation.setEnabled(false);
124 confirmation.setSelected(false);
125 list.addListSelectionListener(new CollectionListListener());
126 list.clearSelection();
127 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
128 list.setModel(list_model);
129 ok_button.addActionListener(new OKButtonListener());
130 ok_button.setEnabled(false);
131 scanForCollections();
132 }
133
134 /** Destructor. */
135 public void destroy() {
136 list_model.clear();
137 list_model = null;
138 close_button = null;
139 confirmation = null;
140 details = null;
141 details_label = null;
142 list = null;
143 ok_button = null;
144 prompt = null;
145 }
146
147 /** This method causes the modal prompt to be displayed.
148 * returns true if it has deleted the collection that is currently open */
149 public boolean display() {
150 // Central pane
151 JPanel list_pane = new JPanel(new BorderLayout());
152 list_pane.add(list_label, BorderLayout.NORTH);
153 list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
154 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
155
156 JPanel details_pane = new JPanel(new BorderLayout());
157 details_pane.add(details_label, BorderLayout.NORTH);
158 details_pane.add(new JScrollPane(details), BorderLayout.CENTER);
159 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
160
161 JPanel central_pane = new JPanel(new GridLayout(2, 1));
162 central_pane.add(list_pane);
163 central_pane.add(details_pane);
164 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
165
166 // Lower pane
167 JPanel confirmation_pane = new JPanel(new BorderLayout());
168 confirmation_pane.add(confirmation, BorderLayout.CENTER);
169 confirmation_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
170
171 JPanel button_pane = new JPanel(new GridLayout(1, 2));
172 button_pane.add(ok_button);
173 button_pane.add(close_button);
174 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
175
176 JPanel lower_pane = new JPanel(new BorderLayout());
177 lower_pane.add(confirmation_pane, BorderLayout.NORTH);
178 lower_pane.add(button_pane, BorderLayout.SOUTH);
179 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
180
181 // Final.
182 JPanel content_pane = (JPanel)this.getContentPane();
183 content_pane.setLayout(new BorderLayout());
184 content_pane.add(central_pane, BorderLayout.CENTER);
185 content_pane.add(lower_pane, BorderLayout.SOUTH);
186
187 // Center and display.
188 Dimension screen_size = Gatherer.config.screen_size;
189 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
190 this.setVisible(true); // blocks until the dialog is killed
191 return current_coll_deleted;
192
193 }
194
195 /** Shows a delete complete prompt.
196 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
197 * @see org.greenstone.gatherer.collection.Collection
198 */
199 public void resultPrompt(boolean success) {
200 args = new String[1];
201 args[0] = collection.getName();
202 if (success) {
203 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Successful_Delete", args),Dictionary.get("DeleteCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
204 }
205 else {
206 JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Failed_Delete", args),Dictionary.get("DeleteCollectionPrompt.Failed_Title"),JOptionPane.WARNING_MESSAGE);
207 }
208 }
209
210 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
211 * @see org.greenstone.gatherer.Configuration
212 * @see org.greenstone.gatherer.Gatherer
213 * @see org.greenstone.gatherer.util.ArrayTools
214 * @see org.greenstone.gatherer.util.Utility
215 */
216 private void scanForCollections() {
217 // Start at the collect dir.
218 String collect_directory_name = Utility.getCollectionDir(Gatherer.config.gsdl_path);
219 File collect_directory = new File(collect_directory_name);
220 if(collect_directory.exists()) {
221 // Now for each child directory see if it contains a .col file and
222 // if so try to load it..
223 File collections[] = collect_directory.listFiles();
224 ArrayTools.sort(collections);
225 for(int i = 0; collections != null && i < collections.length; i++) {
226 if(!collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
227 File config_file = Utility.findConfigFile(collections[i]);
228 if (config_file != null) {
229 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
230 if(!config.getName().equals(StaticStrings.EMPTY_STR)) {
231 list_model.addElement(config);
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 = (BasicCollectionConfiguration) list.getSelectedValue();
265 args = new String[5];
266 args[0] = collection.getName();
267 args[1] = collection.getShortName();
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.getShortName());
310 }
311
312 File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path) + collection.getShortName() + File.separator);
313 if(Utility.delete(delete_me)) {
314 if (Gatherer.c_man.getCollection() != null && collection.getShortName().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}
Note: See TracBrowser for help on using the repository browser.