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

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

export script has been modified to only use one collection. So modified this prompt to reflect this change.

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