source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/DeleteCollectionPrompt.java@ 18297

Last change on this file since 18297 was 18297, checked in by kjdon, 15 years ago

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

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