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

Last change on this file since 18372 was 18372, checked in by kjdon, 15 years ago

set the ComponentOrientation for a few things, for RTL gli

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