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 | */
|
---|
37 | package org.greenstone.gatherer.collection;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import javax.swing.event.*;
|
---|
44 | import org.greenstone.gatherer.Dictionary;
|
---|
45 | import org.greenstone.gatherer.Gatherer;
|
---|
46 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
|
---|
47 | import org.greenstone.gatherer.collection.Collection;
|
---|
48 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
49 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
50 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
51 | import org.greenstone.gatherer.gui.tree.DragTree;
|
---|
52 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
53 | import org.greenstone.gatherer.util.GSDLSiteConfig;
|
---|
54 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
55 | import 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 | */
|
---|
61 | public 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 | * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CloseButtonListener
|
---|
92 | * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.CollectionListListener
|
---|
93 | * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.ConfirmationCheckBoxListener
|
---|
94 | * @see org.greenstone.gatherer.collection.DeleteCollectionPrompt.OKButtonListener
|
---|
95 | */
|
---|
96 | public DeleteCollectionPrompt() {
|
---|
97 | super(Gatherer.g_man);
|
---|
98 | close_button = new GLIButton();
|
---|
99 | close_button.setMnemonic(KeyEvent.VK_C);
|
---|
100 | Dictionary.setBoth(close_button, "General.Close", "General.Close_Tooltip");
|
---|
101 | confirmation = new JCheckBox();
|
---|
102 | Dictionary.setText(confirmation, "DeleteCollectionPrompt.Confirm_Delete");
|
---|
103 | details = new JTextArea();
|
---|
104 | details.setEditable(false);
|
---|
105 | details.setFont(Gatherer.config.getFont("general.tooltip_font", false));
|
---|
106 | Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
|
---|
107 | details_label = new JLabel();
|
---|
108 | Dictionary.setText(details_label, "DeleteCollectionPrompt.Collection_Details");
|
---|
109 | list = new JList();
|
---|
110 | list_label = new JLabel();
|
---|
111 | Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List");
|
---|
112 | list_model = new DefaultListModel();
|
---|
113 | ok_button = new GLIButton();
|
---|
114 | ok_button.setMnemonic(KeyEvent.VK_D);
|
---|
115 | Dictionary.setBoth(ok_button, "DeleteCollectionPrompt.Delete", "DeleteCollectionPrompt.Delete_Tooltip");
|
---|
116 | prompt = this;
|
---|
117 | setModal(true);
|
---|
118 | setSize(SIZE);
|
---|
119 | Dictionary.setText(this, "DeleteCollectionPrompt.Title");
|
---|
120 |
|
---|
121 | setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
|
---|
122 | close_button.addActionListener(new CloseButtonListener());
|
---|
123 | confirmation.addActionListener(new ConfirmationCheckBoxListener());
|
---|
124 | confirmation.setEnabled(false);
|
---|
125 | confirmation.setSelected(false);
|
---|
126 | list.addListSelectionListener(new CollectionListListener());
|
---|
127 | list.clearSelection();
|
---|
128 | list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
129 | list.setModel(list_model);
|
---|
130 | ok_button.addActionListener(new OKButtonListener());
|
---|
131 | ok_button.setEnabled(false);
|
---|
132 | scanForCollections();
|
---|
133 | }
|
---|
134 |
|
---|
135 | /** Destructor. */
|
---|
136 | public void destroy() {
|
---|
137 | list_model.clear();
|
---|
138 | list_model = null;
|
---|
139 | close_button = null;
|
---|
140 | confirmation = null;
|
---|
141 | details = null;
|
---|
142 | details_label = null;
|
---|
143 | list = null;
|
---|
144 | ok_button = null;
|
---|
145 | prompt = null;
|
---|
146 | }
|
---|
147 |
|
---|
148 | /** This method causes the modal prompt to be displayed.
|
---|
149 | * returns true if it has deleted the collection that is currently open */
|
---|
150 | public boolean display() {
|
---|
151 | // Central pane
|
---|
152 | JPanel list_pane = new JPanel(new BorderLayout());
|
---|
153 | list_pane.add(list_label, BorderLayout.NORTH);
|
---|
154 | list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
|
---|
155 | list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
|
---|
156 |
|
---|
157 | JPanel details_pane = new JPanel(new BorderLayout());
|
---|
158 | details_pane.add(details_label, BorderLayout.NORTH);
|
---|
159 | details_pane.add(new JScrollPane(details), BorderLayout.CENTER);
|
---|
160 | details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
161 |
|
---|
162 | JPanel central_pane = new JPanel(new GridLayout(2, 1));
|
---|
163 | central_pane.add(list_pane);
|
---|
164 | central_pane.add(details_pane);
|
---|
165 | central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
166 |
|
---|
167 | // Lower pane
|
---|
168 | JPanel confirmation_pane = new JPanel(new BorderLayout());
|
---|
169 | confirmation_pane.add(confirmation, BorderLayout.CENTER);
|
---|
170 | confirmation_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
171 |
|
---|
172 | JPanel button_pane = new JPanel(new GridLayout(1, 2));
|
---|
173 | button_pane.add(ok_button);
|
---|
174 | button_pane.add(close_button);
|
---|
175 | button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
176 |
|
---|
177 | JPanel lower_pane = new JPanel(new BorderLayout());
|
---|
178 | lower_pane.add(confirmation_pane, BorderLayout.NORTH);
|
---|
179 | lower_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
180 | lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
|
---|
181 |
|
---|
182 | // Final.
|
---|
183 | JPanel content_pane = (JPanel)this.getContentPane();
|
---|
184 | content_pane.setLayout(new BorderLayout());
|
---|
185 | content_pane.add(central_pane, BorderLayout.CENTER);
|
---|
186 | content_pane.add(lower_pane, BorderLayout.SOUTH);
|
---|
187 |
|
---|
188 | // Center and display.
|
---|
189 | Dimension screen_size = Gatherer.config.screen_size;
|
---|
190 | this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
191 | this.setVisible(true); // blocks until the dialog is killed
|
---|
192 | return current_coll_deleted;
|
---|
193 |
|
---|
194 | }
|
---|
195 |
|
---|
196 | /** Shows a delete complete prompt.
|
---|
197 | * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
|
---|
198 | * @see org.greenstone.gatherer.collection.Collection
|
---|
199 | */
|
---|
200 | public void resultPrompt(boolean success) {
|
---|
201 | args = new String[1];
|
---|
202 | args[0] = collection.getName();
|
---|
203 | if (success) {
|
---|
204 | JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Successful_Delete", args),Dictionary.get("DeleteCollectionPrompt.Successful_Title"),JOptionPane.INFORMATION_MESSAGE);
|
---|
205 | }
|
---|
206 | else {
|
---|
207 | JOptionPane.showMessageDialog(prompt,Dictionary.get("DeleteCollectionPrompt.Failed_Delete", args),Dictionary.get("DeleteCollectionPrompt.Failed_Title"),JOptionPane.WARNING_MESSAGE);
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
|
---|
212 | * @see org.greenstone.gatherer.Configuration
|
---|
213 | * @see org.greenstone.gatherer.Gatherer
|
---|
214 | * @see org.greenstone.gatherer.util.ArrayTools
|
---|
215 | * @see org.greenstone.gatherer.util.Utility
|
---|
216 | */
|
---|
217 | private void scanForCollections() {
|
---|
218 | // Start at the collect dir.
|
---|
219 | String collect_directory_name = Utility.getCollectDir(Gatherer.config.gsdl_path);
|
---|
220 | File collect_directory = new File(collect_directory_name);
|
---|
221 | if(collect_directory.exists()) {
|
---|
222 | // Now for each child directory see if it contains a .col file and
|
---|
223 | // if so try to load it..
|
---|
224 | File collections[] = collect_directory.listFiles();
|
---|
225 | ArrayTools.sort(collections);
|
---|
226 | for(int i = 0; collections != null && i < collections.length; i++) {
|
---|
227 | if(!collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
|
---|
228 | File config_file = Utility.findConfigFile(collections[i]);
|
---|
229 | if (config_file != null) {
|
---|
230 | BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
|
---|
231 | if(!config.getName().equals(StaticStrings.EMPTY_STR)) {
|
---|
232 | list_model.addElement(config);
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 | }
|
---|
237 | }
|
---|
238 | // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
|
---|
239 | }
|
---|
240 |
|
---|
241 | /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
|
---|
242 | private class CloseButtonListener
|
---|
243 | implements ActionListener {
|
---|
244 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
245 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
246 | */
|
---|
247 | public void actionPerformed(ActionEvent event) {
|
---|
248 | // Done
|
---|
249 | prompt.dispose();
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 | /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
|
---|
254 | */
|
---|
255 | private class CollectionListListener
|
---|
256 | implements ListSelectionListener {
|
---|
257 | /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
|
---|
258 | * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
|
---|
259 | */
|
---|
260 | public void valueChanged(ListSelectionEvent event) {
|
---|
261 | ok_button.setEnabled(false);
|
---|
262 | confirmation.setSelected(false);
|
---|
263 | if(!list.isSelectionEmpty()) {
|
---|
264 | confirmation.setEnabled(true);
|
---|
265 | collection = (BasicCollectionConfiguration) list.getSelectedValue();
|
---|
266 | args = new String[5];
|
---|
267 | args[0] = collection.getName();
|
---|
268 | args[1] = collection.getShortName();
|
---|
269 | args[2] = collection.getCreator();
|
---|
270 | args[3] = collection.getMaintainer();
|
---|
271 | args[4] = collection.getDescription();
|
---|
272 | Dictionary.setText(details, "DeleteCollectionPrompt.Details", args);
|
---|
273 | details.setCaretPosition(0);
|
---|
274 | }
|
---|
275 | else {
|
---|
276 | confirmation.setEnabled(false);
|
---|
277 | Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
|
---|
278 | }
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | /** A check box listener so we can tell if the user has confirmed the deletion */
|
---|
283 | private class ConfirmationCheckBoxListener
|
---|
284 | implements ActionListener {
|
---|
285 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
286 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
287 | */
|
---|
288 | public void actionPerformed(ActionEvent event) {
|
---|
289 | // OK button is only enabled if the confirmation check box is ticked
|
---|
290 | ok_button.setEnabled(confirmation.isSelected());
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | /** The OK button listener implementation. */
|
---|
295 | private class OKButtonListener
|
---|
296 | implements ActionListener {
|
---|
297 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
298 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
299 | * @see org.greenstone.gatherer.Configuration
|
---|
300 | * @see org.greenstone.gatherer.Gatherer
|
---|
301 | * @see org.greenstone.gatherer.util.Utility
|
---|
302 | */
|
---|
303 | public void actionPerformed(ActionEvent event) {
|
---|
304 | // Delete the selected collection.
|
---|
305 |
|
---|
306 | // first of all we must release it from the local library
|
---|
307 | if(Gatherer.config.exec_file != null) {
|
---|
308 | ///ystem.err.println("Local Library Found!");
|
---|
309 | //Gatherer.g_man.preview_pane.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
|
---|
310 | Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getShortName());
|
---|
311 | }
|
---|
312 |
|
---|
313 | File delete_me = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path, collection.getShortName()));
|
---|
314 | if(Utility.delete(delete_me)) {
|
---|
315 | if (Gatherer.c_man.getCollection() != null && collection.getShortName().equals(Gatherer.c_man.getCollection().getName())) {
|
---|
316 | current_coll_deleted = true;
|
---|
317 | }
|
---|
318 | list_model.removeElement(collection);
|
---|
319 |
|
---|
320 | // Refresh the collects shown in the workspace tree
|
---|
321 | Gatherer.g_man.gather_pane.refreshWorkspaceTree(DragTree.LIBRARY_CONTENTS_CHANGED);
|
---|
322 |
|
---|
323 | resultPrompt(true);
|
---|
324 | Dictionary.setText(details, "DeleteCollectionPrompt.No_Collection");
|
---|
325 | confirmation.setEnabled(false);
|
---|
326 | confirmation.setSelected(false);
|
---|
327 | ok_button.setEnabled(false);
|
---|
328 | collection = null;
|
---|
329 | }
|
---|
330 | else {
|
---|
331 | resultPrompt(false);
|
---|
332 | }
|
---|
333 | }
|
---|
334 | }
|
---|
335 | }
|
---|