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

Last change on this file since 14045 was 14045, checked in by xiao, 17 years ago

Changes made to look for collectionConfig.xml in gs3 mode and collect.cfg in gs2 mode, rather than presumably only for the file collect.cfg.

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