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 | */
|
---|
37 | package org.greenstone.gatherer.gui;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import java.util.ArrayList;
|
---|
43 | import javax.swing.*;
|
---|
44 | import javax.swing.event.*;
|
---|
45 | import org.greenstone.gatherer.Configuration;
|
---|
46 | import org.greenstone.gatherer.DebugStream;
|
---|
47 | import org.greenstone.gatherer.Dictionary;
|
---|
48 | import org.greenstone.gatherer.Gatherer;
|
---|
49 | import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
|
---|
50 | import org.greenstone.gatherer.shell.GShell;
|
---|
51 | import org.greenstone.gatherer.shell.GShellEvent;
|
---|
52 | import org.greenstone.gatherer.shell.GShellListener;
|
---|
53 | import org.greenstone.gatherer.util.ArrayTools;
|
---|
54 | import org.greenstone.gatherer.util.CheckList;
|
---|
55 | import org.greenstone.gatherer.util.CheckListEntry;
|
---|
56 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
57 | import org.greenstone.gatherer.util.Utility;
|
---|
58 |
|
---|
59 | /** This class provides the functionality to export a set of current
|
---|
60 | * collections from the GSDLHOME/collect/ directory to various formats
|
---|
61 | * (hence ExportAs) using export.pl. The user chooses the collection from a
|
---|
62 | * list, where each entry also displays details about itself, confirms the
|
---|
63 | * delete of a collection by checking a checkbox then presses the ok button
|
---|
64 | * to actually delete the collection.
|
---|
65 | * Copied from WriteCDImagePrompt
|
---|
66 | * @author John Thompson, Greenstone Digital Library, University of Waikato
|
---|
67 | * @version 2.3
|
---|
68 | */
|
---|
69 | public class ExportAsPrompt
|
---|
70 | extends ModalDialog
|
---|
71 | implements GShellListener {
|
---|
72 |
|
---|
73 | static final private Dimension LABEL_SIZE = new Dimension(120, 25);
|
---|
74 |
|
---|
75 | private OKButtonListener ok_button_listener;
|
---|
76 |
|
---|
77 | private JLabel saveas_label = null;
|
---|
78 | private JComboBox saveas_combobox = null;
|
---|
79 |
|
---|
80 | private ArrayList all_collections = null;
|
---|
81 | private ArrayList selected_collections = null;
|
---|
82 | /** The list of collections to include in exported cd-rom/dvd image */
|
---|
83 | private CheckList list = null;
|
---|
84 | /** The currently selected collection for deletion. */
|
---|
85 | private BasicCollectionConfiguration collection = null;
|
---|
86 | /** A reference to ourself so any inner-classes can dispose of us. */
|
---|
87 | private ExportAsPrompt prompt = null;
|
---|
88 | /** The close button, which exits the prompt without deleting anything. */
|
---|
89 | private JButton cancel_button = null;
|
---|
90 | /** The ok button which causes the selected collection to be deleted. */
|
---|
91 | private JButton ok_button = null;
|
---|
92 | /** The label above details. */
|
---|
93 | private JLabel details_label = null;
|
---|
94 | /** The label above the list. */
|
---|
95 | private JLabel list_label = null;
|
---|
96 | /** The text area used to display details about the collection selected. */
|
---|
97 | private JTextArea details_textarea = null;
|
---|
98 | /** The text area used to display instructions for the cd-rom/dvd export */
|
---|
99 | private JTextArea instructions_textarea;
|
---|
100 | /** A string array used to pass arguments to the phrase retrieval method. */
|
---|
101 | private JTextField title_field = null;
|
---|
102 | private JLabel title_label = null;
|
---|
103 | private String args[] = null;
|
---|
104 | private String cd_title = null;
|
---|
105 | /** whether the exporting was successful or not */
|
---|
106 | private boolean successful = false;
|
---|
107 | /** whether we are trying to export or not */
|
---|
108 | private boolean exporting = false;
|
---|
109 | /** the error message if any */
|
---|
110 | private StringBuffer error_message = null;
|
---|
111 | /** The size of the export prompt screen. */
|
---|
112 | public static final Dimension SIZE = new Dimension(500, 500);
|
---|
113 |
|
---|
114 | /** Constructor.
|
---|
115 | * @see org.greenstone.gatherer.collection.ExportAsPrompt.CancelButtonListener
|
---|
116 | * @see org.greenstone.gatherer.collection.ExportAsPrompt.CollectionListListener
|
---|
117 | * @see org.greenstone.gatherer.collection.ExportAsPrompt.OKButtonListener
|
---|
118 | */
|
---|
119 | public ExportAsPrompt() {
|
---|
120 | super(Gatherer.g_man, true);
|
---|
121 | cancel_button = new GLIButton();
|
---|
122 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
123 | Dictionary.setBoth(cancel_button, "General.Close", "General.Close_Tooltip");
|
---|
124 | details_textarea = new JTextArea();
|
---|
125 | details_textarea.setEditable(false);
|
---|
126 | Dictionary.setText(details_textarea, "DeleteCollectionPrompt.No_Collection");
|
---|
127 | details_label = new JLabel();
|
---|
128 | Dictionary.setText(details_label, "DeleteCollectionPrompt.Collection_Details");
|
---|
129 |
|
---|
130 | instructions_textarea = new JTextArea();
|
---|
131 | instructions_textarea.setCaretPosition(0);
|
---|
132 | instructions_textarea.setEditable(false);
|
---|
133 | instructions_textarea.setLineWrap(true);
|
---|
134 | instructions_textarea.setRows(4);
|
---|
135 | instructions_textarea.setWrapStyleWord(true);
|
---|
136 | Dictionary.registerText(instructions_textarea, "ExportAsPrompt.Instructions");
|
---|
137 |
|
---|
138 | // Save As
|
---|
139 | ArrayList saveas_formats = new ArrayList();
|
---|
140 | saveas_formats.add("METS");
|
---|
141 | saveas_formats.add("DSpace");
|
---|
142 |
|
---|
143 | saveas_label = new JLabel();
|
---|
144 | //saveas_label.setPreferredSize(LABEL_SIZE);
|
---|
145 | Dictionary.registerText(saveas_label, "ExportAsPrompt.SaveAs");
|
---|
146 | saveas_combobox = new JComboBox(saveas_formats.toArray());
|
---|
147 | Dictionary.registerTooltip(saveas_combobox, "ExportAsPrompt.SaveAs_Tooltip");
|
---|
148 |
|
---|
149 | all_collections = new ArrayList();
|
---|
150 | list = new CheckList(true);
|
---|
151 | list_label = new JLabel();
|
---|
152 | Dictionary.setText(list_label, "DeleteCollectionPrompt.Collection_List");
|
---|
153 | ok_button = new GLIButton();
|
---|
154 | ok_button.setMnemonic(KeyEvent.VK_D);
|
---|
155 | Dictionary.setBoth(ok_button, "ExportAsPrompt.Export", "ExportAsPrompt.Export_Tooltip");
|
---|
156 |
|
---|
157 | title_field = new JTextField();
|
---|
158 | // Dictionary.setTooltip(title_field, "ExportAsPrompt.Export_Name_Tooltip");
|
---|
159 | title_label = new JLabel();
|
---|
160 | Dictionary.setText(title_label, "ExportAsPrompt.Export_Name");
|
---|
161 | scanForCollections();
|
---|
162 | list.setListData(all_collections);
|
---|
163 |
|
---|
164 | prompt = this;
|
---|
165 | setSize(SIZE);
|
---|
166 | Dictionary.setText(this, "ExportAsPrompt.Title");
|
---|
167 |
|
---|
168 | setJMenuBar(new SimpleMenuBar("0")); // need to find an appropriate help page to open at
|
---|
169 | cancel_button.addActionListener(new CancelButtonListener());
|
---|
170 | list.addListSelectionListener(new CollectionListListener());
|
---|
171 | list.clearSelection();
|
---|
172 | list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
173 | ok_button_listener = new OKButtonListener();
|
---|
174 | ok_button.addActionListener(ok_button_listener);
|
---|
175 | ok_button.setEnabled(false);
|
---|
176 | //title.getDocument().addDocumentListener(new DocumentListener());
|
---|
177 | }
|
---|
178 |
|
---|
179 | /** Destructor. */
|
---|
180 | public void destroy() {
|
---|
181 | saveas_label = null;
|
---|
182 | saveas_combobox = null;
|
---|
183 | all_collections.clear();
|
---|
184 | all_collections = null;
|
---|
185 | cancel_button = null;
|
---|
186 | details_textarea = null;
|
---|
187 | details_label = null;
|
---|
188 | list = null;
|
---|
189 | ok_button = null;
|
---|
190 | prompt = null;
|
---|
191 | if (selected_collections!=null) {
|
---|
192 | selected_collections.clear();
|
---|
193 | selected_collections = null;
|
---|
194 | }
|
---|
195 | title_field = null;
|
---|
196 | title_label = null;
|
---|
197 | }
|
---|
198 |
|
---|
199 | /** This method causes the modal prompt to be displayed.
|
---|
200 | * returns true if it has exported the collections that are currently selected */
|
---|
201 | public boolean display() {
|
---|
202 | // Top pane
|
---|
203 | JPanel instructions_pane = new JPanel(new BorderLayout());
|
---|
204 | instructions_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
|
---|
205 | instructions_pane.add(new JScrollPane(instructions_textarea), BorderLayout.CENTER);
|
---|
206 |
|
---|
207 | title_label.setBorder(BorderFactory.createEmptyBorder(0,5,0,15));
|
---|
208 |
|
---|
209 | JPanel title_pane = new JPanel(new BorderLayout());
|
---|
210 | title_pane.add(title_label, BorderLayout.WEST);
|
---|
211 | title_pane.add(title_field, BorderLayout.CENTER);
|
---|
212 | instructions_pane.add(title_pane, BorderLayout.CENTER);
|
---|
213 |
|
---|
214 | // Save as pane
|
---|
215 | JPanel saveas_pane = new JPanel(new BorderLayout());
|
---|
216 | saveas_pane.setLayout(new BorderLayout());
|
---|
217 | saveas_pane.add(saveas_label, BorderLayout.WEST);
|
---|
218 | saveas_pane.add(saveas_combobox, BorderLayout.CENTER);
|
---|
219 | instructions_pane.add(saveas_pane, BorderLayout.SOUTH);
|
---|
220 |
|
---|
221 | // Central pane
|
---|
222 | JPanel list_pane = new JPanel(new BorderLayout());
|
---|
223 | list_pane.add(list_label, BorderLayout.NORTH);
|
---|
224 | list_pane.add(new JScrollPane(list), BorderLayout.CENTER);
|
---|
225 | list_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 0));
|
---|
226 |
|
---|
227 | JPanel details_pane = new JPanel(new BorderLayout());
|
---|
228 | details_pane.add(details_label, BorderLayout.NORTH);
|
---|
229 | details_pane.add(new JScrollPane(details_textarea), BorderLayout.CENTER);
|
---|
230 | details_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
231 |
|
---|
232 | JPanel central_pane = new JPanel(new GridLayout(2, 1));
|
---|
233 | central_pane.add(list_pane);
|
---|
234 | central_pane.add(details_pane);
|
---|
235 | central_pane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
---|
236 |
|
---|
237 | // Lower pane
|
---|
238 | JPanel button_pane = new JPanel(new GridLayout(1, 2));
|
---|
239 | button_pane.add(ok_button);
|
---|
240 | button_pane.add(cancel_button);
|
---|
241 | button_pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
---|
242 |
|
---|
243 | JPanel lower_pane = new JPanel(new BorderLayout());
|
---|
244 | lower_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
245 | lower_pane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
|
---|
246 |
|
---|
247 | // Final.
|
---|
248 | JPanel content_pane = (JPanel)this.getContentPane();
|
---|
249 | content_pane.setLayout(new BorderLayout());
|
---|
250 | content_pane.add(instructions_pane, BorderLayout.NORTH);
|
---|
251 | content_pane.add(central_pane, BorderLayout.CENTER);
|
---|
252 | content_pane.add(lower_pane, BorderLayout.SOUTH);
|
---|
253 |
|
---|
254 | // Center and display.
|
---|
255 | Dimension screen_size = Configuration.screen_size;
|
---|
256 | this.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
257 | this.setVisible(true); // blocks until the dialog is killed
|
---|
258 | return true;
|
---|
259 |
|
---|
260 | }
|
---|
261 |
|
---|
262 |
|
---|
263 | /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
|
---|
264 | * @see org.greenstone.gatherer.Configuration
|
---|
265 | * @see org.greenstone.gatherer.Gatherer
|
---|
266 | * @see org.greenstone.gatherer.collection.Collection
|
---|
267 | * @see org.greenstone.gatherer.gui.BuildOptions
|
---|
268 | * @see org.greenstone.gatherer.shell.GShell
|
---|
269 | * @see org.greenstone.gatherer.shell.GShellListener
|
---|
270 | * @see org.greenstone.gatherer.shell.GShellProgressMonitor
|
---|
271 | * @see org.greenstone.gatherer.util.Utility
|
---|
272 | */
|
---|
273 | public void exportAsCollections() {
|
---|
274 | DebugStream.println("ExportAsPrompt.exportAsCollections()");
|
---|
275 |
|
---|
276 | int num_collections = selected_collections.size();
|
---|
277 | if (num_collections == 0) return;
|
---|
278 | cd_title = title_field.getText();
|
---|
279 | cd_title = cd_title.trim();
|
---|
280 | cd_title = cd_title.replaceAll("\"","");
|
---|
281 | int num_args = num_collections + 9;
|
---|
282 | boolean has_title = false;
|
---|
283 | if (!cd_title.equals("")) {
|
---|
284 | num_args += 2;
|
---|
285 | has_title = true;
|
---|
286 | }
|
---|
287 | String args[];
|
---|
288 | int next_arg = 0;
|
---|
289 | if(Utility.isWindows()) {
|
---|
290 | args = new String[num_args+2];
|
---|
291 | args[0] = Configuration.perl_path;
|
---|
292 | args[1] = "-S";
|
---|
293 | next_arg = 2;
|
---|
294 | } else {
|
---|
295 | args = new String[num_args];
|
---|
296 | }
|
---|
297 |
|
---|
298 | String export_type = (String)saveas_combobox.getSelectedItem();
|
---|
299 |
|
---|
300 | args[next_arg] = Configuration.getScriptPath() + "export.pl";
|
---|
301 | next_arg++;
|
---|
302 | args[next_arg] = "-gli"; next_arg++;
|
---|
303 | args[next_arg] = "-language"; next_arg++;
|
---|
304 | args[next_arg] = Configuration.getLanguage(); next_arg++;
|
---|
305 | args[next_arg] = "-removeold"; next_arg++;
|
---|
306 | args[next_arg] = "-saveas"; next_arg++;
|
---|
307 | args[next_arg] = export_type; next_arg++;
|
---|
308 |
|
---|
309 | args[next_arg] = "-exportdir"; next_arg++;
|
---|
310 | args[next_arg] = Configuration.gsdl_path+"tmp"+File.separator;
|
---|
311 | if(!has_title) {
|
---|
312 | args[next_arg] += "exported_" + export_type;
|
---|
313 | } else {
|
---|
314 | args[next_arg] += "exported_"+cd_title.replaceAll("\\s","");
|
---|
315 | }
|
---|
316 | next_arg++;
|
---|
317 |
|
---|
318 |
|
---|
319 | for (int i=0; i<num_collections;i++,next_arg++) {
|
---|
320 | args[next_arg] = ((BasicCollectionConfiguration)selected_collections.get(i)).getShortName();
|
---|
321 | }
|
---|
322 |
|
---|
323 | /*
|
---|
324 | args[next_arg] = ((BasicCollectionConfiguration)selected_collections.get(0)).getShortName(); next_arg++;
|
---|
325 | */
|
---|
326 |
|
---|
327 | DebugStream.print("export command = ");
|
---|
328 | for (int i=0; i<args.length; i++) {
|
---|
329 | DebugStream.print(args[i]+" ");
|
---|
330 | System.err.print(args[i]+" ");
|
---|
331 | }
|
---|
332 | DebugStream.println("");
|
---|
333 | System.err.println("");
|
---|
334 |
|
---|
335 | GShell process = new GShell(args, GShell.EXPORTAS, 3, this, null, GShell.GSHELL_EXPORTAS);
|
---|
336 | process.start();
|
---|
337 | //process.run();
|
---|
338 | DebugStream.println("ExportAsPrompt.exportAsCollections().return");
|
---|
339 |
|
---|
340 | }
|
---|
341 |
|
---|
342 | /** Shows an export complete prompt.
|
---|
343 | * @param success A <strong>boolean</strong> indicating if the collection was successfully deleted.
|
---|
344 | * @see org.greenstone.gatherer.collection.Collection
|
---|
345 | */
|
---|
346 | public void resultPrompt(boolean success, String extra) {
|
---|
347 | args = new String[2];
|
---|
348 | StringBuffer coll_names = new StringBuffer();
|
---|
349 | for (int i=0; i<selected_collections.size();i++) {
|
---|
350 | if (i>0) {
|
---|
351 | coll_names.append(", ");
|
---|
352 | }
|
---|
353 | BasicCollectionConfiguration complete_collection = (BasicCollectionConfiguration)selected_collections.get(i);
|
---|
354 | coll_names.append(complete_collection.getName() + StaticStrings.SPACE_CHARACTER + StaticStrings.OPEN_PARENTHESIS_CHARACTER + complete_collection.getShortName() + StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
|
---|
355 | complete_collection = null;
|
---|
356 | }
|
---|
357 |
|
---|
358 | args[0] = coll_names.toString();
|
---|
359 |
|
---|
360 | args[1] = Configuration.gsdl_path+"tmp"+File.separator;
|
---|
361 | if(cd_title.equals("")) {
|
---|
362 | String export_type = (String)saveas_combobox.getSelectedItem();
|
---|
363 | args[1] += "exported_" + export_type;
|
---|
364 | } else {
|
---|
365 | args[1] += "exported_"+cd_title.replaceAll("\\s","");
|
---|
366 | }
|
---|
367 |
|
---|
368 | String title;
|
---|
369 | String label;
|
---|
370 | String details;
|
---|
371 |
|
---|
372 | if (success) {
|
---|
373 | String successMessage
|
---|
374 | = (selected_collections.size()==1)
|
---|
375 | ? "ExportAsPrompt.Successful_ExportOne"
|
---|
376 | : "ExportAsPrompt.Successful_ExportMany";
|
---|
377 |
|
---|
378 | title = Dictionary.get("ExportAsPrompt.Successful_Title");
|
---|
379 | label = Dictionary.get(successMessage, args);
|
---|
380 | details = Dictionary.get("ExportAsPrompt.Successful_Details", args);
|
---|
381 | } else {
|
---|
382 | String failedMessage
|
---|
383 | = (selected_collections.size()==1)
|
---|
384 | ? "ExportAsPrompt.Failed_ExportOne"
|
---|
385 | : "ExportAsPrompt.Failed_ExportMany";
|
---|
386 |
|
---|
387 | title = Dictionary.get("ExportAsPrompt.Failed_Title");
|
---|
388 | label = Dictionary.get(failedMessage, args);
|
---|
389 | details = Dictionary.get("ExportAsPrompt.Failed_Details", args);
|
---|
390 | }
|
---|
391 | SimpleResultDialog result_dialog = new SimpleResultDialog(title, label, details);
|
---|
392 | result_dialog.setVisible(true); // Blocks
|
---|
393 | result_dialog.dispose();
|
---|
394 | result_dialog = null;
|
---|
395 | }
|
---|
396 |
|
---|
397 | /** Method to scan the collect directory retrieving and reloading each collection it finds, while building the list of known collections.
|
---|
398 | * @see org.greenstone.gatherer.Configuration
|
---|
399 | * @see org.greenstone.gatherer.Gatherer
|
---|
400 | * @see org.greenstone.gatherer.util.ArrayTools
|
---|
401 | * @see org.greenstone.gatherer.util.Utility
|
---|
402 | */
|
---|
403 | private void scanForCollections() {
|
---|
404 | // Start at the collect dir.
|
---|
405 | File collect_directory = new File(Gatherer.getCollectDirectoryPath());
|
---|
406 | if (collect_directory.exists()) {
|
---|
407 | // Now for each child directory see if it contains a .col file and
|
---|
408 | // if so try to load it..
|
---|
409 | File collections[] = collect_directory.listFiles();
|
---|
410 | ArrayTools.sort(collections);
|
---|
411 | for(int i = 0; collections != null && i < collections.length; i++) {
|
---|
412 | if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
|
---|
413 | File config_file = new File(collections[i], Utility.CONFIG_FILE);
|
---|
414 | if (config_file.exists()) {
|
---|
415 | BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
|
---|
416 | all_collections.add(config);
|
---|
417 | config = null;
|
---|
418 | }
|
---|
419 | }
|
---|
420 | }
|
---|
421 | }
|
---|
422 | // Otherwise the collect directory doesn't actually exist, so there ain't much we can do.
|
---|
423 | }
|
---|
424 |
|
---|
425 |
|
---|
426 | /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
|
---|
427 | * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
|
---|
428 | */
|
---|
429 | public synchronized void message(GShellEvent event) {
|
---|
430 | // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars)
|
---|
431 | String message = event.getMessage();
|
---|
432 | if (message.startsWith("export.pl>")) {
|
---|
433 | message = message.substring(13);
|
---|
434 | //DebugStream.println("message = "+event.getMessage());
|
---|
435 | error_message.append(message);
|
---|
436 | error_message.append("\n");
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | /** 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.
|
---|
441 | * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
|
---|
442 | */
|
---|
443 | public synchronized void processBegun(GShellEvent event) {
|
---|
444 | // We don't care.
|
---|
445 | }
|
---|
446 | /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
|
---|
447 | * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
|
---|
448 | */
|
---|
449 | public synchronized void processComplete(GShellEvent event) {
|
---|
450 | successful = false;
|
---|
451 | if(event.getStatus() == GShell.OK) {
|
---|
452 | if(event.getType() == GShell.EXPORTAS) {
|
---|
453 | successful = true;
|
---|
454 | }
|
---|
455 | }
|
---|
456 | ok_button_listener.processComplete();
|
---|
457 | }
|
---|
458 |
|
---|
459 | /** A button listener implementation, which listens for actions on the close button and disposes of the dialog when detected. */
|
---|
460 | private class CancelButtonListener
|
---|
461 | implements ActionListener {
|
---|
462 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
463 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
464 | */
|
---|
465 | public void actionPerformed(ActionEvent event) {
|
---|
466 | prompt.dispose();
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | /** This private class listens for selection events in from the list and then displays the appropriate details for that collection.
|
---|
471 | */
|
---|
472 | private class CollectionListListener
|
---|
473 | implements ListSelectionListener
|
---|
474 | {
|
---|
475 | /** Any implementation of ListSelectionListener must include this method so we can be informed when the list selection changes.
|
---|
476 | * @param event a <strong>ListSelectionEvent</strong> containing all the relevant information garnered from the event itself
|
---|
477 | */
|
---|
478 | public void valueChanged(ListSelectionEvent event)
|
---|
479 | {
|
---|
480 | // Can only export when something is ticked
|
---|
481 | ok_button.setEnabled(!list.isNothingTicked());
|
---|
482 |
|
---|
483 | if (list.isSelectionEmpty()) {
|
---|
484 | // This only happens when the dialog is first entered
|
---|
485 | Dictionary.setText(details_textarea, "DeleteCollectionPrompt.No_Collection");
|
---|
486 | return;
|
---|
487 | }
|
---|
488 |
|
---|
489 | collection = (BasicCollectionConfiguration) ((CheckListEntry) list.getSelectedValue()).getObject();
|
---|
490 | args = new String[3];
|
---|
491 | args[0] = collection.getCreator();
|
---|
492 | args[1] = collection.getMaintainer();
|
---|
493 | args[2] = collection.getDescription();
|
---|
494 | Dictionary.setText(details_textarea, "DeleteCollectionPrompt.Details", args);
|
---|
495 | details_textarea.setCaretPosition(0);
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 |
|
---|
500 | /** The OK button listener implementation. */
|
---|
501 | private class OKButtonListener
|
---|
502 | implements ActionListener {
|
---|
503 | private Component glass_pane;
|
---|
504 | private MouseListener mouse_blocker_listener;
|
---|
505 | private ProgressDialog progress_dialog;
|
---|
506 |
|
---|
507 | /** Any implementation of ActionListener must include this method so we can be informed when the button is actioned.
|
---|
508 | * @param event An <strong>ActionEvent</strong> containing all the relevant information garnered from the event itself.
|
---|
509 | * @see org.greenstone.gatherer.Configuration
|
---|
510 | * @see org.greenstone.gatherer.Gatherer
|
---|
511 | * @see org.greenstone.gatherer.util.Utility
|
---|
512 | */
|
---|
513 | public void actionPerformed(ActionEvent event) {
|
---|
514 | ///ystem.err.println("OK Clicked");
|
---|
515 | // Make sure there are some colls specified
|
---|
516 | selected_collections = list.getTicked();
|
---|
517 | error_message = new StringBuffer();
|
---|
518 |
|
---|
519 | // Set the cursor to hourglass
|
---|
520 | glass_pane = getGlassPane();
|
---|
521 | mouse_blocker_listener = new MouseAdapter() {};
|
---|
522 | glass_pane.addMouseListener(mouse_blocker_listener);
|
---|
523 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
---|
524 | glass_pane.setVisible(true);
|
---|
525 |
|
---|
526 | // Export the selected collection.
|
---|
527 | ///ystem.err.println("Exporting As for named collections");
|
---|
528 | exportAsCollections();
|
---|
529 |
|
---|
530 | // Show progress dialog
|
---|
531 | ///ystem.err.println("Showing progress dialog");
|
---|
532 | progress_dialog = new ProgressDialog();
|
---|
533 | progress_dialog.setVisible(true);
|
---|
534 | }
|
---|
535 |
|
---|
536 | public void processComplete() {
|
---|
537 | ///ystem.err.println("Process complete");
|
---|
538 | // Dispose of progress dialog
|
---|
539 | progress_dialog.setVisible(false);
|
---|
540 | progress_dialog.dispose();
|
---|
541 | progress_dialog = null;
|
---|
542 |
|
---|
543 | // unset the cursor
|
---|
544 | glass_pane.setVisible(false);
|
---|
545 | glass_pane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
---|
546 | glass_pane.removeMouseListener(mouse_blocker_listener);
|
---|
547 | glass_pane = null;
|
---|
548 | mouse_blocker_listener= null;
|
---|
549 |
|
---|
550 | if (successful) {
|
---|
551 | resultPrompt(true, error_message.toString());
|
---|
552 | } else {
|
---|
553 | resultPrompt(false, error_message.toString());
|
---|
554 | }
|
---|
555 | error_message = null;
|
---|
556 | }
|
---|
557 |
|
---|
558 | private class ProgressDialog
|
---|
559 | extends ModalDialog {
|
---|
560 |
|
---|
561 | private Dimension size = new Dimension(400,65);
|
---|
562 |
|
---|
563 | public ProgressDialog() {
|
---|
564 | super(Gatherer.g_man, Dictionary.get("ExportAsPrompt.Title"), true);
|
---|
565 | setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
---|
566 | setSize(size);
|
---|
567 | JPanel content_pane = (JPanel) getContentPane();
|
---|
568 | JLabel progress_label = new JLabel();
|
---|
569 | Dictionary.setText(progress_label, "ExportAsPrompt.Progress_Label");
|
---|
570 | JProgressBar progress_bar = new JProgressBar();
|
---|
571 | progress_bar.setIndeterminate(true);
|
---|
572 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
573 | content_pane.setLayout(new BorderLayout());
|
---|
574 | content_pane.add(progress_label, BorderLayout.NORTH);
|
---|
575 | content_pane.add(progress_bar, BorderLayout.CENTER);
|
---|
576 | // Position
|
---|
577 | Rectangle frame_bounds = Gatherer.g_man.getBounds();
|
---|
578 | setLocation(frame_bounds.x + (frame_bounds.width - size.width) / 2, frame_bounds.y + (frame_bounds.height - size.height) / 2);
|
---|
579 | }
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 |
|
---|
584 | }
|
---|
585 |
|
---|
586 |
|
---|
587 |
|
---|
588 |
|
---|