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

Last change on this file since 13320 was 13320, checked in by shaoqun, 17 years ago

added a browse button for the export directory

  • Property svn:keywords set to Author Date Id Revision
File size: 33.6 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, 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 if (collect_directory.exists()) {
593 // Now for each child directory see if it contains a .col file and
594 // if so try to load it..
595 File collections[] = collect_directory.listFiles();
596 ArrayTools.sort(collections);
597 for(int i = 0; collections != null && i < collections.length; i++) {
598 if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
599 File config_file = new File(collections[i], Utility.CONFIG_FILE);
600 if (config_file.exists()) {
601 BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
602 all_collections.add(config);
603 config = null;
604 }
605 }
606 }
607 }
608 // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
609 }
610
611
612 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
613 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
614 */
615 public synchronized void message(GShellEvent event) {
616 // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
617 String message = event.getMessage();
618 if (message.startsWith("export.pl>")) {
619 message = message.substring(13);
620 //DebugStream.println("message = "+event.getMessage());
621 error_message.append(message);
622 error_message.append("\n");
623 }
624 }
625
626 /** 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.
627 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
628 */
629 public synchronized void processBegun(GShellEvent event) {
630 // We don't care.
631 }
632 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
633 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
634 */
635 public synchronized void processComplete(GShellEvent event) {
636 successful = false;
637 if(event.getStatus() == GShell.OK) {
638 if(event.getType() == GShell.EXPORTAS) {
639 successful = true;
640 }
641 }
642 ok_button_listener.processComplete();
643 }
644
645 /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
646 private class CancelButtonListener
647 implements ActionListener {
648 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
649 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
650 */
651 public void actionPerformed(ActionEvent event) {
652 prompt.dispose();
653 }
654 }
655
656 /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
657 */
658 private class CollectionListListener
659 implements ListSelectionListener
660 {
661 /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
662 * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
663 */
664 public void valueChanged(ListSelectionEvent event)
665 {
666 // Can only export when something is ticked
667 ok_button.setEnabled(!list.isNothingTicked());
668
669 if (list.isSelectionEmpty()) {
670 // This only happens when the dialog is first entered
671 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.No_Collection"));
672 return;
673 }
674
675 collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
676 args = new String[3];
677 args[0] = collection.getCreator();
678 args[1] = collection.getMaintainer();
679 args[2] = collection.getDescription();
680 details_textarea.setText(Dictionary.get("DeleteCollectionPrompt.Details", args));
681 details_textarea.setCaretPosition(0);
682 }
683 }
684
685
686 /** The OK button listener implementation. */
687 private class OKButtonListener
688 implements ActionListener {
689 private Component glass_pane;
690 private MouseListener mouse_blocker_listener;
691 private ProgressDialog progress_dialog;
692
693 /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
694 * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
695 * @see org.greenstone.gatherer.Configuration
696 * @see org.greenstone.gatherer.Gatherer
697 * @see org.greenstone.gatherer.util.Utility
698 */
699 public void actionPerformed(ActionEvent event) {
700 ///ystem.err.println("OK Clicked");
701 // Make sure there are some colls specified
702 selected_collections = list.getTicked();
703 error_message = new StringBuffer();
704
705 // Set the cursor to hourglass
706 glass_pane = getGlassPane();
707 mouse_blocker_listener = new MouseAdapter() {};
708 glass_pane.addMouseListener(mouse_blocker_listener);
709 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
710 glass_pane.setVisible(true);
711
712 // Export the selected collection.
713 ///ystem.err.println("Exporting As for named collections");
714 exportAsCollections();
715
716 // Show progress dialog
717 ///ystem.err.println("Showing progress dialog");
718 progress_dialog = new ProgressDialog();
719 progress_dialog.setVisible(true);
720 }
721
722 public void processComplete() {
723 ///ystem.err.println("Process complete");
724 // Dispose of progress dialog
725
726
727 progress_dialog.setVisible(false);
728 progress_dialog.dispose();
729 progress_dialog = null;
730
731 // unset the cursor
732 glass_pane.setVisible(false);
733 glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
734 glass_pane.removeMouseListener(mouse_blocker_listener);
735 glass_pane = null;
736 mouse_blocker_listener= null;
737
738 if (successful) {
739 resultPrompt(true, error_message.toString());
740 } else {
741 resultPrompt(false, error_message.toString());
742 }
743 error_message = null;
744
745 convert_xml_button1.setEnabled(false);
746 xsl_file1 = null;
747 convert_xml_field1.setText("");
748 convert_xml_checkbox1.setSelected(false);
749
750 convert_xml_button2.setEnabled(false);
751 xsl_file2 = null;
752 convert_xml_field2.setText("");
753 convert_xml_checkbox2.setSelected(false);
754
755 mapping_xml_checkbox.setSelected(false);
756 output_single_checkbox.setSelected(false);
757 convert_xml_button3.setEnabled(false);
758 mapping_xml_field.setText("");
759 mapping_file = null;
760
761 }
762
763 private class ProgressDialog
764 extends ModalDialog {
765
766 private Dimension size = new Dimension(400,110);
767
768 public ProgressDialog() {
769 super(Gatherer.g_man, Dictionary.get("ExportAsPrompt.Title"), true);
770 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
771 setSize(size);
772 JPanel content_pane = (JPanel) getContentPane();
773 JLabel progress_label = new JLabel(Dictionary.get("ExportAsPrompt.Progress_Label"));
774
775 JProgressBar progress_bar = new JProgressBar();
776 progress_bar.setIndeterminate(true);
777 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
778 GLIButton cancel_button = new GLIButton(Dictionary.get("ExportAsPrompt.Cancel"),Dictionary.get("ExportAsPrompt.Cancel_Tooltip"));
779 cancel_button.setMnemonic(KeyEvent.VK_C);
780
781 cancel_button.addActionListener(new ActionListener(){
782 public void actionPerformed(ActionEvent e){
783 cancelExporting();
784 }
785
786 });
787
788 JPanel cancel_panel = new JPanel(new FlowLayout(FlowLayout.CENTER,0,0));
789 cancel_panel.add(cancel_button);
790
791 content_pane.setLayout(new BorderLayout(0,5));
792 content_pane.add(progress_label, BorderLayout.NORTH);
793 content_pane.add(progress_bar, BorderLayout.CENTER);
794 content_pane.add(cancel_panel, BorderLayout.SOUTH);
795
796 // Position
797 Rectangle frame_bounds = Gatherer.g_man.getBounds();
798 setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
799 }
800 }
801 }
802
803 private class ConvertXMLCheckboxListener implements ActionListener {
804 public void actionPerformed(ActionEvent event) {
805
806 convert_xml_button1.setEnabled(convert_xml_checkbox1.isSelected());
807 convert_xml_button2.setEnabled(convert_xml_checkbox2.isSelected());
808 convert_xml_button3.setEnabled(mapping_xml_checkbox.isSelected());
809
810 }
811 }
812
813
814
815 private class SaveasListener implements ActionListener {
816
817 public void actionPerformed(ActionEvent event) {
818
819 convert_xml_checkbox1.setSelected(false);
820 convert_xml_checkbox2.setSelected(false);
821 mapping_xml_checkbox.setSelected(false);
822 output_single_checkbox.setSelected(false);
823
824 convert_xml_button1.setEnabled(false);
825 convert_xml_button2.setEnabled(false);
826 convert_xml_button3.setEnabled(false);
827
828 convert_xml_field1.setText("");
829 convert_xml_field2.setText("");
830 mapping_xml_field.setText("");
831
832 String saveas = (String)saveas_combobox.getSelectedItem();
833
834 if (convert_xml_pane.getComponentCount() > 1){
835 convert_xml_pane.remove(1);
836 if (convert_xml_pane.getComponentCount() > 1){
837 convert_xml_pane.remove(1);
838 }
839 }
840
841 if (!saveas.equals("METS")){
842
843 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",(String)plugoutMap.get(saveas)));
844 if (saveas.equals("MARCXML")){
845 convert_xml_pane.add(mapping_xml_pane);
846 convert_xml_pane.add(output_single_checkbox);
847 }
848 }
849 else{
850 String[] docs = ((String)plugoutMap.get(saveas)).split(",");
851 convert_xml_checkbox1.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[0]));
852 convert_xml_checkbox2.setText(Dictionary.get("ExportAsPrompt.ApplyXSL",docs[1]));
853 convert_xml_pane.add(convert_xml_pane2);
854 }
855
856 convert_xml_pane.revalidate();
857 convert_xml_pane.repaint();
858 instructions_pane.revalidate();
859 instructions_pane.repaint();
860
861 }
862
863 }
864
865 private class ConvertXMLButtonListener implements ActionListener {
866 public void actionPerformed(ActionEvent event) {
867 JFileChooser chooser = new JFileChooser();
868 // Note: source for ExampleFileFilter can be found in FileChooserDemo,
869 // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
870 javax.swing.filechooser.FileFilter filter = new javax.swing.filechooser.FileFilter(){
871 public boolean accept(File f){
872 return f.getPath().endsWith(".xsl")||f.isDirectory()||f.getPath().endsWith(".xml");
873 }
874
875 public String getDescription(){
876 return "XSL or XML file";
877 }
878 };
879
880 chooser.setFileFilter(filter);
881 int returnVal = chooser.showOpenDialog(prompt);
882
883 if(returnVal == JFileChooser.APPROVE_OPTION) {
884 if (event.getSource() == convert_xml_button1){
885
886 xsl_file1 = chooser.getSelectedFile();
887 convert_xml_field1.setText(xsl_file1.getPath());
888 }
889 else if (event.getSource() == convert_xml_button2){
890 xsl_file2 = chooser.getSelectedFile();
891 convert_xml_field2.setText(xsl_file2.getPath());
892
893 }
894 else {
895 mapping_file = chooser.getSelectedFile();
896 mapping_xml_field.setText(mapping_file.getPath());
897 }
898 }
899 }
900 }
901
902 private class FolderButtonListener implements ActionListener {
903 public void actionPerformed(ActionEvent event) {
904 JFileChooser chooser = new JFileChooser();
905 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
906
907 int returnVal = chooser.showOpenDialog(prompt);
908
909 if(returnVal == JFileChooser.APPROVE_OPTION) {
910 File folder_name = chooser.getSelectedFile();
911 title_field.setText(folder_name.getPath());
912 }
913
914 }
915 }
916}
917
918
919
920
921
Note: See TracBrowser for help on using the repository browser.