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