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

Last change on this file since 12592 was 12592, checked in by shaoqun, 18 years ago

added mapping file option for MARCXML

  • Property svn:keywords set to Author Date Id Revision
File size: 32.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.LocalGreenstone;
52import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
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, 520);
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
123 private JPanel instructions_pane = null;
124
125 private JPanel convert_xml_pane1 = null;
126 private JPanel convert_xml_pane2 = null;
127 private JPanel mapping_xml_pane = null;
128
129 private JCheckBox convert_xml_checkbox1 = null;
130 private JCheckBox convert_xml_checkbox2 = null;
131 private JCheckBox mapping_xml_checkbox = null;
132
133 private JCheckBox output_single_checkbox = null;
134
135 private JTextField convert_xml_field1 = null;
136 private JTextField convert_xml_field2 = null;
137 private JTextField mapping_xml_field = null;
138
139
140 private File xsl_file1 = null;
141 private File xsl_file2 = null;
142 private File mapping_file = null;
143
144 private JPanel convert_xml_pane = null;
145
146 private HashMap plugoutMap = new HashMap();
147
148
149 /** Constructor.
150 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CancelButtonListener
151 * @see org.greenstone.gatherer.collection.ExportAsPrompt.CollectionListListener
152 * @see org.greenstone.gatherer.collection.ExportAsPrompt.OKButtonListener
153 */
154 public ExportAsPrompt() {
155 super(Gatherer.g_man, true);
156
157 plugoutMap.clear();
158 plugoutMap.put("DSpace","dublin-core.xml");
159 plugoutMap.put("MARCXML","doc.xml");
160 plugoutMap.put("METS","doctxt.xml,docmets.xml");
161 plugoutMap.put("GA","doc.xml");
162
163 cancel_button = new GLIButton(Dictionary.get("General.Close"), Dictionary.get("General.Close_Tooltip"));
164
165 details_textarea = new JTextArea(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
166 details_textarea.setEditable(false);
167
168 details_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_Details"));
169
170
171 instructions_textarea = new JTextArea(Dictionary.get("ExportAsPrompt.Instructions"));
172 instructions_textarea.setCaretPosition(0);
173 instructions_textarea.setEditable(false);
174 instructions_textarea.setLineWrap(true);
175 instructions_textarea.setRows(4);
176 instructions_textarea.setWrapStyleWord(true);
177
178
179 // Save As
180 ArrayList saveas_formats = new ArrayList(plugoutMap.keySet());
181
182 saveas_label = new JLabel(Dictionary.get("ExportAsPrompt.SaveAs")
183);
184 //saveas_label.setPreferredSize(LABEL_SIZE);
185
186 saveas_combobox = new JComboBox(saveas_formats.toArray());
187 saveas_combobox.setToolTipText(Dictionary.get("ExportAsPrompt.SaveAs_Tooltip"));
188
189
190 // Add xml conversion feature
191 convert_xml_button1 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
192 convert_xml_button1.setEnabled(false);
193
194 convert_xml_button2 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
195 convert_xml_button2.setEnabled(false);
196
197 convert_xml_button3 = new GLIButton(Dictionary.get("ExportAsPrompt.Browse"),Dictionary.get("ExportAsPrompt.Browse_Tooltip"));
198 convert_xml_button3.setEnabled(false);
199
200 convert_xml_checkbox1 = new JCheckBox();
201 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL","doc.xml"));
202 convert_xml_checkbox1.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
203
204 convert_xml_checkbox2 = new JCheckBox();
205 convert_xml_checkbox2.setToolTipText(Dictionary.get("ExportAsPrompt.ApplyXSL_Tooltip"));
206
207
208 output_single_checkbox = new JCheckBox();
209 output_single_checkbox.setText(Dictionary.get("ExportAsPrompt.MARCXMLGroup"));
210 output_single_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MARCXMLGroup_Tooltip"));
211
212
213 mapping_xml_checkbox = new JCheckBox();
214 mapping_xml_checkbox.setText(Dictionary.get("ExportAsPrompt.MappingXML"));
215 mapping_xml_checkbox.setToolTipText(Dictionary.get("ExportAsPrompt.MappingXML_Tooltip"));
216
217
218 convert_xml_field1 = new JTextField();
219 convert_xml_field2 = new JTextField();
220 mapping_xml_field = new JTextField();
221
222 convert_xml_pane1 = new JPanel(new BorderLayout());
223
224 convert_xml_pane2 = new JPanel(new BorderLayout());
225
226 mapping_xml_pane = new JPanel(new BorderLayout());
227
228 convert_xml_pane = new JPanel(new GridLayout(3,1));
229
230 all_collections = new ArrayList();
231 list = new CheckList(true);
232 list_label = new JLabel(Dictionary.get("DeleteCollectionPrompt.Collection_List"));
233
234 ok_button = new GLIButton(Dictionary.get("ExportAsPrompt.Export"), Dictionary.get("ExportAsPrompt.Export_Tooltip"));
235
236 title_field = new JTextField();
237 // Dictionary.setTooltip(title_field, "ExportAsPrompt.Export_Name_Tooltip");
238 title_label = new JLabel(Dictionary.get("ExportAsPrompt.Export_Name"));
239
240 scanForCollections();
241 list.setListData(all_collections);
242
243 prompt = this;
244 setSize(SIZE);
245 setTitle(Dictionary.get("ExportAsPrompt.Title"));
246
247 setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
248 cancel_button.addActionListener(new CancelButtonListener());
249 list.addListSelectionListener(new CollectionListListener());
250 list.clearSelection();
251 list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
252 ok_button_listener = new OKButtonListener();
253 ok_button.addActionListener(ok_button_listener);
254 ok_button.setEnabled(false);
255 //title.getDocument().addDocumentListener(new DocumentListener());
256
257 convert_xml_button1.addActionListener(new ConvertXMLButtonListener());
258 convert_xml_checkbox1.addActionListener(new ConvertXMLCheckboxListener());
259 mapping_xml_checkbox.addActionListener(new ConvertXMLCheckboxListener());
260 convert_xml_button3.addActionListener(new ConvertXMLButtonListener());
261
262 convert_xml_button2.addActionListener(new ConvertXMLButtonListener());
263 convert_xml_checkbox2.addActionListener(new ConvertXMLCheckboxListener());
264
265 saveas_combobox.addActionListener(new SaveasListener());
266
267 }
268
269 /** Destructor. */
270 public void destroy() {
271 saveas_label = null;
272 saveas_combobox = null;
273 all_collections.clear();
274 all_collections = null;
275 cancel_button = null;
276 details_textarea = null;
277 details_label = null;
278 list = null;
279 ok_button = null;
280 prompt = null;
281 if (selected_collections!=null) {
282 selected_collections.clear();
283 selected_collections = null;
284 }
285 title_field = null;
286 title_label = null;
287 }
288
289 /** This method causes the modal prompt to be displayed.
290 * returns true if it has exported the collections that are currently selected */
291 public boolean display() {
292 // Top pane
293 instructions_pane = new JPanel(new BorderLayout());
294 instructions_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
295 instructions_pane.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
296
297 title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
298
299 JPanel title_pane = new JPanel(new BorderLayout());
300 title_pane.add(title_label, BorderLayout.WEST);
301 title_pane.add(title_field, BorderLayout.CENTER);
302
303 //apply xsl pane
304
305 convert_xml_pane1.removeAll();
306 convert_xml_pane2.removeAll();
307 mapping_xml_pane.removeAll();
308 convert_xml_pane.removeAll();
309
310 convert_xml_pane1.add(convert_xml_checkbox1, BorderLayout.WEST);
311 convert_xml_pane1.add(convert_xml_field1, BorderLayout.CENTER);
312 convert_xml_pane1.add(convert_xml_button1, BorderLayout.EAST);
313
314 convert_xml_pane2.add(convert_xml_checkbox2, BorderLayout.WEST);
315 convert_xml_pane2.add(convert_xml_field2, BorderLayout.CENTER);
316 convert_xml_pane2.add(convert_xml_button2, BorderLayout.EAST);
317
318 mapping_xml_pane.add(mapping_xml_checkbox, BorderLayout.WEST);
319 mapping_xml_pane.add(mapping_xml_field, BorderLayout.CENTER);
320 mapping_xml_pane.add(convert_xml_button3, BorderLayout.EAST);
321
322 convert_xml_pane.add(convert_xml_pane1);
323
324 String saveas = (String)saveas_combobox.getSelectedItem();
325 if (saveas.equals("MARCXML")){
326 convert_xml_pane.add(mapping_xml_pane);
327 convert_xml_pane.add(output_single_checkbox);
328 }
329 else{
330 if (saveas.equals("METS")){
331 convert_xml_pane.add(convert_xml_pane2);
332 }
333 }
334 convert_xml_pane.revalidate();
335 convert_xml_pane.repaint();
336
337 // Save as pane
338 JPanel saveas_pane = new JPanel(new BorderLayout());
339 saveas_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
340 saveas_pane.add(saveas_label, BorderLayout.WEST);
341 saveas_pane.add(saveas_combobox, BorderLayout.CENTER);
342
343 JPanel tmp_pane = new JPanel(new BorderLayout());
344 tmp_pane.add(saveas_pane, BorderLayout.WEST);
345 tmp_pane.add(title_pane, BorderLayout.CENTER);
346
347 instructions_pane.add(tmp_pane, BorderLayout.NORTH);
348
349 instructions_pane.add(convert_xml_pane, BorderLayout.CENTER);
350
351 // Central pane
352 JPanel list_pane = new JPanel(new BorderLayout());
353 list_pane.add(list_label, BorderLayout.NORTH);
354 list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
355 list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
356
357 JPanel details_pane = new JPanel(new BorderLayout());
358 details_pane.add(details_label, BorderLayout.NORTH);
359 details_pane.add(new JScrollPane(details_textarea), BorderLayout.CENTER);
360 details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
361
362 JPanel central_pane = new JPanel(new GridLayout(2, 1));
363 central_pane.add(list_pane);
364 central_pane.add(details_pane);
365 central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
366
367 // Lower pane
368 JPanel button_pane = new JPanel(new GridLayout(1, 2));
369 button_pane.add(ok_button);
370 button_pane.add(cancel_button);
371 button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
372
373 JPanel lower_pane = new JPanel(new BorderLayout());
374 lower_pane.add(button_pane, BorderLayout.SOUTH);
375 lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
376
377 // Final.
378 JPanel content_pane = (JPanel)this.getContentPane();
379 content_pane.setLayout(new BorderLayout());
380 content_pane.add(instructions_pane, BorderLayout.NORTH);
381 content_pane.add(central_pane, BorderLayout.CENTER);
382 content_pane.add(lower_pane, BorderLayout.SOUTH);
383
384 // Center and display.
385 Dimension screen_size = Configuration.screen_size;
386 this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
387 this.setVisible(true); // blocks until the dialog is killed
388 return true;
389
390 }
391
392
393 /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
394 * @see org.greenstone.gatherer.Configuration
395 * @see org.greenstone.gatherer.Gatherer
396 * @see org.greenstone.gatherer.collection.Collection
397 * @see org.greenstone.gatherer.gui.BuildOptions
398 * @see org.greenstone.gatherer.shell.GShell
399 * @see org.greenstone.gatherer.shell.GShellListener
400 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
401 * @see org.greenstone.gatherer.util.Utility
402 */
403 public void exportAsCollections() {
404 DebugStream.println("ExportAsPrompt.exportAsCollections()");
405
406 int num_collections = selected_collections.size();
407 if (num_collections == 0) return;
408 cd_title = title_field.getText();
409 cd_title = cd_title.trim();
410 cd_title = cd_title.replaceAll("\"", "");
411
412 String export_type = (String) saveas_combobox.getSelectedItem();
413
414 // Generate the export.pl command
415 ArrayList command_parts_list = new ArrayList();
416 if (Utility.isWindows() && (!Gatherer.isGsdlRemote)) {
417 command_parts_list.add(Configuration.perl_path);
418 command_parts_list.add("-S");
419 }
420 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "export.pl");
421 command_parts_list.add("-gli");
422 command_parts_list.add("-language");
423 command_parts_list.add(Configuration.getLanguage());
424 command_parts_list.add("-removeold");
425 command_parts_list.add("-saveas");
426 command_parts_list.add(export_type);
427 command_parts_list.add("-exportdir");
428 String export_dir = LocalGreenstone.getTmpDirectoryPath();
429 if (cd_title.equals("")) {
430 export_dir += "exported_" + export_type;
431 }
432 else {
433 export_dir += "exported_" + cd_title.replaceAll("\\s", "");
434 }
435 command_parts_list.add(export_dir);
436
437 if (!export_type.equals("METS") && xsl_file1 !=null){
438 command_parts_list.add("-xsltfile");
439 command_parts_list.add(xsl_file1.getPath());
440 }
441
442 //add command specific to MARCXML
443 if (export_type.equals("MARCXML")){
444 //add default transformation file
445 if (xsl_file1 == null){
446 command_parts_list.add("-xsltfile");
447 command_parts_list.add(Configuration.gsdl_path+"etc"+File.separator+"dc2marc.xsl");
448 }
449
450 command_parts_list.add("-mapping_file");
451 //default mapping file
452 if (mapping_file == null){
453 command_parts_list.add(Configuration.gsdl_path+"etc"+File.separator+"dc2marc-mapping.xml");
454 }
455 else{
456 command_parts_list.add(mapping_file.getPath());
457 }
458
459 if (output_single_checkbox.isSelected()){
460 command_parts_list.add("-group_marc");
461 }
462
463 }
464
465
466 if (export_type.equals("METS") && xsl_file1 !=null){
467 command_parts_list.add("-xslt_txt");
468 command_parts_list.add(xsl_file1.getPath());
469 }
470
471 if (export_type.equals("METS") && xsl_file2 !=null){
472 command_parts_list.add("-xslt_mets");
473 command_parts_list.add(xsl_file2.getPath());
474 }
475
476 for (int i = 0; i < num_collections; i++) {
477 command_parts_list.add(((BasicCollectionConfiguration) selected_collections.get(i)).getShortName());
478 }
479
480 DebugStream.print("export command = ");
481 for (int i = 0; i < command_parts_list.size(); i++) {
482 DebugStream.print(command_parts_list.get(i) + " ");
483 //System.err.print(command_parts_list.get(i) + " ");
484 }
485 DebugStream.println("");
486 //System.err.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 StringBuffer coll_names = new StringBuffer();
513 for (int i=0; i<selected_collections.size();i++) {
514 if (i>0) {
515 coll_names.append(", ");
516 }
517 BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
518 coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
519 complete_collection = null;
520 }
521
522 args[0] = coll_names.toString();
523
524 args[1] = LocalGreenstone.getTmpDirectoryPath();
525 if(cd_title.equals("")) {
526 String export_type = (String)saveas_combobox.getSelectedItem();
527 args[1] += "exported_" + export_type;
528 } else {
529 args[1] += "exported_"+cd_title.replaceAll("\\s","");
530 }
531
532 String title;
533 String label;
534 String details;
535
536 if (success) {
537 String successMessage
538 = (selected_collections.size()==1)
539 ? "ExportAsPrompt.Successful_ExportOne"
540 : "ExportAsPrompt.Successful_ExportMany";
541
542 title = Dictionary.get("ExportAsPrompt.Successful_Title");
543 label = Dictionary.get(successMessage, args);
544 details = Dictionary.get("ExportAsPrompt.Successful_Details", args);
545 } else {
546 String failedMessage
547 = (selected_collections.size()==1)
548 ? "ExportAsPrompt.Failed_ExportOne"
549 : "ExportAsPrompt.Failed_ExportMany";
550
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(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 void scanForCollections() {
568 // Start at the collect dir.
569 File collect_directory = new File(Gatherer.getCollectDirectoryPath());
570 if (collect_directory.exists()) {
571 // Now for each child directory see if it contains a .col file and
572 // if so try to load it..
573 File collections[] = collect_directory.listFiles();
574 ArrayTools.sort(collections);
575 for(int i = 0; collections != null && i < collections.length; i++) {
576 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
577 File config_file = new File(collections[i], Utility.CONFIG_FILE);
578 if (config_file.exists()) {
579 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
580 all_collections.add(config);
581 config = null;
582 }
583 }
584 }
585 }
586 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
587 }
588
589
590 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
591 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
592 */
593 public synchronized void message(GShellEvent event) {
594 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
595 String message = event.getMessage();
596 if (message.startsWith("export.pl>")) {
597 message = message.substring(13);
598 //DebugStream.println("message = "+event.getMessage());
599 error_message.append(message);
600 error_message.append("\n");
601 }
602 }
603
604 /** 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.
605 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
606 */
607 public synchronized void processBegun(GShellEvent event) {
608 // We don't care.
609 }
610 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
611 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
612 */
613 public synchronized void processComplete(GShellEvent event) {
614 successful = false;
615 if(event.getStatus() == GShell.OK) {
616 if(event.getType() == GShell.EXPORTAS) {
617 successful = true;
618 }
619 }
620 ok_button_listener.processComplete();
621 }
622
623 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
624 private class CancelButtonListener
625 implements ActionListener {
626 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
627 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
628 */
629 public void actionPerformed(ActionEvent event) {
630 prompt.dispose();
631 }
632 }
633
634 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
635 */
636 private class CollectionListListener
637 implements ListSelectionListener
638 {
639 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
640 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
641 */
642 public void valueChanged(ListSelectionEvent event)
643 {
644 // Can only export when something is ticked
645 ok_button.setEnabled(!list.isNothingTicked());
646
647 if (list.isSelectionEmpty()) {
648 // This only happens when the dialog is first entered
649 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
650 return;
651 }
652
653 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
654 args = new String[3];
655 args[0] = collection.getCreator();
656 args[1] = collection.getMaintainer();
657 args[2] = collection.getDescription();
658 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
659 details_textarea.setCaretPosition(0);
660 }
661 }
662
663
664 /** The OK button listener implementation. */
665 private class OKButtonListener
666 implements ActionListener {
667 private Component glass_pane;
668 private MouseListener mouse_blocker_listener;
669 private ProgressDialog progress_dialog;
670
671 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
672 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
673 * @see org.greenstone.gatherer.Configuration
674 * @see org.greenstone.gatherer.Gatherer
675 * @see org.greenstone.gatherer.util.Utility
676 */
677 public void actionPerformed(ActionEvent event) {
678 ///ystem.err.println("OK Clicked");
679 // Make sure there are some colls specified
680 selected_collections = list.getTicked();
681 error_message = new StringBuffer();
682
683 // Set the cursor to hourglass
684 glass_pane = getGlassPane();
685 mouse_blocker_listener = new MouseAdapter() {};
686 glass_pane.addMouseListener(mouse_blocker_listener);
687 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
688 glass_pane.setVisible(true);
689
690 // Export the selected collection.
691 ///ystem.err.println("Exporting As for named collections");
692 exportAsCollections();
693
694 // Show progress dialog
695 ///ystem.err.println("Showing progress dialog");
696 progress_dialog = new ProgressDialog();
697 progress_dialog.setVisible(true);
698 }
699
700 public void processComplete() {
701 ///ystem.err.println("Process complete");
702 // Dispose of progress dialog
703
704
705 progress_dialog.setVisible(false);
706 progress_dialog.dispose();
707 progress_dialog = null;
708
709 // unset the cursor
710 glass_pane.setVisible(false);
711 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
712 glass_pane.removeMouseListener(mouse_blocker_listener);
713 glass_pane = null;
714 mouse_blocker_listener= null;
715
716 if (successful) {
717 resultPrompt(true, error_message.toString());
718 } else {
719 resultPrompt(false, error_message.toString());
720 }
721 error_message = null;
722
723 convert_xml_button1.setEnabled(false);
724 xsl_file1 = null;
725 convert_xml_field1.setText("");
726 convert_xml_checkbox1.setSelected(false);
727
728 convert_xml_button2.setEnabled(false);
729 xsl_file2 = null;
730 convert_xml_field2.setText("");
731 convert_xml_checkbox2.setSelected(false);
732
733 mapping_xml_checkbox.setSelected(false);
734 output_single_checkbox.setSelected(false);
735 convert_xml_button3.setEnabled(false);
736 mapping_xml_field.setText("");
737 mapping_file = null;
738
739 }
740
741 private class ProgressDialog
742 extends ModalDialog {
743
744 private Dimension size = new Dimension(400,110);
745
746 public ProgressDialog() {
747 super(Gatherer.g_man, Dictionary.get("ExportAsPrompt.Title"), true);
748 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
749 setSize(size);
750 JPanel content_pane = (JPanel) getContentPane();
751 JLabel progress_label = new JLabel(Dictionary.get("ExportAsPrompt.Progress_Label"));
752
753 JProgressBar progress_bar = new JProgressBar();
754 progress_bar.setIndeterminate(true);
755 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
756 GLIButton cancel_button = new GLIButton(Dictionary.get("ExportAsPrompt.Cancel"),Dictionary.get("ExportAsPrompt.Cancel_Tooltip"));
757 cancel_button.setMnemonic(KeyEvent.VK_C);
758
759 cancel_button.addActionListener(new ActionListener(){
760 public void actionPerformed(ActionEvent e){
761 cancelExporting();
762 }
763
764 });
765
766 JPanel cancel_panel = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
767 cancel_panel.add(cancel_button);
768
769 content_pane.setLayout(new BorderLayout(0,5));
770 content_pane.add(progress_label, BorderLayout.NORTH);
771 content_pane.add(progress_bar, BorderLayout.CENTER);
772 content_pane.add(cancel_panel, BorderLayout.SOUTH);
773
774 // Position
775 Rectangle frame_bounds = Gatherer.g_man.getBounds();
776 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
777 }
778 }
779 }
780
781 private class ConvertXMLCheckboxListener implements ActionListener {
782 public void actionPerformed(ActionEvent event) {
783
784 convert_xml_button1.setEnabled(convert_xml_checkbox1.isSelected());
785 convert_xml_button2.setEnabled(convert_xml_checkbox2.isSelected());
786 convert_xml_button3.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.equals("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();
851 }
852
853 public String getDescription(){
854 return "XSL 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_button1){
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}
881
882
883
884
Note: See TracBrowser for help on using the repository browser.