source: trunk/gli/src/org/greenstone/gatherer/gui/CreatePane.java@ 13531

Last change on this file since 13531 was 13326, checked in by mdewsnip, 17 years ago

Removed some unnecessary importing of the util.ZipTools class.

  • Property svn:keywords set to Author Date Id Revision
File size: 37.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
43import javax.swing.event.*;
44import javax.swing.text.*;
45import javax.swing.tree.*;
46import org.greenstone.gatherer.DebugStream;
47import org.greenstone.gatherer.Configuration;
48import org.greenstone.gatherer.Dictionary;
49import org.greenstone.gatherer.Gatherer;
50import org.greenstone.gatherer.LocalLibraryServer;
51import org.greenstone.gatherer.cdm.BuildTypeManager;
52import org.greenstone.gatherer.cdm.CollectionDesignManager;
53import org.greenstone.gatherer.collection.Collection;
54import org.greenstone.gatherer.shell.GBuildProgressMonitor;
55import org.greenstone.gatherer.shell.GImportProgressMonitor;
56import org.greenstone.gatherer.shell.GShell;
57import org.greenstone.gatherer.shell.GShellEvent;
58import org.greenstone.gatherer.shell.GShellListener;
59import org.greenstone.gatherer.shell.GShellProgressMonitor;
60import org.greenstone.gatherer.util.AppendLineOnlyFileDocument;
61import org.greenstone.gatherer.util.StaticStrings;
62import org.greenstone.gatherer.util.Utility;
63
64
65/** This class provides a GUI view showing some statistics on your current collection, and options for building it. As the collection is built this initial view is replaced with one showing progress bars and a message log of the creation process. This log can be later accessed via the options tree located in the center of the initial pane. This class is also responsible for creating the GShellProgressMonitors that are then attatched to external shell processes, and calling the methods in the CollectionManager for actually importing and building the collection. <br><BR>
66 * @author John Thompson, Greenstone Digital Library, University of Waikato
67 * @version 2.3
68 */
69public class CreatePane
70 extends JPanel
71 implements GShellListener {
72
73 static private Dimension ARGUMENT_SIZE = new Dimension(800,90);
74 /** The threshold for when the simple view is replaced by the complex one. */
75 static private final int THRESHOLD = Configuration.EXPERT_MODE;
76 /** An identifier for the control panel within the card layout. */
77 static private String CONTROL = "Control";
78 /** An identifier for the progress panel within the card layout. */
79 static private String PROGRESS = "Progress";
80 /** An identifier for the simple panel within the card layout. */
81 static private String SIMPLE = "Simple";
82
83 /** Determines the current view that should be shown for this pane. */
84 public boolean processing = false;
85 /** The options pane generates all the various option sheet configuations. */
86 public OptionsPane options_pane = null;
87 private AppendLineOnlyFileDocument document;
88 /** A card layout is used to store the separate configuration and progress panes. */
89 private CardLayout card_layout = null;
90 /** Stores a reference to the current collection. */
91 private Collection previous_collection = null;
92 /** This monitor tracks the build processes progress. */
93 private GShellProgressMonitor build_monitor = null;
94 /** This monitor tracks the import processes progress. */
95 private GShellProgressMonitor import_monitor = null;
96 /** The button for begining the building processes. */
97 private JButton build_button = null;
98 /** The button for stopping the building processes. */
99 private JButton cancel_button = null;
100 /** The button for viewing the collection. */
101 private JButton preview_button = null;
102 private JButton simple_build_button;
103 private JButton simple_cancel_button;
104 private JButton simple_preview_button;
105 /** The radio buttons for chnaging the build type (incremental/full) */
106 private JRadioButton full_build_radio_button;
107 private JRadioButton incremental_build_radio_button;
108 private JRadioButton sfull_build_radio_button;
109 private JRadioButton sincremental_build_radio_button;
110 /** The label displaying the number of documents in this collection. */
111 private JLabel document_count = null;
112 /** The label alongside the build progress bar gets some special treatment so... */
113 private JLabel progress_build_label = null;
114 /** The label alongside the import progress bar gets some special treatment so... */
115 private JLabel progress_import_label = null;
116 private JPanel bar_area;
117 /** The panel on which buttons are rendered on higher detail modes. */
118 private JPanel button_pane;
119 /** The pane which contains the controls for configuration. */
120 private JPanel control_pane = null;
121 /** The pane which has the card layout as its manager. */
122 private JPanel main_pane = null;
123 /** The pane which contains the progress information. */
124 private JPanel progress_pane = null;
125 /** The pane on the right-hand side - shows the requested options view */
126 private JPanel right = null;
127 /** The simple panel on which all of the available arguments are rendered. */
128 private JPanel sargument_configuration_panel;
129 /** The panel on which buttons are rendered on lower details modes. */
130 private JPanel sbutton_panel;
131 /** A simplified version for lower detail modes containing both the control and progress panes smooshed together. */
132 private JSplitPane simple_panel;
133 /** The lower part of the panel which is global so the log pane can be added and removed from it */
134 private JPanel slower_panel;
135 /** The inner panel of the simple pane which is global so that the bar_area can be added and removed from it. */
136 private JPanel sinner_panel;
137 /** The scrolling pane for the log. */
138 private JScrollPane log_scroll;
139 /** The scrolling pane the simple arguments are rendered within. */
140 private JScrollPane sargument_configuration_scroll;
141 /** the scrolling pane the righthand side is inside - only used for import and build options. the log and log list are not inside a scrollpane */
142 private JScrollPane scroll_pane;
143 /** The message log for the entire session. */
144 private JTextArea log_textarea;
145 /** A tree used to display the currently available option views. */
146 private OptionTree tree = null;
147 /** An array used to pass arguments with dictionary calls. */
148 private String args[] = null;
149 /** The homepage address of the current collection */
150 public String homepage = null;
151
152
153 /** The constructor creates important helper classes, and initializes all the components.
154 * @see org.greenstone.gatherer.collection.CollectionManager
155 * @see org.greenstone.gatherer.gui.BuildOptions
156 * @see org.greenstone.gatherer.gui.CreatePane.BuildButtonListener
157 * @see org.greenstone.gatherer.gui.CreatePane.CancelButtonListener
158 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
159 * @see org.greenstone.gatherer.gui.OptionsPane
160 * @see org.greenstone.gatherer.shell.GBuildProgressMonitor
161 * @see org.greenstone.gatherer.shell.GImportProgressMonitor
162 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
163 */
164 public CreatePane() {
165 Collection collection = Gatherer.c_man.getCollection();
166 log_textarea = new JTextArea();
167 log_scroll = new JScrollPane(log_textarea);
168
169 // Create components
170 card_layout = new CardLayout();
171 // Control Pane
172 control_pane = new JPanel();
173 tree = new OptionTree();
174 button_pane = new JPanel();
175
176 // Progress Pane
177 progress_pane = new JPanel(); // One owner of the bar component
178 bar_area = new JPanel(); // This component will be shared about
179
180 progress_import_label = new JLabel(Dictionary.get("CreatePane.Import_Progress"));
181
182 import_monitor = new GImportProgressMonitor();
183 Gatherer.c_man.registerImportMonitor(import_monitor);
184
185 progress_build_label = new JLabel(Dictionary.get("CreatePane.Build_Progress"));
186
187 build_monitor = new GBuildProgressMonitor(import_monitor.getSharedProgress());
188 Gatherer.c_man.registerBuildMonitor(build_monitor);
189
190 // And the simple panel
191 slower_panel = new JPanel();
192 sbutton_panel = new JPanel();
193 sinner_panel = new JPanel();
194
195 //Radio buttons
196 incremental_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Minimal_Build"));
197 incremental_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Minimal_Build_Tooltip"));
198 full_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Full_Build"));
199 full_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Full_Build_Tooltip"));
200 sincremental_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Minimal_Build"));
201 sincremental_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Minimal_Build_Tooltip"));
202 sfull_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Full_Build"));
203 sfull_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Full_Build_Tooltip"));
204
205
206 // Buttons
207 BuildButtonListener bbl = new BuildButtonListener();
208 CancelButtonListener cbl = new CancelButtonListener();
209
210 build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip"));
211 build_button.addActionListener(bbl);
212
213 cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip"));
214 cancel_button.addActionListener(cbl);
215 cancel_button.setEnabled(false);
216
217 preview_button = new PreviewButton(Dictionary.get("CreatePane.Preview_Collection"), Dictionary.get("CreatePane.Preview_Collection_Tooltip"));
218 //preview_button.addActionListener(pbl);
219 if(Gatherer.c_man != null) {
220 preview_button.setEnabled(Gatherer.c_man.built());
221 }
222 else {
223 preview_button.setEnabled(false);
224 }
225
226 simple_build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip"));
227 simple_build_button.addActionListener(bbl);
228
229 simple_cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip"));
230 simple_cancel_button.addActionListener(cbl);
231 simple_cancel_button.setEnabled(false);
232
233 simple_preview_button = new PreviewButton(Dictionary.get("CreatePane.Preview_Collection"), Dictionary.get("CreatePane.Preview_Collection_Tooltip"));
234 //simple_preview_button.addActionListener(pbl);
235 if(Gatherer.c_man != null) {
236 simple_preview_button.setEnabled(Gatherer.c_man.built());
237 }
238 else {
239 simple_preview_button.setEnabled(false);
240 }
241
242 bbl = null;
243 cbl = null;
244 //pbl = null;
245 }
246
247
248 public void destroy() {
249 if(document != null) {
250 document.destroy();
251 }
252 }
253
254 /** This method is called to actually layout the components.
255 * @see org.greenstone.gatherer.Configuration
256 * @see org.greenstone.gatherer.Gatherer
257 */
258 public void display() {
259
260 int current_mode = Configuration.getMode();
261
262 //Complete/incremental build options panel
263 //For some reason I need to create seperate objects for each mode. Is there a better way??
264 ButtonGroup build_type_group = new ButtonGroup();
265 build_type_group.add(incremental_build_radio_button);
266 full_build_radio_button.setSelected(true);
267 build_type_group.add(full_build_radio_button);
268 ButtonGroup sbuild_type_group = new ButtonGroup();
269 sbuild_type_group.add(sincremental_build_radio_button);
270 sfull_build_radio_button.setSelected(true);
271 sbuild_type_group.add(sfull_build_radio_button);
272 JPanel build_type_pane = new JPanel(new GridLayout(2,1));
273 build_type_pane.add(full_build_radio_button);
274 build_type_pane.add(incremental_build_radio_button);
275 JPanel sbuild_type_pane = new JPanel(new GridLayout(2,1));
276 sbuild_type_pane.add(sfull_build_radio_button);
277 sbuild_type_pane.add(sincremental_build_radio_button);
278
279
280
281 // Build control_pane
282 JPanel left = new JPanel();
283 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
284 left.setLayout(new BorderLayout());
285 left.add(tree, BorderLayout.CENTER);
286 left.add(build_type_pane, BorderLayout.SOUTH);
287 //left.add(full_build_radio_button, BorderLayout.SOUTH);
288
289 right = new JPanel();
290 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
291 right.setLayout(new BorderLayout());
292
293 JPanel options_area = new JPanel();
294 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(Dictionary.get("CreatePane.Options_Title"))));
295 options_area.setLayout(new BorderLayout());
296 options_area.add(left, BorderLayout.WEST);
297 options_area.add(right, BorderLayout.CENTER);
298
299 button_pane = new JPanel();
300 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
301 button_pane.setLayout(new GridLayout(1,4));
302 button_pane.add(build_button);
303 button_pane.add(cancel_button);
304 button_pane.add(preview_button);
305
306 control_pane.setLayout(new BorderLayout());
307 control_pane.add(options_area, BorderLayout.CENTER);
308 control_pane.add(button_pane, BorderLayout.SOUTH);
309
310 // Build progress_pane
311 JPanel labels_pane = new JPanel();
312 labels_pane.setLayout(new GridLayout(2,1,0,5));
313 labels_pane.add(progress_import_label);
314 labels_pane.add(progress_build_label);
315
316 JPanel monitors_pane = new JPanel();
317 monitors_pane.setLayout(new GridLayout(2,1,0,5));
318 monitors_pane.add(import_monitor.getProgress());
319 monitors_pane.add(build_monitor.getProgress());
320
321 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
322 bar_area.setLayout(new BorderLayout(5,5));
323 bar_area.add(labels_pane, BorderLayout.WEST);
324 bar_area.add(monitors_pane, BorderLayout.CENTER);
325
326 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
327 progress_pane.setLayout(new BorderLayout());
328 progress_pane.add(bar_area, BorderLayout.NORTH);
329 if(current_mode >= THRESHOLD) {
330 progress_pane.add(log_scroll, BorderLayout.CENTER);
331 }
332
333 // Simple panel
334 sbutton_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
335 sbutton_panel.setLayout(new GridLayout(1,3));
336 sbutton_panel.add(simple_build_button);
337 sbutton_panel.add(simple_cancel_button);
338 sbutton_panel.add(simple_preview_button);
339
340 JPanel simple_bar_area = new JPanel(new GridLayout(2,1));
341 simple_bar_area.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
342 simple_bar_area.add(import_monitor.getSharedProgress());
343 simple_bar_area.add(sbutton_panel);
344
345 sinner_panel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
346 sinner_panel.setLayout(new BorderLayout());
347 sinner_panel.add(sbuild_type_pane, BorderLayout.WEST);
348 //sinner_panel.add(full_build_radio_button, BorderLayout.WEST);
349 sinner_panel.add(simple_bar_area, BorderLayout.CENTER);
350
351 if(options_pane != null) {
352 sargument_configuration_panel = options_pane.buildImport(null);
353 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
354 }
355 else {
356 sargument_configuration_panel = new JPanel();
357 }
358 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
359 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
360
361 slower_panel.setLayout(new BorderLayout());
362 slower_panel.add(sinner_panel, BorderLayout.NORTH);
363 if(current_mode < THRESHOLD) {
364 slower_panel.add(log_scroll, BorderLayout.CENTER);
365 }
366
367 simple_panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, sargument_configuration_scroll, slower_panel);
368 // Main pane
369 main_pane = new JPanel(card_layout);
370 if(current_mode < THRESHOLD) { // Simple mode - add first
371 main_pane.add(simple_panel, SIMPLE);
372 }
373 main_pane.add(control_pane, CONTROL);
374 main_pane.add(progress_pane, PROGRESS);
375 if(current_mode >= THRESHOLD) { // Expert mode - add last
376 main_pane.add(simple_panel, SIMPLE);
377 }
378
379 this.setLayout(new BorderLayout());
380 this.add(main_pane, BorderLayout.CENTER);
381 }
382
383 /** This method is called whenever the 'Create' tab is selected from the view bar. It allows this view to perform any preactions required prior to display. In this case this entails gathering up to date information about the status of the collection including number of documents etc.
384 * @see org.greenstone.gatherer.Gatherer
385 * @see org.greenstone.gatherer.collection.CollectionManager
386 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
387 */
388 public void gainFocus() {
389 if(Configuration.getMode() < THRESHOLD) {
390 card_layout.show(main_pane, SIMPLE);
391 }
392 else if(!processing) {
393 // Move the buttons to control
394 control_pane.add(button_pane, BorderLayout.SOUTH);
395 card_layout.show(main_pane, CONTROL);
396 }
397 else {
398 // Move the buttons to progress
399 progress_pane.add(button_pane, BorderLayout.SOUTH);
400 card_layout.show(main_pane, PROGRESS);
401 }
402 // Refresh the set of controls.
403 TreePath path = tree.getSelectionPath();
404 tree.clearSelection();
405 tree.setSelectionPath(path);
406
407 //Disable the full/incremental buttons if the collection has not been built.
408 if(Gatherer.c_man.built()) {
409 full_build_radio_button.setEnabled(true);
410 incremental_build_radio_button.setEnabled(true);
411 sfull_build_radio_button.setEnabled(true);
412 sincremental_build_radio_button.setEnabled(true);
413 }
414 else {
415 full_build_radio_button.setEnabled(false);
416 incremental_build_radio_button.setEnabled(false);
417 sfull_build_radio_button.setEnabled(false);
418 sincremental_build_radio_button.setEnabled(false);
419 }
420 }
421
422 /** We are informed when this view pane loses focus so we can update build options. */
423 public void loseFocus() {
424 tree.valueChanged(null);
425 }
426
427 /**
428 * Check to see if doing an incremental build is chosen.
429 * If not, the full rebuild option must be chosen.
430 * @return boolean - true if the collection should be rebuilt incrementally.
431 */
432 public boolean isIncremental() {
433 boolean incremental = false;
434
435 //This is horrible. What if the mode is changed, and different options are chosen on different modes??
436 if(Gatherer.c_man.built()) {
437 if(Configuration.getMode() >= THRESHOLD) {
438 incremental = incremental_build_radio_button.isSelected();
439 }
440 else {
441 incremental = sincremental_build_radio_button.isSelected();
442 }
443 }
444 else {
445 incremental = false; //The collection has not yet been built
446 }
447 return incremental;
448 }
449
450 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
451 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
452 */
453 public synchronized void message(GShellEvent event) {
454 // Ignore the messages from RecPlug (used for progress bars)
455 if (event.getMessage().startsWith("import.pl> RecPlug - ")) {
456 return;
457 }
458 document.appendLine(event.getMessage());
459 log_textarea.setCaretPosition(document.getLengthToNearestLine());
460 }
461
462 /** Called when the detail mode has changed which in turn may cause several import/build configuration arguments to be available/hidden
463 * @param mode the new mode as an int
464 */
465 public void modeChanged(int mode) {
466 // If we are below the complexity threshold ensure the simple controls are being shown
467 if(Configuration.getMode() < THRESHOLD) {
468 // Update the arguments
469 simple_panel.remove(sargument_configuration_scroll);
470 if(options_pane != null) {
471 sargument_configuration_panel = options_pane.buildImport(null);
472 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
473 }
474 else {
475 sargument_configuration_panel = new JPanel();
476 }
477 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
478 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
479 simple_panel.setTopComponent(sargument_configuration_scroll);
480 // Remove the shared components from the expert panels
481 progress_pane.remove(log_scroll);
482 // And add to simple one
483 slower_panel.add(log_scroll, BorderLayout.CENTER);
484 // And bring the card to the front
485 card_layout.show(main_pane, SIMPLE);
486 }
487 // And if we are above the threshold change to the complex controls
488 else {
489 // Remove the shared components from the simple panel
490 slower_panel.remove(log_scroll);
491 // And add then to the expert ones
492 progress_pane.add(log_scroll, BorderLayout.CENTER);
493 // And bring the appropriate card to the front
494 if(!processing) {
495 control_pane.add(button_pane, BorderLayout.SOUTH);
496 card_layout.show(main_pane, CONTROL);
497 }
498 else {
499 progress_pane.add(button_pane, BorderLayout.SOUTH);
500 card_layout.show(main_pane, PROGRESS);
501 }
502 }
503 tree.valueChanged(null); // Ensure tree argument panels are rebuilt
504 }
505
506 /** 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.
507 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
508 */
509 public synchronized void processBegun(GShellEvent event) {
510 // We don't care. We'll get a more acurate start from the progress monitors.
511 }
512 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
513 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
514 */
515 public synchronized void processComplete(GShellEvent event) {
516 DebugStream.println("In CreatePane::processComplete(" + event.getType() + ")...");
517 if(event.getStatus() == GShell.OK) {
518 if(event.getType() == GShell.BUILD) {
519 processing = false;
520 build_button.setEnabled(true);
521 cancel_button.setEnabled(false);
522 //preview_button.setEnabled(true);
523 simple_build_button.setEnabled(true);
524 simple_cancel_button.setEnabled(false);
525 //simple_preview_button.setEnabled(true);
526 int status = event.getStatus();
527 document.setSpecialCharacter(OptionsPane.SUCCESSFUL);
528 options_pane.resetFileEntry();
529 build_monitor.reset();
530 import_monitor.reset();
531 if(Configuration.getMode() >= THRESHOLD) {
532 control_pane.add(button_pane, BorderLayout.SOUTH);
533 card_layout.show(main_pane, CONTROL);
534 }
535 }
536 // Otherwise its completed import but still got build to go
537 }
538 else {
539 processing = false;
540 cancel_button.setEnabled(false);
541 build_button.setEnabled(true);
542 // The build may have failed, but a previous index may still be in place
543 //preview_button.setEnabled(Gatherer.c_man.built());
544
545 simple_build_button.setEnabled(true);
546 simple_cancel_button.setEnabled(false);
547 //simple_preview_button.setEnabled(Gatherer.c_man.built());
548 if(event.getStatus() == GShell.CANCELLED) {
549 document.setSpecialCharacter(OptionsPane.CANCELLED);
550 }
551 else {
552 document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL);
553 }
554 options_pane.resetFileEntry();
555 if(Configuration.getMode() >= THRESHOLD) {
556 control_pane.add(button_pane, BorderLayout.SOUTH);
557 card_layout.show(main_pane, CONTROL);
558 }
559 }
560 }
561
562
563 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
564 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
565 * @see org.greenstone.gatherer.Gatherer
566 * @see org.greenstone.gatherer.collection.CollectionManager
567 * @see org.greenstone.gatherer.gui.BuildOptions
568 * @see org.greenstone.gatherer.gui.OptionsPane
569 */
570 public void refresh(int refresh_reason, boolean ready)
571 {
572 if (Gatherer.c_man == null || !ready) {
573 return;
574 }
575 Collection current_collection = Gatherer.c_man.getCollection();
576 if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) {
577 this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options);
578 if (previous_collection != null) {
579 // clear the log
580 Document log_document = log_textarea.getDocument();
581 if (log_document instanceof AppendLineOnlyFileDocument) {
582 ((AppendLineOnlyFileDocument) log_document).destroy();
583 }
584 }
585 previous_collection = current_collection;
586
587 }
588 // If we are in simple mode, we have to rebuild the simple arguments list
589 if(Configuration.getMode() < THRESHOLD) {
590 simple_panel.remove(sargument_configuration_scroll);
591 sargument_configuration_panel = options_pane.buildImport(null);
592 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
593 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
594 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
595 simple_panel.setTopComponent(sargument_configuration_scroll);
596 }
597 tree.valueChanged(null);
598
599 // Validate the preview button
600 if (Gatherer.c_man.built() && Configuration.library_url != null) {
601 preview_button.setEnabled(true);
602 simple_preview_button.setEnabled(true);
603 }
604 else {
605 preview_button.setEnabled(false);
606 simple_preview_button.setEnabled(false);
607 }
608 }
609
610 /** This class serves as the listener for actions on the build button. */
611 private class BuildButtonListener
612 implements ActionListener {
613 /**
614 * This method checks to see what needs to be done for a build, and starts the process off.
615 * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection.
616 * However, this doesn't always happen, as sometimes an incremental build will do :-)
617 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
618 * @see org.greenstone.gatherer.Gatherer
619 * @see org.greenstone.gatherer.collection.CollectionManager
620 * @see org.greenstone.gatherer.gui.BuildOptions
621 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
622 */
623 public void actionPerformed(ActionEvent event) {
624 Collection collection = Gatherer.c_man.getCollection();
625 String collection_name = collection.getName();
626 if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) {
627 //Only design options have changes, and we want to be smart in the way we handle them.
628 int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired();
629 if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) {
630 // Just run the buildcol command.
631 DebugStream.println("Just want to run buildcol.pl");
632 prepareForBuild();
633 Gatherer.c_man.buildCollection(isIncremental());
634 }
635 else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
636 // Do both import and buildcol
637 DebugStream.println("Want to do a complete build");
638 prepareForBuild();
639 Gatherer.c_man.importCollection(); //This starts the building process.
640 }
641 else {
642 //Nothing at all needs doing.
643 //This is bad HCI. Maybe should disable the build button in this situation?
644 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
645 }
646 }
647 else {
648 //Do a complete build.
649 prepareForBuild();
650 Gatherer.c_man.importCollection(); //This starts the building process.
651 }
652 //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
653 }
654
655 /**
656 * This does some stuff that is needed before a collection can be built.
657 * For example, buttons are enabled/disabled, and certain flags are set.
658 * This is called from {@link actionPerformed(ActionEvent)}
659 */
660 private void prepareForBuild() {
661 // First we force the build options to be updated if we haven't already.
662 tree.valueChanged(null);
663
664 // Remember that for lower thresholds the above doesn't work, so try this instead
665 if(Configuration.getMode() < THRESHOLD) {
666 options_pane.update(sargument_configuration_panel);
667 }
668
669 // Now go about building.
670 build_button.setEnabled(false);
671 cancel_button.setEnabled(true);
672 preview_button.setEnabled(false);
673
674 simple_build_button.setEnabled(false);
675 simple_cancel_button.setEnabled(true);
676 simple_preview_button.setEnabled(false);
677
678 document = options_pane.createNewLogDocument();
679 log_textarea.setDocument(document);
680 options_pane.log_textarea.setDocument(document);
681 // Change the view.
682 processing = true;
683 if(Configuration.getMode() >= THRESHOLD) {
684 progress_pane.add(button_pane, BorderLayout.SOUTH);
685 card_layout.show(main_pane, PROGRESS);
686 }
687 // Reset the stop flag in all the process monitors, just incase.
688 ((GBuildProgressMonitor)build_monitor).reset();
689 import_monitor.setStop(false);
690 }
691 }
692
693
694 /** This class serves as the listener for actions on the cancel button. */
695 private class CancelButtonListener
696 implements ActionListener {
697 /** This method attempts to cancel the current GShell task. It does this by first telling CollectionManager not to carry out any further action. This it turn tells the GShell to break from the current job immediately, without waiting for the processEnded message, and then kills the thread in an attempt to stop the process. The results of such an action are debatable.
698 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
699 * @see org.greenstone.gatherer.Gatherer
700 * @see org.greenstone.gatherer.collection.CollectionManager
701 * @see org.greenstone.gatherer.gui.BuildOptions
702 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
703 */
704 public void actionPerformed(ActionEvent event) {
705 build_button.setEnabled(false);
706 cancel_button.setEnabled(false);
707 preview_button.setEnabled(false);
708
709 simple_build_button.setEnabled(false);
710 simple_cancel_button.setEnabled(false);
711 simple_preview_button.setEnabled(false);
712
713 processing = false;
714 document.setSpecialCharacter(OptionsPane.CANCELLED);
715 if(Configuration.getMode() >= THRESHOLD) {
716 control_pane.add(button_pane, BorderLayout.SOUTH);
717 card_layout.show(main_pane, CONTROL);
718 }
719 // Set the stop flag in all the process monitor.
720 import_monitor.setStop(true);
721 import_monitor.reset();
722 build_monitor.setStop(true);
723 build_monitor.reset();
724
725 // Remove the collection lock.
726 //Gatherer.g_man.lockCollection(false, false);
727 }
728 }
729
730
731 /** The OptionTree is simply a tree structure that has a root node labelled "Options" and then has a child node for each available options screen. These screens are either combinations of the available import and build arguments, or a message log detailing the shell processes progress. */
732 private class OptionTree
733 extends JTree
734 implements TreeSelectionListener {
735 /** The model behind the tree. */
736 private DefaultTreeModel model = null;
737 /** The previous options view displayed, which is sometimes needed to refresh properly. */
738 private JPanel previous_pane = null;
739 /** The node corresponding to the building options view. */
740 private OptionTreeNode building = null;
741 /** The node corresponding to the importing options view. */
742 private OptionTreeNode importing = null;
743 /** The node corresponding to the log view. */
744 private OptionTreeNode log = null;
745 /** The root node of the options tree, which has no associated options view. */
746 private OptionTreeNode options = null;
747 /** Constructor.
748 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
749 */
750 public OptionTree() {
751 super();
752
753 ToolTipManager.sharedInstance().registerComponent(this);
754 addTreeSelectionListener(this);
755 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
756 setCellRenderer(new ToolTipTreeCellRenderer());
757 setRootVisible(false);
758 setToggleClickCount(1);
759
760 // Create tree.
761 building = new OptionTreeNode(Dictionary.get("CreatePane.Build"));
762 building.setToolTipText(Dictionary.get("CreatePane.Build_Tooltip"));
763 importing = new OptionTreeNode(Dictionary.get("CreatePane.Import"));
764 importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip"));
765 log = new OptionTreeNode(Dictionary.get("CreatePane.Log"));
766 log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip"));
767 options = new OptionTreeNode(Dictionary.get("CreatePane.Options"));
768
769 model = new DefaultTreeModel(options);
770 setModel(model);
771 model.insertNodeInto(importing, options, 0);
772 model.insertNodeInto(building, options, 1);
773 model.insertNodeInto(log, options, 2);
774 // Expand the root node
775 expandPath(new TreePath(options));
776 }
777 /** Any implementation of TreeSelectionListener must include this method to allow this listener to know when the selection has changed. Here we swap the options view depending on the selected OptionTreeNode.
778 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
779 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
780 */
781 public void valueChanged(TreeSelectionEvent event) {
782 TreePath path = null;
783 OptionTreeNode node = null;
784 //if(event != null) {
785 //path = event.getPath();
786 path = getSelectionPath();
787 if(path != null) {
788 node = (OptionTreeNode)path.getLastPathComponent();
789 }
790 //}
791 if(previous_pane != null) {
792 //target_pane.remove(previous_pane);
793 options_pane.update(previous_pane);
794 if(scroll_pane != null) {
795 right.remove(scroll_pane);
796 }
797 else {
798 right.remove(previous_pane);
799 }
800 previous_pane = null;
801 scroll_pane = null;
802 }
803 if(node != null && node.equals(building)) {
804 previous_pane = options_pane.buildBuild(null);
805 scroll_pane = new JScrollPane(previous_pane);
806 right.add(scroll_pane, BorderLayout.CENTER);
807 //target_pane.add(previous_pane, BorderLayout.CENTER);
808 }
809 else if(node != null && node.equals(importing)) {
810 previous_pane = options_pane.buildImport(null);
811 scroll_pane = new JScrollPane(previous_pane);
812 right.add(scroll_pane, BorderLayout.CENTER);
813 //target_pane.add(previous_pane, BorderLayout.CENTER);
814 }
815 else {
816 if (options_pane != null) {
817 previous_pane = options_pane.buildLog();
818 right.add(previous_pane, BorderLayout.CENTER);
819 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
820 ///ystem.err.println("I've added the log back to the right pane again.");
821 //target_pane.add(previous_pane, BorderLayout.CENTER);
822 }
823 }
824 //scroll_pane.setViewportView(previous_pane);
825 //previous_pane.validate();
826 right.validate();
827 //System.err.println("Current pane size: " + previous_pane.getSize());
828 //System.err.println("While its preferred size is: " + previous_pane.getPreferredSize());
829 }
830 }
831
832 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
833 */
834 private class OptionTreeNode
835 extends DefaultMutableTreeNode
836 implements Comparable {
837 /** The text label given to this node in the tree. */
838 private String title = null;
839 /** a tool tip to be used for this node in the tree */
840 private String tool_tip = null;
841 /** Constructor.
842 * @param title The <strong>String</strong> which serves as this nodes title.
843 */
844 public OptionTreeNode(String title) {
845 super();
846 this.title = title;
847 }
848
849 /** This method compares two nodes for ordering.
850 * @param obj The <strong>Object</strong> to compare to.
851 * @return An <strong>int</strong> of one of the possible values -1, 0 or 1 indicating if this node is less than, equal to or greater than the target node respectively.
852 */
853 public int compareTo(Object obj) {
854 return title.compareTo(obj.toString());
855 }
856
857 /** This method checks if two nodes are equivalent.
858 * @param obj The <strong>Object</strong> to be tested against.
859 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
860 */
861 public boolean equals(Object obj) {
862 if(compareTo(obj) == 0) {
863 return true;
864 }
865 return false;
866 }
867
868 /** get the tool tip */
869 public String getToolTipText() {
870 return tool_tip;
871 }
872
873 /** set the tool tip */
874 public void setToolTipText(String tip) {
875 tool_tip = tip;
876 }
877
878 /** Method to translate this node into a textual representation.
879 * @return A <strong>String</strong> which in this case is the title.
880 */
881 public String toString() {
882 return title;
883 }
884 }
885
886 // Adds tooltips to the tree nodes
887 private class ToolTipTreeCellRenderer
888 extends DefaultTreeCellRenderer {
889
890 public Component getTreeCellRendererComponent(JTree tree,
891 Object value,
892 boolean sel,
893 boolean expanded,
894 boolean leaf,
895 int row,
896 boolean hasFocus) {
897
898 super.getTreeCellRendererComponent(tree, value, sel,
899 expanded, leaf, row,
900 hasFocus);
901 if (value instanceof OptionTreeNode) {
902 String tip = ((OptionTreeNode) value).getToolTipText();
903 if (tip != null) {
904 setToolTipText(tip);
905 }
906 }
907 return this;
908 }
909 }
910}
Note: See TracBrowser for help on using the repository browser.