source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/ExportAsPrompt.java@ 18297

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

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

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