source: main/trunk/gli/src/org/greenstone/gatherer/gui/WriteCDImagePrompt.java@ 22691

Last change on this file since 22691 was 22410, checked in by ak19, 14 years ago

Getting collectgroup to work for a remote Greenstone server. Need to update gliserver.pl still to work with the collectgroup changes. 1. GLI side changes: no longer does the collectdir parameter to import and build include the colgroup at the end, it is now back to being everything upto the GS collect dir. Instead, the loaded collection is colgroup/subcolname. 2. Changed CollectionManager.getLoadedCollectionName() to return (colgroup/)subcolname instead of the subcolname excluding groupname. 3. This required changes in other classes, including replacing unnecessary explicit calls to getLoadedGroupQualifiedCollectionName(). 4. Added another variant: getLoadedCollectionName(boolean). If the parameter is true, it will put a url style slash between colgroup and subcolname, otherwise use the OS dependent FileSeparator. 5. Changes to RemoteGreenstoneServer to pass the group/subcol as the collectionname to gliserver.pl, with a vertical bar separator. 6. Minor changes like: WorkspaceTreeNode now knows not to load a collection group if it's already in the loaded collection (previously handed only sub collection name), removed old debugging statements and unused import statements.

  • Property svn:keywords set to Author Date Id Revision
File size: 26.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.util.ArrayList;
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.greenstone.LocalGreenstone;
52import org.greenstone.gatherer.shell.GShell;
53import org.greenstone.gatherer.shell.GShellEvent;
54import org.greenstone.gatherer.shell.GShellListener;
55import org.greenstone.gatherer.util.ArrayTools;
56import org.greenstone.gatherer.util.CheckList;
57import org.greenstone.gatherer.util.CheckListEntry;
58import org.greenstone.gatherer.util.StaticStrings;
59import org.greenstone.gatherer.util.Utility;
60
61/** This class provides the functionality to write a CD-ROM/DVD image of current collections from the GSDLHOME/collect/ directory to CDROM. 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.
62 Copied from DeleteCollectionPrompt
63 * @author John Thompson, Greenstone Digital Library, University of Waikato
64 * @version 2.3
65 */
66public class WriteCDImagePrompt
67 extends ModalDialog
68 implements GShellListener {
69
70 private OKButtonListener ok_button_listener;
71 private ArrayList all_collections = null;
72 private ArrayList selected_collections = null;
73 /** The list of collections to include in exported cd-rom/dvd image */
74 private CheckList list = null;
75 /** The currently selected collection for deletion. */
76 private BasicCollectionConfiguration collection = null;
77 /** A reference to ourself so any inner-classes can dispose of us. */
78 private WriteCDImagePrompt prompt = null;
79 /** The close button, which exits the prompt without deleting anything. */
80 private JButton cancel_button = null;
81 /** The ok button which causes the selected collection to be deleted. */
82 private JButton ok_button = null;
83 /** The label above details. */
84 private JLabel details_label = null;
85 /** The label above the list. */
86 private JLabel list_label = null;
87 /** The text area used to display details about the collection selected. */
88 private JTextArea details_textarea = null;
89 /** The text area used to display instructions for the cd-rom/dvd export */
90 private JTextArea instructions_textarea;
91
92 /** The radio button for switching on the noinstall option */
93 private JRadioButton noinstall_button = null;
94 private JRadioButton install_button = null;
95 private JTextField title_field = null;
96 private JTextField estimated_size_field = null;
97 private JLabel title_label = null;
98 private JLabel estimated_size_label = null;
99 /** A string array used to pass arguments to the exportcol.pl script */
100 private String args[] = null;
101 private String cd_title = null;
102 /** whether the exporting was successful or not */
103 private boolean successful = false;
104 /** whether we are trying to export or not */
105 private boolean exporting = false;
106 /** the error message if any */
107 private StringBuffer error_message = null;
108 /** This is the size of the exported stuff on its own without collections. */
109 private long total_exported_size = 14000000;
110 /** The size of the export prompt screen. */
111 public static final Dimension SIZE = new Dimension(500, 500);
112
113 /** Constructor.
114 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.CancelButtonListener
115 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.CollectionListListener
116 * @see org.greenstone.gatherer.collection.WriteCDImagePrompt.OKButtonListener
117 */
118 public WriteCDImagePrompt() {
119 super(Gatherer.g_man, true);
120 this.setComponentOrientation(Dictionary.getOrientation());
121 cancel_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
122
123 details_textarea = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
124 details_textarea.setComponentOrientation(Dictionary.getOrientation());
125 details_textarea.setEditable(false);
126
127 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
128 details_label.setComponentOrientation(Dictionary.getOrientation());
129
130 instructions_textarea = new JTextArea(Dictionary.get("WriteCDImagePrompt.Instructions"));
131 instructions_textarea.setComponentOrientation(Dictionary.getOrientation());
132 instructions_textarea.setCaretPosition(0);
133 instructions_textarea.setEditable(false);
134 instructions_textarea.setLineWrap(true);
135 instructions_textarea.setRows(4);
136 instructions_textarea.setWrapStyleWord(true);
137
138 all_collections = new ArrayList();
139 list = new CheckList(true);
140 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
141 list_label.setComponentOrientation(Dictionary.getOrientation());
142
143 ok_button = new GLIButton(Dictionary.get("WriteCDImagePrompt.Export"), Dictionary.get("WriteCDImagePrompt.Export_Tooltip"));
144
145 title_field = new JTextField();
146 title_field.setComponentOrientation(Dictionary.getOrientation());
147 // Dictionary.setTooltip(title_field, "WriteCDImagePrompt.CD_Name_Tooltip");
148 title_label = new JLabel(Dictionary.get("WriteCDImagePrompt.CD_Name"));
149 title_label.setComponentOrientation(Dictionary.getOrientation());
150
151 estimated_size_field = new JTextField();
152 estimated_size_field.setComponentOrientation(Dictionary.getOrientation());
153 estimated_size_field.setEditable(false);
154
155 // work out the size of the images directory - could be large if they
156 // have the classic interface pack installed
157 total_exported_size += getFileSize(new File(LocalGreenstone.getDirectoryPath()+File.separator+"images"));
158 estimated_size_field.setText(Utility.formatFileLength(total_exported_size));
159 estimated_size_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
160 estimated_size_label = new JLabel(Dictionary.get("WriteCDImagePrompt.Size_Label"));
161 estimated_size_label.setComponentOrientation(Dictionary.getOrientation());
162
163 scanForCollections();
164 list.setListData(all_collections);
165
166 prompt = this;
167 setSize(SIZE);
168 setTitle(Dictionary.get("WriteCDImagePrompt.Export"));
169
170 setJMenuBar(new SimpleMenuBar("exportingcollections"));
171 cancel_button.addActionListener(new CancelButtonListener());
172 list.addListSelectionListener(new CollectionListListener());
173 list.clearSelection();
174 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
175 ok_button_listener = new OKButtonListener();
176 ok_button.addActionListener(ok_button_listener);
177 ok_button.setEnabled(false);
178 //title.getDocument().addDocumentListener(new DocumentListener());
179
180 noinstall_button = new JRadioButton(Dictionary.get("WriteCDImagePrompt.NoInstall"));
181 noinstall_button.setToolTipText(Dictionary.get("WriteCDImagePrompt.NoInstall_Tooltip"));
182 noinstall_button.setComponentOrientation(Dictionary.getOrientation());
183
184 install_button = new JRadioButton(Dictionary.get("WriteCDImagePrompt.Install"));
185 install_button.setToolTipText(Dictionary.get("WriteCDImagePrompt.Install_Tooltip"));
186 install_button.setComponentOrientation(Dictionary.getOrientation());
187
188 }
189
190 /** Destructor. */
191 public void destroy() {
192 all_collections.clear();
193 all_collections = null;
194 cancel_button = null;
195 details_textarea = null;
196 details_label = null;
197 list = null;
198 ok_button = null;
199 prompt = null;
200 if (selected_collections!=null) {
201 selected_collections.clear();
202 selected_collections = null;
203 }
204 title_field = null;
205 title_label = null;
206 }
207
208 /** This method causes the modal prompt to be displayed.
209 * returns true if it has exported the collections that are currently selected */
210 public boolean display() {
211
212 JScrollPane scrol_tmp;
213 // Radio buttons
214 ButtonGroup radio_group = new ButtonGroup();
215 radio_group.add(install_button);
216 install_button.setSelected(true);
217 radio_group.add(noinstall_button);
218
219 // Top pane
220 JPanel instructions_pane = new JPanel(new BorderLayout());
221 instructions_pane.setComponentOrientation(Dictionary.getOrientation());
222 instructions_pane.setBorder(BorderFactory.createEmptyBorder(5,5,0,5));
223 scrol_tmp = new JScrollPane(instructions_textarea);
224 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
225 instructions_pane.add(scrol_tmp, BorderLayout.CENTER);
226
227 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
228
229 JPanel title_pane = new JPanel(new BorderLayout());
230 title_pane.setComponentOrientation(Dictionary.getOrientation());
231 title_pane.add(title_label, BorderLayout.LINE_START);
232 title_pane.add(title_field, BorderLayout.CENTER);
233 title_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
234
235 JPanel radio_pane = new JPanel(new GridLayout(2,1));
236 radio_pane.setComponentOrientation(Dictionary.getOrientation());
237 install_button.setBackground(Configuration.getColor("coloring.collection_heading_background", true));
238 noinstall_button.setBackground(Configuration.getColor("coloring.collection_heading_background", true));
239 radio_pane.add(install_button);
240 radio_pane.add(noinstall_button);
241
242 JPanel options_pane = new JPanel(new BorderLayout());
243 options_pane.setComponentOrientation(Dictionary.getOrientation());
244 options_pane.add(title_pane, BorderLayout.NORTH);
245 options_pane.add(radio_pane, BorderLayout.CENTER);
246 instructions_pane.add(options_pane, BorderLayout.SOUTH);
247
248 // Central pane
249 JPanel list_pane = new JPanel(new BorderLayout());
250 list_pane.setComponentOrientation(Dictionary.getOrientation());
251 list_pane.add(list_label, BorderLayout.NORTH);
252 scrol_tmp =new JScrollPane(list);
253 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
254 list_pane.add(scrol_tmp, BorderLayout.CENTER);
255 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
256
257 JPanel details_pane = new JPanel(new BorderLayout());
258 details_pane.add(details_label, BorderLayout.NORTH);
259 scrol_tmp =new JScrollPane(details_textarea);
260 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
261 details_pane.add(scrol_tmp, BorderLayout.CENTER);
262 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
263
264 JPanel central_pane = new JPanel(new GridLayout(2, 1));
265 central_pane.setComponentOrientation(Dictionary.getOrientation());
266 central_pane.add(list_pane);
267 central_pane.add(details_pane);
268 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
269
270 // Lower pane
271 JPanel estimated_size_pane = new JPanel(new BorderLayout());
272 estimated_size_pane.setComponentOrientation(Dictionary.getOrientation());
273 estimated_size_pane.add(estimated_size_label, BorderLayout.LINE_START);
274 estimated_size_pane.add(estimated_size_field, BorderLayout.CENTER);
275 estimated_size_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
276
277 JPanel button_pane = new JPanel(new GridLayout(1, 2));
278 button_pane.setComponentOrientation(Dictionary.getOrientation());
279 button_pane.add(ok_button);
280 button_pane.add(cancel_button);
281 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
282
283 JPanel lower_pane = new JPanel(new BorderLayout());
284 lower_pane.setComponentOrientation(Dictionary.getOrientation());
285 lower_pane.add(estimated_size_pane, BorderLayout.NORTH);
286 lower_pane.add(button_pane, BorderLayout.SOUTH);
287 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
288
289 // Final.
290 JPanel content_pane = (JPanel)this.getContentPane();
291 content_pane.setComponentOrientation(Dictionary.getOrientation());
292 content_pane.setLayout(new BorderLayout());
293 content_pane.add(instructions_pane, BorderLayout.NORTH);
294 content_pane.add(central_pane, BorderLayout.CENTER);
295 content_pane.add(lower_pane, BorderLayout.SOUTH);
296
297 // Center and display.
298 Dimension screen_size = Configuration.screen_size;
299 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
300 this.setVisible(true); // blocks until the dialog is killed
301 return true;
302
303 }
304
305
306 private long getFileSize(File file)
307 {
308 long file_size = 0;
309
310 // Directory case
311 if (file.isDirectory()) {
312 File files[] = file.listFiles();
313 for (int i = 0; i < files.length; i++) {
314 file_size += getFileSize(files[i]);
315 }
316 }
317 // File case
318 else {
319 file_size = file.length();
320 }
321
322 return file_size;
323 }
324
325 /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
326 * @see org.greenstone.gatherer.Configuration
327 * @see org.greenstone.gatherer.Gatherer
328 * @see org.greenstone.gatherer.collection.Collection
329 * @see org.greenstone.gatherer.gui.BuildOptions
330 * @see org.greenstone.gatherer.shell.GShell
331 * @see org.greenstone.gatherer.shell.GShellListener
332 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
333 * @see org.greenstone.gatherer.util.Utility
334 */
335 public void writeCDImageCollections()
336 {
337 DebugStream.println("WriteCDImagePrompt.writeCDImageCollections()");
338
339 int num_collections = selected_collections.size();
340 if (num_collections == 0) return;
341 cd_title = title_field.getText();
342 cd_title = cd_title.trim();
343 cd_title = cd_title.replaceAll("\"","");
344
345 // Generate the exportcol.pl command
346 ArrayList command_parts_list = new ArrayList();
347 if (!Gatherer.isGsdlRemote) {
348 command_parts_list.add(Configuration.perl_path);
349 command_parts_list.add("-S");
350 }
351 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "exportcol.pl");
352
353 command_parts_list.add("-gli");
354 command_parts_list.add("-language");
355 command_parts_list.add(Configuration.getLanguage());
356
357 if (cd_title.equals("")) {
358 command_parts_list.add("-cdname");
359 command_parts_list.add("Greenstone Collections");
360
361 command_parts_list.add("-cddir");
362 command_parts_list.add("exported_collections");
363 }
364 else {
365 command_parts_list.add("-cdname");
366 command_parts_list.add(cd_title);
367
368 String cd_dir = "exported_"+cd_title.replaceAll("\\s","");
369 command_parts_list.add("-cddir");
370 command_parts_list.add(cd_dir);
371 }
372
373 if (noinstall_button.isSelected()) {
374 command_parts_list.add("-noinstall");
375 }
376
377 for (int i = 0; i < num_collections; i++) {
378 command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
379 }
380
381 DebugStream.print("export command = ");
382 for (int i = 0; i < command_parts_list.size(); i++) {
383 DebugStream.print(command_parts_list.get(i) + " ");
384 }
385 DebugStream.println("");
386 // Run the exportcol.pl command
387 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
388 GShell process = new GShell(command_parts, GShell.CDIMAGE, 3, this, null, GShell.GSHELL_CDIMAGE);
389 process.start();
390 //process.run();
391 DebugStream.println("WriteCDImagePrompt.writeCDImageCollections().return");
392
393 }
394
395 /** Shows an export complete prompt.
396 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
397 * @see org.greenstone.gatherer.collection.Collection
398 */
399 public void resultPrompt(boolean success, String extra) {
400 args = new String[2];
401 StringBuffer coll_names = new StringBuffer();
402 for (int i=0; i<selected_collections.size();i++) {
403 if (i>0) {
404 coll_names.append(", ");
405 }
406 BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
407 coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
408 complete_collection = null;
409 }
410
411 args[0] = coll_names.toString();
412 args[1] = LocalGreenstone.getTmpDirectoryPath();
413 if(cd_title.equals("")) {
414 args[1] += "exported_collections";
415 } else {
416 args[1] += "exported_"+cd_title.replaceAll("\\s","");
417 }
418 String title;
419 String label;
420 if (success) {
421 title = Dictionary.get("WriteCDImagePrompt.Successful_Title");
422 label = Dictionary.get("WriteCDImagePrompt.Successful_Export", args);
423 } else {
424 title = Dictionary.get("WriteCDImagePrompt.Failed_Title");
425 label = Dictionary.get("WriteCDImagePrompt.Failed_Export", args);
426 }
427 SimpleResultDialog result_dialog = new SimpleResultDialog(title, label, extra);
428 result_dialog.setVisible(true); // Blocks
429 result_dialog.dispose();
430 result_dialog = null;
431 }
432
433 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
434 * @see org.greenstone.gatherer.Configuration
435 * @see org.greenstone.gatherer.Gatherer
436 * @see org.greenstone.gatherer.util.ArrayTools
437 * @see org.greenstone.gatherer.util.Utility
438 */
439 private void scanForCollections() {
440 // Start at the collect dir.
441 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
442 if (collect_directory.exists()) {
443 scanForCollectionsInternal(collect_directory);
444 }
445 }
446
447 private void scanForCollectionsInternal(File collect_directory) {
448
449 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
450 // For each child directory see if it contains a .cfg file and
451 // if so try to load it..
452 File collections[] = collect_directory.listFiles();
453 ArrayTools.sort(collections);
454 for(int i = 0; collections != null && i < collections.length; i++) {
455 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
456 File config_file = new File(collections[i], file_name);
457 if (config_file.exists()) {
458 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
459 if (config.getCollectGroup().equals("true")) {
460 scanForCollectionsInternal(collections[i]);
461 } else {
462 all_collections.add(config);
463 config = null;
464 }
465 }
466 }
467 }
468 }
469
470
471 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
472 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
473 */
474 public synchronized void message(GShellEvent event) {
475 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
476 String message = event.getMessage();
477 if (message.startsWith("exportcol.pl>")) {
478 message = message.substring(13);
479 //DebugStream.println("message = "+event.getMessage());
480 error_message.append(message);
481 error_message.append("\n");
482 }
483 }
484
485 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell begins its task. Implementation side-effect, not actually used.
486 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
487 */
488 public synchronized void processBegun(GShellEvent event) {
489 // We don't care.
490 }
491 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
492 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
493 */
494 public synchronized void processComplete(GShellEvent event) {
495 successful = false;
496 if(event.getStatus() == GShell.OK) {
497 if(event.getType() == GShell.CDIMAGE) {
498 successful = true;
499 }
500 }
501 ok_button_listener.processComplete();
502 }
503
504 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
505 private class CancelButtonListener
506 implements ActionListener {
507 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
508 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
509 */
510 public void actionPerformed(ActionEvent event) {
511 prompt.dispose();
512 }
513 }
514
515 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
516 */
517 private class CollectionListListener
518 implements ListSelectionListener
519 {
520 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
521 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
522 */
523 public void valueChanged(ListSelectionEvent event)
524 {
525 // Wait for things to settle down a bit
526 if (event.getValueIsAdjusting()) {
527 return;
528 }
529
530 // Can only export when something is ticked
531 ok_button.setEnabled(!list.isNothingTicked());
532
533 if (list.isSelectionEmpty()) {
534 // This only happens when the dialog is first entered
535 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
536 return;
537 }
538
539 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
540 args = new String[3];
541 args[0] = collection.getCreator();
542 args[1] = collection.getMaintainer();
543 args[2] = collection.getDescription();
544 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
545 details_textarea.setCaretPosition(0);
546
547 // Find the size of the "etc", "images" and "index" directories of the collection
548 String collection_directory_path = CollectionManager.getCollectionDirectoryPath(collection.getShortName()); // (colgroup/)subcol
549 File etc_directory = new File(collection_directory_path + "etc");
550 File images_directory = new File(collection_directory_path + "images");
551 File index_directory = new File(collection_directory_path + "index");
552 long collection_size_built = getFileSize(etc_directory) + getFileSize(images_directory) + getFileSize(index_directory);
553
554 // Add/subtract it from the total, depending on whether the collection has just been ticked/unticked
555 if (((CheckListEntry) list.getSelectedValue()).isSelected()) {
556 total_exported_size += collection_size_built;
557 }
558 else {
559 total_exported_size -= collection_size_built;
560 }
561
562 // Update the size field
563 estimated_size_field.setText(Utility.formatFileLength(total_exported_size));
564 }
565 }
566
567
568 /** The OK button listener implementation. */
569 private class OKButtonListener
570 implements ActionListener {
571 private Component glass_pane;
572 private MouseListener mouse_blocker_listener;
573 private ProgressDialog progress_dialog;
574
575 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
576 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
577 * @see org.greenstone.gatherer.Configuration
578 * @see org.greenstone.gatherer.Gatherer
579 * @see org.greenstone.gatherer.util.Utility
580 */
581 public void actionPerformed(ActionEvent event) {
582 ///ystem.err.println("OK Clicked");
583 // Make sure there are some colls specified
584 selected_collections = list.getTicked();
585 error_message = new StringBuffer();
586
587 // Set the cursor to hourglass
588 glass_pane = getGlassPane();
589 mouse_blocker_listener = new MouseAdapter() {};
590 glass_pane.addMouseListener(mouse_blocker_listener);
591 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
592 glass_pane.setVisible(true);
593
594 // Export the selected collection.
595 ///ystem.err.println("Write CD-ROM/DVD image for named collections");
596 writeCDImageCollections();
597
598 // Show progress dialog
599 ///ystem.err.println("Showing progress dialog");
600 progress_dialog = new ProgressDialog();
601 progress_dialog.setVisible(true);
602 }
603
604 public void processComplete() {
605 ///ystem.err.println("Process complete");
606 // Dispose of progress dialog
607 progress_dialog.setVisible(false);
608 progress_dialog.dispose();
609 progress_dialog = null;
610
611 // unset the cursor
612 glass_pane.setVisible(false);
613 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
614 glass_pane.removeMouseListener(mouse_blocker_listener);
615 glass_pane = null;
616 mouse_blocker_listener= null;
617
618 if (successful) {
619 resultPrompt(true, error_message.toString());
620 } else {
621 resultPrompt(false, error_message.toString());
622 }
623 error_message = null;
624 }
625
626 private class ProgressDialog
627 extends ModalDialog {
628
629 private Dimension size = new Dimension(400,65);
630
631 public ProgressDialog() {
632 super(Gatherer.g_man, Dictionary.get("WriteCDImagePrompt.Title"), true);
633 this.setComponentOrientation(Dictionary.getOrientation());
634 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
635 setSize(size);
636 JPanel content_pane = (JPanel) getContentPane();
637 content_pane.setComponentOrientation(Dictionary.getOrientation());
638 JLabel progress_label = new JLabel(Dictionary.get("WriteCDImagePrompt.Progress_Label"));
639 progress_label.setComponentOrientation(Dictionary.getOrientation());
640
641 JProgressBar progress_bar = new JProgressBar();
642 progress_bar.setComponentOrientation(Dictionary.getOrientation());
643 progress_bar.setIndeterminate(true);
644 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
645 content_pane.setLayout(new BorderLayout());
646 content_pane.add(progress_label, BorderLayout.NORTH);
647 content_pane.add(progress_bar, BorderLayout.CENTER);
648 // Position
649 Rectangle frame_bounds = Gatherer.g_man.getBounds();
650 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
651 }
652 }
653 }
654}
Note: See TracBrowser for help on using the repository browser.