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

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

small changes to do with updating fields based on saveas, and disable the text fields if checkbox not selected

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