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

Last change on this file since 13195 was 13195, checked in by kjdon, 18 years ago

quan's changes to remove blue borders around buttons and comboboxes on macs

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