source: gli/trunk/src/org/greenstone/gatherer/gui/ExportAsPrompt.java@ 17132

Last change on this file since 17132 was 17132, checked in by kjdon, 16 years ago

added GreenstoneMETS and FedoraMETS instead of METS in the saveas list. changed all .equals(METS) tests to .endsWith(METS)

  • Property svn:keywords set to Author Date Id Revision
File size: 33.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 java.util.HashMap;
44import javax.swing.*;
45import javax.swing.event.*;
46
47import org.greenstone.gatherer.Configuration;
48import org.greenstone.gatherer.DebugStream;
49import org.greenstone.gatherer.Dictionary;
50import org.greenstone.gatherer.Gatherer;
51import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
52import org.greenstone.gatherer.greenstone.LocalGreenstone;
53import org.greenstone.gatherer.shell.GShell;
54import org.greenstone.gatherer.shell.GShellEvent;
55import org.greenstone.gatherer.shell.GShellListener;
56import org.greenstone.gatherer.shell.GDefaultProgressMonitor;
57import org.greenstone.gatherer.util.ArrayTools;
58import org.greenstone.gatherer.util.CheckList;
59import org.greenstone.gatherer.util.CheckListEntry;
60import org.greenstone.gatherer.util.StaticStrings;
61import org.greenstone.gatherer.util.Utility;
62
63/** This class provides the functionality to export a set of current
64 * collections from the GSDLHOME/collect/ directory to various formats
65 * (hence ExportAs) using export.pl. The user chooses the collection from a
66 * list, where each entry also displays details about itself, confirms the
67 * delete of a collection by checking a checkbox then presses the ok button
68 * to actually delete the collection.
69 * Copied from WriteCDImagePrompt
70 * @author John Thompson, Greenstone Digital Library, University of Waikato
71 * @version 2.3
72 */
73public class ExportAsPrompt
74 extends ModalDialog
75 implements GShellListener {
76
77 static final private Dimension LABEL_SIZE = new Dimension(120, 25);
78
79 private OKButtonListener ok_button_listener;
80
81 private JLabel saveas_label = null;
82 private JComboBox saveas_combobox = null;
83
84 private ArrayList all_collections = null;
85 private ArrayList selected_collections = null;
86 /** The list of collections to include in exported cd-rom/dvd image */
87 private CheckList list = null;
88 /** The currently selected collection for deletion. */
89 private BasicCollectionConfiguration collection = null;
90 /** A reference to ourself so any inner-classes can dispose of us. */
91 private ExportAsPrompt prompt = null;
92 /** The close button, which exits the prompt without deleting anything. */
93 private JButton cancel_button = null;
94 /** The ok button which causes the selected collection to be deleted. */
95 private JButton ok_button = null;
96 /** The label above details. */
97 private JLabel details_label = null;
98 /** The label above the list. */
99 private JLabel list_label = null;
100 /** The text area used to display details about the collection selected. */
101 private JTextArea details_textarea = null;
102 /** The text area used to display instructions for the cd-rom/dvd export */
103 private JTextArea instructions_textarea;
104 /** A string array used to pass arguments to the phrase retrieval method. */
105 private JTextField title_field = null;
106 private JLabel title_label = null;
107 private String args[] = null;
108 private String cd_title = null;
109 /** whether the exporting was successful or not */
110 private boolean successful = false;
111 /** whether we are trying to export or not */
112 private boolean exporting = false;
113 /** the error message if any */
114 private StringBuffer error_message = null;
115 /** The size of the export prompt screen. */
116 public static final Dimension SIZE = new Dimension(500, 540);
117 private GDefaultProgressMonitor progress_monitor;
118
119 private JButton convert_xml_button1 = null;
120 private JButton convert_xml_button2 = null;
121 private JButton convert_xml_button3 = null;
122 private JButton folder_button = null;
123
124 private JPanel instructions_pane = null;
125
126 private JPanel convert_xml_pane1 = null;
127 private JPanel convert_xml_pane2 = null;
128 private JPanel mapping_xml_pane = null;
129
130 private JCheckBox convert_xml_checkbox1 = null;
131 private JCheckBox convert_xml_checkbox2 = null;
132 private JCheckBox mapping_xml_checkbox = null;
133
134 private JCheckBox output_single_checkbox = null;
135
136 private JTextField convert_xml_field1 = null;
137 private JTextField convert_xml_field2 = null;
138 private JTextField mapping_xml_field = null;
139
140
141 private File xsl_file1 = null;
142 private File xsl_file2 = null;
143 private File mapping_file = null;
144
145 private JPanel convert_xml_pane = null;
146
147 private HashMap plugoutMap = new HashMap();
148
149
150 /** Constructor.
151 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CancelButtonListener
152 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CollectionListListener
153 * @see org.greenstone.gatherer.collection.ExportAsPrompt.OKButtonListener
154 */
155 public ExportAsPrompt() {
156 super(Gatherer.g_man, true);
157
158 plugoutMap.clear();
159 plugoutMap.put("DSpace","dublin-core.xml");
160 plugoutMap.put("MARCXML","doc.xml");
161 plugoutMap.put("GreenstoneMETS","doctxt.xml,docmets.xml");
162 plugoutMap.put("FedoraMETS","doctxt.xml,docmets.xml");
163 plugoutMap.put("GA","doc.xml");
164
165 // this is the order we want them to appear in the list
166 String [] saveas_formats = {"GA", "GreenstoneMETS", "FedoraMETS", "MARCXML", "DSpace"};
167 cancel_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
168
169 details_textarea = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
170 details_textarea.setEditable(false);
171
172 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
173
174
175 instructions_textarea = new JTextArea(Dictionary.get("ExportAsPrompt.Instructions"));
176 instructions_textarea.setCaretPosition(0);
177 instructions_textarea.setEditable(false);
178 instructions_textarea.setLineWrap(true);
179 instructions_textarea.setRows(4);
180 instructions_textarea.setWrapStyleWord(true);
181
182
183
184 saveas_label = new JLabel(Dictionary.get("ExportAsPrompt.SaveAs")
185);
186 //saveas_label.setPreferredSize(LABEL_SIZE);
187
188 saveas_combobox = new JComboBox(saveas_formats);
189 saveas_combobox.setOpaque(false);
190 saveas_combobox.setToolTipText(Dictionary.get("ExportAsPrompt.SaveAs_Tooltip"));
191
192
193 // Add xml conversion feature
194 convert_xml_button1 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
195 convert_xml_button1.setEnabled(false);
196
197 convert_xml_button2 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
198 convert_xml_button2.setEnabled(false);
199
200 convert_xml_button3 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
201 convert_xml_button3.setEnabled(false);
202
203 convert_xml_checkbox1 = new JCheckBox();
204 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL","doc.xml"));
205 convert_xml_checkbox1.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
206
207 convert_xml_checkbox2 = new JCheckBox();
208 convert_xml_checkbox2.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
209
210
211 output_single_checkbox = new JCheckBox();
212 output_single_checkbox.setText(Dictionary.get("ExportAsPrompt.MARCXMLGroup"));
213 output_single_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MARCXMLGroup_Tooltip"));
214
215
216 mapping_xml_checkbox = new JCheckBox();
217 mapping_xml_checkbox.setText(Dictionary.get("ExportAsPrompt.MappingXML"));
218 mapping_xml_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MappingXML_Tooltip"));
219
220
221 convert_xml_field1 = new JTextField();
222 convert_xml_field2 = new JTextField();
223 mapping_xml_field = new JTextField();
224
225 convert_xml_pane1 = new JPanel(new BorderLayout());
226
227 convert_xml_pane2 = new JPanel(new BorderLayout());
228
229 mapping_xml_pane = new JPanel(new BorderLayout());
230
231 convert_xml_pane = new JPanel(new GridLayout(3,1));
232
233 all_collections = new ArrayList();
234 list = new CheckList(true);
235 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
236
237 ok_button = new GLIButton(Dictionary.get("ExportAsPrompt.Export"), Dictionary.get("ExportAsPrompt.Export_Tooltip"));
238
239 title_field = new JTextField();
240 title_field.setToolTipText(Dictionary.get("ExportAsPrompt.Export_Name_Tooltip"));
241 title_label = new JLabel(Dictionary.get("ExportAsPrompt.Export_Name"));
242
243 folder_button = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
244 folder_button.addActionListener(new FolderButtonListener());
245
246
247 scanForCollections();
248 list.setListData(all_collections);
249
250 prompt = this;
251 setSize(SIZE);
252 setTitle(Dictionary.get("ExportAsPrompt.Title"));
253
254 setJMenuBar(new SimpleMenuBar("exporting"));
255 cancel_button.addActionListener(new CancelButtonListener());
256 list.addListSelectionListener(new CollectionListListener());
257 list.clearSelection();
258 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
259 ok_button_listener = new OKButtonListener();
260 ok_button.addActionListener(ok_button_listener);
261 ok_button.setEnabled(false);
262 //title.getDocument().addDocumentListener(new DocumentListener());
263
264 convert_xml_button1.addActionListener(new ConvertXMLButtonListener());
265 convert_xml_checkbox1.addActionListener(new ConvertXMLCheckboxListener());
266 mapping_xml_checkbox.addActionListener(new ConvertXMLCheckboxListener());
267 convert_xml_button3.addActionListener(new ConvertXMLButtonListener());
268
269 convert_xml_button2.addActionListener(new ConvertXMLButtonListener());
270 convert_xml_checkbox2.addActionListener(new ConvertXMLCheckboxListener());
271
272 saveas_combobox.addActionListener(new SaveasListener());
273
274 }
275
276 /** Destructor. */
277 public void destroy() {
278 saveas_label = null;
279 saveas_combobox = null;
280 all_collections.clear();
281 all_collections = null;
282 cancel_button = null;
283 details_textarea = null;
284 details_label = null;
285 list = null;
286 ok_button = null;
287 prompt = null;
288 if (selected_collections!=null) {
289 selected_collections.clear();
290 selected_collections = null;
291 }
292 title_field = null;
293 title_label = null;
294 }
295
296 /** This method causes the modal prompt to be displayed.
297 * returns true if it has exported the collections that are currently selected */
298 public boolean display() {
299 // Top pane
300 instructions_pane = new JPanel(new BorderLayout());
301 instructions_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
302 instructions_pane.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
303
304 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
305
306 JPanel title_pane = new JPanel(new BorderLayout());
307 title_pane.add(title_label, BorderLayout.WEST);
308 title_pane.add(title_field, BorderLayout.CENTER);
309 title_pane.add(folder_button, BorderLayout.EAST);
310 //apply xsl pane
311
312 convert_xml_pane1.removeAll();
313 convert_xml_pane2.removeAll();
314 mapping_xml_pane.removeAll();
315 convert_xml_pane.removeAll();
316
317 convert_xml_pane1.add(convert_xml_checkbox1, BorderLayout.WEST);
318 convert_xml_pane1.add(convert_xml_field1, BorderLayout.CENTER);
319 convert_xml_pane1.add(convert_xml_button1, BorderLayout.EAST);
320
321 convert_xml_pane2.add(convert_xml_checkbox2, BorderLayout.WEST);
322 convert_xml_pane2.add(convert_xml_field2, BorderLayout.CENTER);
323 convert_xml_pane2.add(convert_xml_button2, BorderLayout.EAST);
324
325 mapping_xml_pane.add(mapping_xml_checkbox, BorderLayout.WEST);
326 mapping_xml_pane.add(mapping_xml_field, BorderLayout.CENTER);
327 mapping_xml_pane.add(convert_xml_button3, BorderLayout.EAST);
328
329 convert_xml_pane.add(convert_xml_pane1);
330
331 String saveas = (String)saveas_combobox.getSelectedItem();
332 if (saveas.equals("MARCXML")){
333 convert_xml_pane.add(mapping_xml_pane);
334 convert_xml_pane.add(output_single_checkbox);
335 }
336 else{
337 if (saveas.endsWith("METS")){
338 convert_xml_pane.add(convert_xml_pane2);
339 }
340 }
341 convert_xml_pane.revalidate();
342 convert_xml_pane.repaint();
343
344 // Save as pane
345 JPanel saveas_pane = new JPanel(new BorderLayout());
346 saveas_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
347 saveas_pane.add(saveas_label, BorderLayout.WEST);
348 saveas_pane.add(saveas_combobox, BorderLayout.CENTER);
349
350 JPanel tmp_pane = new JPanel(new BorderLayout());
351 tmp_pane.add(saveas_pane, BorderLayout.NORTH);
352 tmp_pane.add(title_pane, BorderLayout.CENTER);
353
354 instructions_pane.add(tmp_pane, BorderLayout.NORTH);
355
356 instructions_pane.add(convert_xml_pane, BorderLayout.CENTER);
357
358 // Central pane
359 JPanel list_pane = new JPanel(new BorderLayout());
360 list_pane.add(list_label, BorderLayout.NORTH);
361 list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
362 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
363
364 JPanel details_pane = new JPanel(new BorderLayout());
365 details_pane.add(details_label, BorderLayout.NORTH);
366 details_pane.add(new JScrollPane(details_textarea), BorderLayout.CENTER);
367 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
368
369 JPanel central_pane = new JPanel(new GridLayout(2, 1));
370 central_pane.add(list_pane);
371 central_pane.add(details_pane);
372 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
373
374 // Lower pane
375 JPanel button_pane = new JPanel(new GridLayout(1, 2));
376 button_pane.add(ok_button);
377 button_pane.add(cancel_button);
378 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
379
380 JPanel lower_pane = new JPanel(new BorderLayout());
381 lower_pane.add(button_pane, BorderLayout.SOUTH);
382 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
383
384 // Final.
385 JPanel content_pane = (JPanel)this.getContentPane();
386 content_pane.setLayout(new BorderLayout());
387 content_pane.add(instructions_pane, BorderLayout.NORTH);
388 content_pane.add(central_pane, BorderLayout.CENTER);
389 content_pane.add(lower_pane, BorderLayout.SOUTH);
390
391 // Center and display.
392 Dimension screen_size = Configuration.screen_size;
393 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
394 this.setVisible(true); // blocks until the dialog is killed
395 return true;
396
397 }
398
399
400 /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
401 * @see org.greenstone.gatherer.Configuration
402 * @see org.greenstone.gatherer.Gatherer
403 * @see org.greenstone.gatherer.collection.Collection
404 * @see org.greenstone.gatherer.gui.BuildOptions
405 * @see org.greenstone.gatherer.shell.GShell
406 * @see org.greenstone.gatherer.shell.GShellListener
407 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
408 * @see org.greenstone.gatherer.util.Utility
409 */
410 public void exportAsCollections() {
411 DebugStream.println("ExportAsPrompt.exportAsCollections()");
412
413 int num_collections = selected_collections.size();
414 if (num_collections == 0) return;
415 cd_title = title_field.getText();
416
417 String export_type = (String) saveas_combobox.getSelectedItem();
418
419 // Generate the export.pl command
420 ArrayList command_parts_list = new ArrayList();
421 if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
422 command_parts_list.add(Configuration.perl_path);
423 command_parts_list.add("-S");
424 }
425 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "export.pl");
426 command_parts_list.add("-gli");
427 command_parts_list.add("-language");
428 command_parts_list.add(Configuration.getLanguage());
429 command_parts_list.add("-removeold");
430 command_parts_list.add("-saveas");
431 command_parts_list.add(export_type);
432 command_parts_list.add("-exportdir");
433 String export_dir = LocalGreenstone.getTmpDirectoryPath();
434 if (cd_title.equals("")) {
435 export_dir += "exported_" + export_type;
436 }
437 else {
438 File cd_file = new File(cd_title);
439 if (cd_file.isAbsolute())
440 export_dir = cd_title + File.separator + "exported_" + export_type;
441 else{
442 cd_title = cd_title.replaceAll("\\s+","");
443 cd_title = cd_title.replaceAll("\\\\+","/");
444 cd_title = cd_title.replaceAll("/+","/");
445 export_dir +=cd_title;
446 }
447 }
448
449 command_parts_list.add(export_dir);
450
451 if (!export_type.endsWith("METS") && xsl_file1 !=null){
452 command_parts_list.add("-xsltfile");
453 command_parts_list.add(xsl_file1.getPath());
454 }
455
456 //add command specific to MARCXML
457 if (export_type.equals("MARCXML")){
458 //add default transformation file
459 if (xsl_file1 == null){
460 command_parts_list.add("-xsltfile");
461 command_parts_list.add(Configuration.gsdl_path+"etc"+File.separator+"dc2marc.xsl");
462 }
463
464 command_parts_list.add("-mapping_file");
465 //default mapping file
466 if (mapping_file == null){
467 command_parts_list.add(Configuration.gsdl_path+"etc"+File.separator+"dc2marc-mapping.xml");
468 }
469 else{
470 command_parts_list.add(mapping_file.getPath());
471 }
472
473 if (output_single_checkbox.isSelected()){
474 command_parts_list.add("-group_marc");
475 }
476
477 }
478
479
480 if (export_type.endsWith("METS") && xsl_file1 !=null){
481 command_parts_list.add("-xslt_txt");
482 command_parts_list.add(xsl_file1.getPath());
483 }
484
485 if (export_type.endsWith("METS") && xsl_file2 !=null){
486 command_parts_list.add("-xslt_mets");
487 command_parts_list.add(xsl_file2.getPath());
488 }
489
490 for (int i = 0; i < num_collections; i++) {
491 command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
492 }
493
494 DebugStream.print("export command = ");
495 for (int i = 0; i < command_parts_list.size(); i++) {
496 DebugStream.print(command_parts_list.get(i) + " ");
497 //System.err.print(command_parts_list.get(i) + " ");
498 }
499 DebugStream.println("");
500
501 // Run the export.pl command
502 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
503
504 progress_monitor = new GDefaultProgressMonitor();
505
506 GShell process = new GShell(command_parts, GShell.EXPORTAS, 3, this,progress_monitor , GShell.GSHELL_EXPORTAS);
507 process.start();
508 //process.run();
509 DebugStream.println("ExportAsPrompt.exportAsCollections().return");
510
511 }
512
513
514 public void cancelExporting(){
515 progress_monitor.setStop(true);
516 }
517
518
519 /** Shows an export complete prompt.
520 * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
521 * @see org.greenstone.gatherer.collection.Collection
522 */
523 public void resultPrompt(boolean success, String extra) {
524 args = new String[2];
525 StringBuffer coll_names = new StringBuffer();
526 for (int i=0; i<selected_collections.size();i++) {
527 if (i>0) {
528 coll_names.append(", ");
529 }
530 BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
531 coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
532 complete_collection = null;
533 }
534
535 args[0] = coll_names.toString();
536
537 String export_type = (String) saveas_combobox.getSelectedItem();
538 args[1] = LocalGreenstone.getTmpDirectoryPath();
539 if (cd_title.equals("")) {
540 args[1] += "exported_" + export_type;
541 }
542 else {
543 File cd_file = new File(cd_title);
544 if (cd_file.isAbsolute())
545 args[1] = cd_title + File.separator + "exported_" + export_type;
546 else{
547 cd_title = cd_title.replaceAll("\\s+","");
548 cd_title = cd_title.replaceAll("\\\\+","/");
549 cd_title = cd_title.replaceAll("/+","/");
550 args[1] +=cd_title;
551 }
552 }
553
554
555 String title;
556 String label;
557 String details;
558
559 if (success) {
560 String successMessage
561 = (selected_collections.size()==1)
562 ? "ExportAsPrompt.Successful_ExportOne"
563 : "ExportAsPrompt.Successful_ExportMany";
564
565 title = Dictionary.get("ExportAsPrompt.Successful_Title");
566 label = Dictionary.get(successMessage, args);
567 details = Dictionary.get("ExportAsPrompt.Successful_Details", args);
568 } else {
569 String failedMessage
570 = (selected_collections.size()==1)
571 ? "ExportAsPrompt.Failed_ExportOne"
572 : "ExportAsPrompt.Failed_ExportMany";
573
574 title = Dictionary.get("ExportAsPrompt.Failed_Title");
575 label = Dictionary.get(failedMessage, args);
576 details = Dictionary.get("ExportAsPrompt.Failed_Details", args);
577 }
578 SimpleResultDialog result_dialog = new SimpleResultDialog(this, title, label, details);
579 result_dialog.setVisible(true); // Blocks
580 result_dialog.dispose();
581 result_dialog = null;
582 }
583
584 /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
585 * @see org.greenstone.gatherer.Configuration
586 * @see org.greenstone.gatherer.Gatherer
587 * @see org.greenstone.gatherer.util.ArrayTools
588 * @see org.greenstone.gatherer.util.Utility
589 */
590 private void scanForCollections() {
591 // Start at the collect dir.
592 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
593 String file_name = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
594 if (collect_directory.exists()) {
595 // Now for each child directory see if it contains a .col file and
596 // if so try to load it..
597 File collections[] = collect_directory.listFiles();
598 ArrayTools.sort(collections);
599 for(int i = 0; collections != null && i < collections.length; i++) {
600 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
601 File config_file = new File(collections[i], file_name);
602 if (config_file.exists()) {
603 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
604 all_collections.add(config);
605 config = null;
606 }
607 }
608 }
609 }
610 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
611 }
612
613
614 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
615 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
616 */
617 public synchronized void message(GShellEvent event) {
618 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
619 String message = event.getMessage();
620 if (message.startsWith("export.pl>")) {
621 message = message.substring(13);
622 //DebugStream.println("message = "+event.getMessage());
623 error_message.append(message);
624 error_message.append("\n");
625 }
626 }
627
628 /** 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.
629 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
630 */
631 public synchronized void processBegun(GShellEvent event) {
632 // We don't care.
633 }
634 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
635 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
636 */
637 public synchronized void processComplete(GShellEvent event) {
638 successful = false;
639 if(event.getStatus() == GShell.OK) {
640 if(event.getType() == GShell.EXPORTAS) {
641 successful = true;
642 }
643 }
644 ok_button_listener.processComplete();
645 }
646
647 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
648 private class CancelButtonListener
649 implements ActionListener {
650 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
651 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
652 */
653 public void actionPerformed(ActionEvent event) {
654 prompt.dispose();
655 }
656 }
657
658 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
659 */
660 private class CollectionListListener
661 implements ListSelectionListener
662 {
663 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
664 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
665 */
666 public void valueChanged(ListSelectionEvent event)
667 {
668 // Can only export when something is ticked
669 ok_button.setEnabled(!list.isNothingTicked());
670
671 if (list.isSelectionEmpty()) {
672 // This only happens when the dialog is first entered
673 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
674 return;
675 }
676
677 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
678 args = new String[3];
679 args[0] = collection.getCreator();
680 args[1] = collection.getMaintainer();
681 args[2] = collection.getDescription();
682 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
683 details_textarea.setCaretPosition(0);
684 }
685 }
686
687
688 /** The OK button listener implementation. */
689 private class OKButtonListener
690 implements ActionListener {
691 private Component glass_pane;
692 private MouseListener mouse_blocker_listener;
693 private ProgressDialog progress_dialog;
694
695 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
696 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
697 * @see org.greenstone.gatherer.Configuration
698 * @see org.greenstone.gatherer.Gatherer
699 * @see org.greenstone.gatherer.util.Utility
700 */
701 public void actionPerformed(ActionEvent event) {
702 ///ystem.err.println("OK Clicked");
703 // Make sure there are some colls specified
704 selected_collections = list.getTicked();
705 error_message = new StringBuffer();
706
707 // Set the cursor to hourglass
708 glass_pane = getGlassPane();
709 mouse_blocker_listener = new MouseAdapter() {};
710 glass_pane.addMouseListener(mouse_blocker_listener);
711 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
712 glass_pane.setVisible(true);
713
714 // Export the selected collection.
715 ///ystem.err.println("Exporting As for named collections");
716 exportAsCollections();
717
718 // Show progress dialog
719 ///ystem.err.println("Showing progress dialog");
720 progress_dialog = new ProgressDialog();
721 progress_dialog.setVisible(true);
722 }
723
724 public void processComplete() {
725 ///ystem.err.println("Process complete");
726 // Dispose of progress dialog
727
728
729 progress_dialog.setVisible(false);
730 progress_dialog.dispose();
731 progress_dialog = null;
732
733 // unset the cursor
734 glass_pane.setVisible(false);
735 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
736 glass_pane.removeMouseListener(mouse_blocker_listener);
737 glass_pane = null;
738 mouse_blocker_listener= null;
739
740 if (successful) {
741 resultPrompt(true, error_message.toString());
742 } else {
743 resultPrompt(false, error_message.toString());
744 }
745 error_message = null;
746
747 convert_xml_button1.setEnabled(false);
748 xsl_file1 = null;
749 convert_xml_field1.setText("");
750 convert_xml_checkbox1.setSelected(false);
751
752 convert_xml_button2.setEnabled(false);
753 xsl_file2 = null;
754 convert_xml_field2.setText("");
755 convert_xml_checkbox2.setSelected(false);
756
757 mapping_xml_checkbox.setSelected(false);
758 output_single_checkbox.setSelected(false);
759 convert_xml_button3.setEnabled(false);
760 mapping_xml_field.setText("");
761 mapping_file = null;
762
763 }
764
765 private class ProgressDialog
766 extends ModalDialog {
767
768 private Dimension size = new Dimension(400,110);
769
770 public ProgressDialog() {
771 super(Gatherer.g_man, Dictionary.get("ExportAsPrompt.Title"), true);
772 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
773 setSize(size);
774 JPanel content_pane = (JPanel) getContentPane();
775 JLabel progress_label = new JLabel(Dictionary.get("ExportAsPrompt.Progress_Label"));
776
777 JProgressBar progress_bar = new JProgressBar();
778 progress_bar.setIndeterminate(true);
779 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
780 GLIButton cancel_button = new GLIButton(Dictionary.get("ExportAsPrompt.Cancel"),Dictionary.get("ExportAsPrompt.Cancel_Tooltip"));
781 cancel_button.setMnemonic(KeyEvent.VK_C);
782
783 cancel_button.addActionListener(new ActionListener(){
784 public void actionPerformed(ActionEvent e){
785 cancelExporting();
786 }
787
788 });
789
790 JPanel cancel_panel = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
791 cancel_panel.add(cancel_button);
792
793 content_pane.setLayout(new BorderLayout(0,5));
794 content_pane.add(progress_label, BorderLayout.NORTH);
795 content_pane.add(progress_bar, BorderLayout.CENTER);
796 content_pane.add(cancel_panel, BorderLayout.SOUTH);
797
798 // Position
799 Rectangle frame_bounds = Gatherer.g_man.getBounds();
800 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
801 }
802 }
803 }
804
805 private class ConvertXMLCheckboxListener implements ActionListener {
806 public void actionPerformed(ActionEvent event) {
807
808 convert_xml_button1.setEnabled(convert_xml_checkbox1.isSelected());
809 convert_xml_button2.setEnabled(convert_xml_checkbox2.isSelected());
810 convert_xml_button3.setEnabled(mapping_xml_checkbox.isSelected());
811
812 }
813 }
814
815
816
817 private class SaveasListener implements ActionListener {
818
819 public void actionPerformed(ActionEvent event) {
820
821 convert_xml_checkbox1.setSelected(false);
822 convert_xml_checkbox2.setSelected(false);
823 mapping_xml_checkbox.setSelected(false);
824 output_single_checkbox.setSelected(false);
825
826 convert_xml_button1.setEnabled(false);
827 convert_xml_button2.setEnabled(false);
828 convert_xml_button3.setEnabled(false);
829
830 convert_xml_field1.setText("");
831 convert_xml_field2.setText("");
832 mapping_xml_field.setText("");
833
834 String saveas = (String)saveas_combobox.getSelectedItem();
835
836 if (convert_xml_pane.getComponentCount() > 1){
837 convert_xml_pane.remove(1);
838 if (convert_xml_pane.getComponentCount() > 1){
839 convert_xml_pane.remove(1);
840 }
841 }
842
843 if (!saveas.endsWith("METS")){
844
845 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",(String)plugoutMap.get(saveas)));
846 if (saveas.equals("MARCXML")){
847 convert_xml_pane.add(mapping_xml_pane);
848 convert_xml_pane.add(output_single_checkbox);
849 }
850 }
851 else{
852 String[] docs = ((String)plugoutMap.get(saveas)).split(",");
853 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[0]));
854 convert_xml_checkbox2.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[1]));
855 convert_xml_pane.add(convert_xml_pane2);
856 }
857
858 convert_xml_pane.revalidate();
859 convert_xml_pane.repaint();
860 instructions_pane.revalidate();
861 instructions_pane.repaint();
862
863 }
864
865 }
866
867 private class ConvertXMLButtonListener implements ActionListener {
868 public void actionPerformed(ActionEvent event) {
869 JFileChooser chooser = new JFileChooser();
870 // Note: source for ExampleFileFilter can be found in FileChooserDemo,
871 // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
872 javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter(){
873 public boolean accept(File f){
874 return f.getPath().endsWith(".xsl")||f.isDirectory()||f.getPath().endsWith(".xml");
875 }
876
877 public String getDescription(){
878 return "XSL or XML file";
879 }
880 };
881
882 chooser.setFileFilter(filter);
883 int returnVal = chooser.showOpenDialog(prompt);
884
885 if(returnVal == JFileChooser.APPROVE_OPTION) {
886 if (event.getSource() == convert_xml_button1){
887
888 xsl_file1 = chooser.getSelectedFile();
889 convert_xml_field1.setText(xsl_file1.getPath());
890 }
891 else if (event.getSource() == convert_xml_button2){
892 xsl_file2 = chooser.getSelectedFile();
893 convert_xml_field2.setText(xsl_file2.getPath());
894
895 }
896 else {
897 mapping_file = chooser.getSelectedFile();
898 mapping_xml_field.setText(mapping_file.getPath());
899 }
900 }
901 }
902 }
903
904 private class FolderButtonListener implements ActionListener {
905 public void actionPerformed(ActionEvent event) {
906 JFileChooser chooser = new JFileChooser();
907 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
908
909 int returnVal = chooser.showOpenDialog(prompt);
910
911 if(returnVal == JFileChooser.APPROVE_OPTION) {
912 File folder_name = chooser.getSelectedFile();
913 title_field.setText(folder_name.getPath());
914 }
915
916 }
917 }
918}
919
920
921
922
923
Note: See TracBrowser for help on using the repository browser.