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