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

Last change on this file since 16134 was 16134, checked in by osborn, 16 years ago

Additions for Scheduling Component

  • Property svn:keywords set to Author Date Id Revision
File size: 44.4 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.cdm.BuildTypeManager;
51import org.greenstone.gatherer.cdm.CollectionDesignManager;
52import org.greenstone.gatherer.collection.Collection;
53import org.greenstone.gatherer.shell.GBuildProgressMonitor;
54import org.greenstone.gatherer.shell.GImportProgressMonitor;
55import org.greenstone.gatherer.shell.GScheduleProgressMonitor;
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 /** This monitor tracks the schedule processes progress. */
97 private GShellProgressMonitor schedule_monitor = null;
98 /** The button for begining the building processes. */
99 private JButton build_button = null;
100 /** The button for stopping the building processes. */
101 private JButton cancel_button = null;
102 /** The button for setting up scheduling */
103 private JButton schedule_button = null;
104 /** The button for viewing the collection. */
105 private JButton preview_button = null;
106 private JButton simple_build_button;
107 private JButton simple_cancel_button;
108 private JButton simple_preview_button;
109 /** The radio buttons for chnaging the build type (incremental/full) */
110 private JRadioButton full_build_radio_button;
111 private JRadioButton incremental_build_radio_button;
112 private JRadioButton sfull_build_radio_button;
113 private JRadioButton sincremental_build_radio_button;
114 /** The label displaying the number of documents in this collection. */
115 private JLabel document_count = null;
116 /** The label alongside the build progress bar gets some special treatment so... */
117 private JLabel progress_build_label = null;
118 /** The label alongside the import progress bar gets some special treatment so... */
119 private JLabel progress_import_label = null;
120 private JPanel bar_area;
121 /** The panel on which buttons are rendered on higher detail modes. */
122 private JPanel button_pane;
123 /** The pane which contains the controls for configuration. */
124 private JPanel control_pane = null;
125 /** The pane which has the card layout as its manager. */
126 private JPanel main_pane = null;
127 /** The pane which contains the progress information. */
128 private JPanel progress_pane = null;
129 /** The pane on the right-hand side - shows the requested options view */
130 private JPanel right = null;
131 /** The simple panel on which all of the available arguments are rendered. */
132 private JPanel sargument_configuration_panel;
133 /** The panel on which buttons are rendered on lower details modes. */
134 private JPanel sbutton_panel;
135 /** A simplified version for lower detail modes containing both the control and progress panes smooshed together. */
136 private JSplitPane simple_panel;
137 /** The lower part of the panel which is global so the log pane can be added and removed from it */
138 private JPanel slower_panel;
139 /** The inner panel of the simple pane which is global so that the bar_area can be added and removed from it. */
140 private JPanel sinner_panel;
141 /** The scrolling pane for the log. */
142 private JScrollPane log_scroll;
143 /** The scrolling pane the simple arguments are rendered within. */
144 private JScrollPane sargument_configuration_scroll;
145 /** 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 */
146 private JScrollPane scroll_pane;
147 /** The message log for the entire session. */
148 private JTextArea log_textarea;
149 /** A tree used to display the currently available option views. */
150 private OptionTree tree = null;
151 /** An array used to pass arguments with dictionary calls. */
152 private String args[] = null;
153 /** The homepage address of the current collection */
154 public String homepage = null;
155
156
157 /** The constructor creates important helper classes, and initializes all the components.
158 * @see org.greenstone.gatherer.collection.CollectionManager
159 * @see org.greenstone.gatherer.gui.BuildOptions
160 * @see org.greenstone.gatherer.gui.CreatePane.BuildButtonListener
161 * @see org.greenstone.gatherer.gui.CreatePane.CancelButtonListener
162 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
163 * @see org.greenstone.gatherer.gui.OptionsPane
164 * @see org.greenstone.gatherer.shell.GBuildProgressMonitor
165 * @see org.greenstone.gatherer.shell.GImportProgressMonitor
166 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
167 */
168 public CreatePane() {
169 log_textarea = new JTextArea();
170 log_scroll = new JScrollPane(log_textarea);
171
172 // Create components
173 card_layout = new CardLayout();
174 // Control Pane
175 control_pane = new JPanel();
176 tree = new OptionTree();
177 button_pane = new JPanel();
178
179 // Progress Pane
180 progress_pane = new JPanel(); // One owner of the bar component
181 bar_area = new JPanel(); // This component will be shared about
182
183 progress_import_label = new JLabel(Dictionary.get("CreatePane.Import_Progress"));
184
185 import_monitor = new GImportProgressMonitor();
186 Gatherer.c_man.registerImportMonitor(import_monitor);
187
188 progress_build_label = new JLabel(Dictionary.get("CreatePane.Build_Progress"));
189
190 build_monitor = new GBuildProgressMonitor(import_monitor.getSharedProgress());
191 Gatherer.c_man.registerBuildMonitor(build_monitor);
192
193 //We only need a schedule monitor for text output. No use for a progress bar!
194
195 //progress_schedule_label = new JLabel(Dictionary.get("CreatePane.Schedule_Progress"));
196
197 schedule_monitor = new GScheduleProgressMonitor();
198 Gatherer.c_man.registerScheduleMonitor(schedule_monitor);
199
200 // And the simple panel
201 slower_panel = new JPanel();
202 sbutton_panel = new JPanel();
203 sinner_panel = new JPanel();
204
205 //Radio buttons
206 incremental_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Minimal_Build"));
207 incremental_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Minimal_Build_Tooltip"));
208 full_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Full_Build"));
209 full_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Full_Build_Tooltip"));
210 sincremental_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Minimal_Build"));
211 sincremental_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Minimal_Build_Tooltip"));
212 sfull_build_radio_button = new JRadioButton(Dictionary.get("CreatePane.Full_Build"));
213 sfull_build_radio_button.setToolTipText(Dictionary.get("CreatePane.Full_Build_Tooltip"));
214
215
216 // Buttons
217 BuildButtonListener bbl = new BuildButtonListener();
218 CancelButtonListener cbl = new CancelButtonListener();
219
220 build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip"));
221 build_button.addActionListener(bbl);
222
223 cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip"));
224 cancel_button.addActionListener(cbl);
225 cancel_button.setEnabled(false);
226
227 preview_button = new PreviewButton(Dictionary.get("CreatePane.Preview_Collection"), Dictionary.get("CreatePane.Preview_Collection_Tooltip"));
228 //preview_button.addActionListener(pbl);
229 if(Gatherer.c_man != null) {
230 preview_button.setEnabled(Gatherer.c_man.built());
231 }
232 else {
233 preview_button.setEnabled(false);
234 }
235
236 BuildSimpleButtonListener bsbl = new BuildSimpleButtonListener();
237 simple_build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip"));
238 simple_build_button.addActionListener(bsbl);
239
240 simple_cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip"));
241 simple_cancel_button.addActionListener(cbl);
242 simple_cancel_button.setEnabled(false);
243
244 simple_preview_button = new PreviewButton(Dictionary.get("CreatePane.Preview_Collection"), Dictionary.get("CreatePane.Preview_Collection_Tooltip"));
245 //simple_preview_button.addActionListener(pbl);
246 if(Gatherer.c_man != null) {
247 simple_preview_button.setEnabled(Gatherer.c_man.built());
248 }
249 else {
250 simple_preview_button.setEnabled(false);
251 }
252
253 bbl = null;
254 bsbl = null;
255 cbl = null;
256 //pbl = null;
257 }
258
259
260 public void destroy() {
261 if(document != null) {
262 document.destroy();
263 }
264 }
265
266 /** This method is called to actually layout the components.
267 * @see org.greenstone.gatherer.Configuration
268 * @see org.greenstone.gatherer.Gatherer
269 */
270 public void display() {
271
272 int current_mode = Configuration.getMode();
273
274 //Complete/incremental build options panel
275 //For some reason I need to create seperate objects for each mode. Is there a better way??
276 ButtonGroup build_type_group = new ButtonGroup();
277 build_type_group.add(incremental_build_radio_button);
278 full_build_radio_button.setSelected(true);
279 build_type_group.add(full_build_radio_button);
280 ButtonGroup sbuild_type_group = new ButtonGroup();
281 sbuild_type_group.add(sincremental_build_radio_button);
282 sfull_build_radio_button.setSelected(true);
283 sbuild_type_group.add(sfull_build_radio_button);
284 JPanel build_type_pane = new JPanel(new GridLayout(2,1));
285 build_type_pane.add(full_build_radio_button);
286 build_type_pane.add(incremental_build_radio_button);
287 JPanel sbuild_type_pane = new JPanel(new GridLayout(2,1));
288 sbuild_type_pane.add(sfull_build_radio_button);
289 sbuild_type_pane.add(sincremental_build_radio_button);
290
291
292
293 // Build control_pane
294 JPanel left = new JPanel();
295 left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
296 left.setLayout(new BorderLayout());
297 left.add(tree, BorderLayout.CENTER);
298 left.add(build_type_pane, BorderLayout.SOUTH);
299 //left.add(full_build_radio_button, BorderLayout.SOUTH);
300
301 right = new JPanel();
302 right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5));
303 right.setLayout(new BorderLayout());
304
305 JPanel options_area = new JPanel();
306 options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(Dictionary.get("CreatePane.Options_Title"))));
307 options_area.setLayout(new BorderLayout());
308 options_area.add(left, BorderLayout.WEST);
309 options_area.add(right, BorderLayout.CENTER);
310
311 button_pane = new JPanel();
312 button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10));
313 button_pane.setLayout(new GridLayout(1,4));
314 button_pane.add(build_button);
315 button_pane.add(cancel_button);
316 button_pane.add(preview_button);
317
318 control_pane.setLayout(new BorderLayout());
319 control_pane.add(options_area, BorderLayout.CENTER);
320 control_pane.add(button_pane, BorderLayout.SOUTH);
321
322 // Build progress_pane
323 JPanel labels_pane = new JPanel();
324 labels_pane.setLayout(new GridLayout(2,1,0,5));
325 labels_pane.add(progress_import_label);
326 labels_pane.add(progress_build_label);
327
328 JPanel monitors_pane = new JPanel();
329 monitors_pane.setLayout(new GridLayout(2,1,0,5));
330 monitors_pane.add(import_monitor.getProgress());
331 monitors_pane.add(build_monitor.getProgress());
332
333 bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10));
334 bar_area.setLayout(new BorderLayout(5,5));
335 bar_area.add(labels_pane, BorderLayout.WEST);
336 bar_area.add(monitors_pane, BorderLayout.CENTER);
337
338 progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
339 progress_pane.setLayout(new BorderLayout());
340 progress_pane.add(bar_area, BorderLayout.NORTH);
341 if(current_mode >= THRESHOLD) {
342 progress_pane.add(log_scroll, BorderLayout.CENTER);
343 }
344
345 // Simple panel
346 sbutton_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
347 sbutton_panel.setLayout(new GridLayout(1,3));
348 sbutton_panel.add(simple_build_button);
349 sbutton_panel.add(simple_cancel_button);
350 sbutton_panel.add(simple_preview_button);
351
352 JPanel simple_bar_area = new JPanel(new GridLayout(2,1));
353 simple_bar_area.setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
354 simple_bar_area.add(import_monitor.getSharedProgress());
355 simple_bar_area.add(sbutton_panel);
356
357 sinner_panel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
358 sinner_panel.setLayout(new BorderLayout());
359 sinner_panel.add(sbuild_type_pane, BorderLayout.WEST);
360 //sinner_panel.add(full_build_radio_button, BorderLayout.WEST);
361 sinner_panel.add(simple_bar_area, BorderLayout.CENTER);
362
363 if(options_pane != null) {
364 sargument_configuration_panel = options_pane.buildImport(null);
365 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
366 sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);
367 }
368 else {
369 sargument_configuration_panel = new JPanel();
370 }
371 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
372 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
373
374 slower_panel.setLayout(new BorderLayout());
375 slower_panel.add(sinner_panel, BorderLayout.NORTH);
376 if(current_mode < THRESHOLD) {
377 slower_panel.add(log_scroll, BorderLayout.CENTER);
378 }
379
380 simple_panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, sargument_configuration_scroll, slower_panel);
381 // Main pane
382 main_pane = new JPanel(card_layout);
383 if(current_mode < THRESHOLD) { // Simple mode - add first
384 main_pane.add(simple_panel, SIMPLE);
385 }
386 main_pane.add(control_pane, CONTROL);
387 main_pane.add(progress_pane, PROGRESS);
388 if(current_mode >= THRESHOLD) { // Expert mode - add last
389 main_pane.add(simple_panel, SIMPLE);
390 }
391
392 this.setLayout(new BorderLayout());
393 this.add(main_pane, BorderLayout.CENTER);
394 }
395
396 /** 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.
397 * @see org.greenstone.gatherer.Gatherer
398 * @see org.greenstone.gatherer.collection.CollectionManager
399 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
400 */
401 public void gainFocus() {
402 if(Configuration.getMode() < THRESHOLD) {
403 card_layout.show(main_pane, SIMPLE);
404 }
405 else if(!processing) {
406 // Move the buttons to control
407 control_pane.add(button_pane, BorderLayout.SOUTH);
408 card_layout.show(main_pane, CONTROL);
409 }
410 else {
411 // Move the buttons to progress
412 progress_pane.add(button_pane, BorderLayout.SOUTH);
413 card_layout.show(main_pane, PROGRESS);
414 }
415 // Refresh the set of controls.
416 TreePath path = tree.getSelectionPath();
417 tree.clearSelection();
418 tree.setSelectionPath(path);
419
420 //Disable the full/incremental buttons if the collection has not been built.
421 if(Gatherer.c_man.built()) {
422 full_build_radio_button.setEnabled(true);
423 incremental_build_radio_button.setEnabled(true);
424 sfull_build_radio_button.setEnabled(true);
425 sincremental_build_radio_button.setEnabled(true);
426 }
427 else {
428 full_build_radio_button.setEnabled(false);
429 incremental_build_radio_button.setEnabled(false);
430 sfull_build_radio_button.setEnabled(false);
431 sincremental_build_radio_button.setEnabled(false);
432 }
433 }
434
435 /** We are informed when this view pane loses focus so we can update build options. */
436 public void loseFocus() {
437 tree.valueChanged(null);
438 }
439
440 /**
441 * Check to see if doing an incremental build is chosen.
442 * If not, the full rebuild option must be chosen.
443 * @return boolean - true if the collection should be rebuilt incrementally.
444 */
445 public boolean isIncremental() {
446 boolean incremental = false;
447
448 //This is horrible. What if the mode is changed, and different options are chosen on different modes??
449 if(Gatherer.c_man.built()) {
450 if(Configuration.getMode() >= THRESHOLD) {
451 incremental = incremental_build_radio_button.isSelected();
452 }
453 else {
454 incremental = sincremental_build_radio_button.isSelected();
455 }
456 }
457 else {
458 incremental = false; //The collection has not yet been built
459 }
460 return incremental;
461 }
462
463 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
464 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
465 */
466 public synchronized void message(GShellEvent event) {
467 // Ignore the messages from RecPlug (used for progress bars)
468 if (event.getMessage().startsWith("import.pl> RecPlug - ")) {
469 return;
470 }
471 document.appendLine(event.getMessage());
472 log_textarea.setCaretPosition(document.getLengthToNearestLine());
473 }
474
475 /** Called when the detail mode has changed which in turn may cause several import/build configuration arguments to be available/hidden
476 * @param mode the new mode as an int
477 */
478 public void modeChanged(int mode) {
479 // If we are below the complexity threshold ensure the simple controls are being shown
480 if(Configuration.getMode() < THRESHOLD) {
481 // Update the arguments
482 simple_panel.remove(sargument_configuration_scroll);
483 if(options_pane != null) {
484 sargument_configuration_panel = options_pane.buildImport(null);
485 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
486 sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);
487 }
488 else {
489 sargument_configuration_panel = new JPanel();
490 }
491 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
492 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
493 simple_panel.setTopComponent(sargument_configuration_scroll);
494 // Remove the shared components from the expert panels
495 progress_pane.remove(log_scroll);
496 // And add to simple one
497 slower_panel.add(log_scroll, BorderLayout.CENTER);
498 // And bring the card to the front
499 card_layout.show(main_pane, SIMPLE);
500 }
501 // And if we are above the threshold change to the complex controls
502 else {
503 // Remove the shared components from the simple panel
504 slower_panel.remove(log_scroll);
505 // And add then to the expert ones
506 progress_pane.add(log_scroll, BorderLayout.CENTER);
507 // And bring the appropriate card to the front
508 if(!processing) {
509 control_pane.add(button_pane, BorderLayout.SOUTH);
510 card_layout.show(main_pane, CONTROL);
511 }
512 else {
513 progress_pane.add(button_pane, BorderLayout.SOUTH);
514 card_layout.show(main_pane, PROGRESS);
515 }
516 }
517 tree.valueChanged(null); // Ensure tree argument panels are rebuilt
518 }
519
520 /** 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.
521 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
522 */
523 public synchronized void processBegun(GShellEvent event) {
524 // We don't care. We'll get a more acurate start from the progress monitors.
525 }
526 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
527 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
528 */
529 public synchronized void processComplete(GShellEvent event) {
530 DebugStream.println("In CreatePane::processComplete(" + event.getType() + ")...");
531 if(event.getStatus() == GShell.OK) {
532 if(event.getType() == GShell.SCHEDULE) {
533
534 processing = false;
535 build_button.setEnabled(true);
536 cancel_button.setEnabled(false);
537 preview_button.setEnabled(true);
538 //only enable preview if the collection has been built.
539 preview_button.setEnabled(Gatherer.c_man.built());
540 simple_build_button.setEnabled(true);
541 simple_cancel_button.setEnabled(false);
542 simple_preview_button.setEnabled(Gatherer.c_man.built());
543 int status = event.getStatus();
544 document.setSpecialCharacter(OptionsPane.SCHEDULED);
545 options_pane.resetFileEntry();
546 build_monitor.reset();
547 import_monitor.reset();
548 if(Configuration.getMode() >= THRESHOLD) {
549 control_pane.add(button_pane, BorderLayout.SOUTH);
550 card_layout.show(main_pane, CONTROL);
551 }
552 }
553 else if(event.getType() == GShell.BUILD) {
554 processing = false;
555 build_button.setEnabled(true);
556 cancel_button.setEnabled(false);
557 preview_button.setEnabled(true);
558 simple_build_button.setEnabled(true);
559 simple_cancel_button.setEnabled(false);
560 //simple_preview_button.setEnabled(true);
561 int status = event.getStatus();
562 document.setSpecialCharacter(OptionsPane.SUCCESSFUL);
563 options_pane.resetFileEntry();
564 build_monitor.reset();
565 import_monitor.reset();
566 if(Configuration.getMode() >= THRESHOLD) {
567 control_pane.add(button_pane, BorderLayout.SOUTH);
568 card_layout.show(main_pane, CONTROL);
569 }
570 }
571 // Otherwise its completed import but still got build to go
572 }
573 else {
574 processing = false;
575 cancel_button.setEnabled(false);
576 build_button.setEnabled(true);
577 // The build may have failed, but a previous index may still be in place
578 preview_button.setEnabled(Gatherer.c_man.built());
579
580 simple_build_button.setEnabled(true);
581 simple_cancel_button.setEnabled(false);
582 simple_preview_button.setEnabled(Gatherer.c_man.built());
583 if(event.getStatus() == GShell.CANCELLED) {
584 document.setSpecialCharacter(OptionsPane.CANCELLED);
585 }
586 else {
587 document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL);
588 }
589 options_pane.resetFileEntry();
590 if(Configuration.getMode() >= THRESHOLD) {
591 control_pane.add(button_pane, BorderLayout.SOUTH);
592 card_layout.show(main_pane, CONTROL);
593 }
594 }
595 }
596
597
598 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
599 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
600 * @see org.greenstone.gatherer.Gatherer
601 * @see org.greenstone.gatherer.collection.CollectionManager
602 * @see org.greenstone.gatherer.gui.BuildOptions
603 * @see org.greenstone.gatherer.gui.OptionsPane
604 */
605 public void refresh(int refresh_reason, boolean ready)
606 {
607 if (Gatherer.c_man == null || !ready) {
608 return;
609 }
610 Collection current_collection = Gatherer.c_man.getCollection();
611 if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) {
612 this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options, current_collection.schedule_options);
613 if (previous_collection != null) {
614 // clear the log
615 Document log_document = log_textarea.getDocument();
616 if (log_document instanceof AppendLineOnlyFileDocument) {
617 ((AppendLineOnlyFileDocument) log_document).destroy();
618 }
619 }
620 previous_collection = current_collection;
621
622 }
623 // If we are in simple mode, we have to rebuild the simple arguments list
624 if(Configuration.getMode() < THRESHOLD) {
625 simple_panel.remove(sargument_configuration_scroll);
626 sargument_configuration_panel = options_pane.buildImport(null);
627 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
628 sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);
629 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
630 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
631 simple_panel.setTopComponent(sargument_configuration_scroll);
632 }
633 tree.valueChanged(null);
634
635 // Validate the preview button
636 if (Gatherer.c_man.built() && Configuration.library_url != null) {
637 preview_button.setEnabled(true);
638 simple_preview_button.setEnabled(true);
639 }
640 else {
641 preview_button.setEnabled(false);
642 simple_preview_button.setEnabled(false);
643 }
644 }
645
646 /** This class serves as the listener for actions on the build button. */
647 private class BuildButtonListener
648 implements ActionListener {
649 /**
650 * This method checks to see what needs to be done for a build, and starts the process off.
651 * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection.
652 * However, this doesn't always happen, as sometimes an incremental build will do :-)
653 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
654 * @see org.greenstone.gatherer.Gatherer
655 * @see org.greenstone.gatherer.collection.CollectionManager
656 * @see org.greenstone.gatherer.gui.BuildOptions
657 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
658 */
659 public void actionPerformed(ActionEvent event) {
660 Collection collection = Gatherer.c_man.getCollection();
661 String collection_name = collection.getName();
662
663 //if button is labelled for Building
664 if(event.getActionCommand().equals(Dictionary.get("CreatePane.Build_Collection"))) {
665
666 if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) {
667 //Only design options have changes, and we want to be smart in the way we handle them.
668 int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired();
669 if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) {
670 // Just run the buildcol command.
671 DebugStream.println("Just want to run buildcol.pl");
672 prepareForBuild();
673 Gatherer.c_man.buildCollection(isIncremental());
674 }
675 else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
676 // Do both import and buildcol
677 DebugStream.println("Want to do a complete build");
678 prepareForBuild();
679 Gatherer.c_man.importCollection(); //This starts the building process.
680 }
681 else {
682 //Nothing at all needs doing.
683 //This is bad HCI. Maybe should disable the build button in this situation?
684 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
685 }
686 }
687 else {
688 //Do a complete build.
689 prepareForBuild();
690 Gatherer.c_man.importCollection(); //This starts the building process.
691 }
692
693 } else { //button is labelled for setting up scheduling
694
695 //this needs to be called to configure buttons... but no building is done
696 prepareForBuild();
697
698 Gatherer.c_man.scheduleBuild(isIncremental());
699 }
700
701 //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
702 }
703
704 /**
705 * This does some stuff that is needed before a collection can be built.
706 * For example, buttons are enabled/disabled, and certain flags are set.
707 * This is called from {@link actionPerformed(ActionEvent)}
708 */
709 private void prepareForBuild() {
710 // First we force the build options to be updated if we haven't already.
711 tree.valueChanged(null);
712
713 // Remember that for lower thresholds the above doesn't work, so try this instead
714 if(Configuration.getMode() < THRESHOLD) {
715 options_pane.update(sargument_configuration_panel);
716 }
717
718 // Now go about building.
719 build_button.setEnabled(false);
720 cancel_button.setEnabled(true);
721 preview_button.setEnabled(false);
722
723 simple_build_button.setEnabled(false);
724 simple_cancel_button.setEnabled(true);
725 simple_preview_button.setEnabled(false);
726
727 document = options_pane.createNewLogDocument();
728 log_textarea.setDocument(document);
729 options_pane.log_textarea.setDocument(document);
730 // Change the view.
731 processing = true;
732 if(Configuration.getMode() >= THRESHOLD) {
733 progress_pane.add(button_pane, BorderLayout.SOUTH);
734 card_layout.show(main_pane, PROGRESS);
735 }
736 // Reset the stop flag in all the process monitors, just incase.
737 ((GBuildProgressMonitor)build_monitor).reset();
738 import_monitor.setStop(false);
739 }
740 }
741
742 /** I hope this works. Wendy */
743 private class BuildSimpleButtonListener
744 implements ActionListener {
745 /**
746 * This method checks to see what needs to be done for a build, and starts the process off.
747 * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection.
748 * However, this doesn't always happen, as sometimes an incremental build will do :-)
749 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
750 * @see org.greenstone.gatherer.Gatherer
751 * @see org.greenstone.gatherer.collection.CollectionManager
752 * @see org.greenstone.gatherer.gui.BuildOptions
753 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
754 */
755 public void actionPerformed(ActionEvent event) {
756 Collection collection = Gatherer.c_man.getCollection();
757 String collection_name = collection.getName();
758
759 //prepareForBuild();
760 if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) {
761 //Only design options have changes, and we want to be smart in the way we handle them.
762 int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired();
763 if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) {
764 // Just run the buildcol command.
765 DebugStream.println("Just want to run buildcol.pl");
766 prepareForBuild();
767 Gatherer.c_man.buildCollection(isIncremental());
768 }
769 else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
770 // Do both import and buildcol
771 DebugStream.println("Want to do a complete build");
772 prepareForBuild();
773 Gatherer.c_man.importCollection(); //This starts the building process.
774 }
775 else {
776 //Nothing at all needs doing.
777 //This is bad HCI. Maybe should disable the build button in this situation?
778 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
779 }
780 }
781 else {
782 //Do a complete build.
783 prepareForBuild();
784 Gatherer.c_man.importCollection(); //This starts the building process.
785 }
786
787 //only schedule in SYSTEM mode - also done in EXPERT mode, but that is handled elsewhere
788 if(Configuration.getMode() == Configuration.SYSTEMS_MODE) {
789 if(Gatherer.c_man.getCollection().schedule_options.getValueEnabled("schedule")) {
790 Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"add");
791 Gatherer.c_man.getCollection().schedule_options.setValue("email",false, null);
792 Gatherer.c_man.getCollection().schedule_options.setValue("smtp",false, null);
793 Gatherer.c_man.getCollection().schedule_options.setValue("toaddr",false, null);
794 Gatherer.c_man.getCollection().schedule_options.setValue("fromaddr",false, null);
795 Gatherer.c_man.getCollection().schedule_options.setValue("frequency",false, null);
796 Gatherer.c_man.scheduleBuild(isIncremental());
797 } else {
798 //need to turn off existing scheduling
799 Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"delete");
800 Gatherer.c_man.scheduleBuild(isIncremental());
801
802 }
803 }
804 //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
805 }
806
807 /**
808 * This does some stuff that is needed before a collection can be built.
809 * For example, buttons are enabled/disabled, and certain flags are set.
810 * This is called from {@link actionPerformed(ActionEvent)}
811 */
812 private void prepareForBuild() {
813 // First we force the build options to be updated if we haven't already.
814 tree.valueChanged(null);
815
816 // Remember that for lower thresholds the above doesn't work, so try this instead
817 if(Configuration.getMode() < THRESHOLD) {
818 options_pane.update(sargument_configuration_panel);
819 }
820
821 // Now go about building.
822 build_button.setEnabled(false);
823 cancel_button.setEnabled(true);
824 preview_button.setEnabled(false);
825
826 simple_build_button.setEnabled(false);
827 simple_cancel_button.setEnabled(true);
828 simple_preview_button.setEnabled(false);
829
830 document = options_pane.createNewLogDocument();
831 log_textarea.setDocument(document);
832 options_pane.log_textarea.setDocument(document);
833 // Change the view.
834 processing = true;
835 if(Configuration.getMode() >= THRESHOLD) {
836 progress_pane.add(button_pane, BorderLayout.SOUTH);
837 card_layout.show(main_pane, PROGRESS);
838 }
839 // Reset the stop flag in all the process monitors, just incase.
840 ((GBuildProgressMonitor)build_monitor).reset();
841 import_monitor.setStop(false);
842 }
843 }
844
845
846 /** This class serves as the listener for actions on the cancel button. */
847 private class CancelButtonListener
848 implements ActionListener {
849 /** 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.
850 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
851 * @see org.greenstone.gatherer.Gatherer
852 * @see org.greenstone.gatherer.collection.CollectionManager
853 * @see org.greenstone.gatherer.gui.BuildOptions
854 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
855 */
856 public void actionPerformed(ActionEvent event) {
857 build_button.setEnabled(false);
858 cancel_button.setEnabled(false);
859 preview_button.setEnabled(false);
860
861 simple_build_button.setEnabled(false);
862 simple_cancel_button.setEnabled(false);
863 simple_preview_button.setEnabled(false);
864
865 processing = false;
866 document.setSpecialCharacter(OptionsPane.CANCELLED);
867 if(Configuration.getMode() >= THRESHOLD) {
868 control_pane.add(button_pane, BorderLayout.SOUTH);
869 card_layout.show(main_pane, CONTROL);
870 }
871 // Set the stop flag in all the process monitor.
872 import_monitor.setStop(true);
873 import_monitor.reset();
874 build_monitor.setStop(true);
875 build_monitor.reset();
876
877 // Remove the collection lock.
878 //Gatherer.g_man.lockCollection(false, false);
879 }
880 }
881
882
883 /** 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. */
884 private class OptionTree
885 extends JTree
886 implements TreeSelectionListener {
887 /** The model behind the tree. */
888 private DefaultTreeModel model = null;
889 /** The previous options view displayed, which is sometimes needed to refresh properly. */
890 private JPanel previous_pane = null;
891 /** The node corresponding to the building options view. */
892 private OptionTreeNode building = null;
893 /** The node corresponding to the importing options view. */
894 private OptionTreeNode importing = null;
895 /** The node corresponding to the scheduling options view. */
896 private OptionTreeNode scheduling = null;
897 /** The node corresponding to the log view. */
898 private OptionTreeNode log = null;
899 /** The root node of the options tree, which has no associated options view. */
900 private OptionTreeNode options = null;
901 /** Constructor.
902 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
903 */
904 public OptionTree() {
905 super();
906
907 ToolTipManager.sharedInstance().registerComponent(this);
908 addTreeSelectionListener(this);
909 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
910 setCellRenderer(new ToolTipTreeCellRenderer());
911 setRootVisible(false);
912 setToggleClickCount(1);
913
914 // Create tree.
915 building = new OptionTreeNode(Dictionary.get("CreatePane.Build"));
916 building.setToolTipText(Dictionary.get("CreatePane.Build_Tooltip"));
917 importing = new OptionTreeNode(Dictionary.get("CreatePane.Import"));
918 importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip"));
919 scheduling = new OptionTreeNode(Dictionary.get("CreatePane.Schedule"));
920 scheduling.setToolTipText(Dictionary.get("CreatePane.Schedule_Tooltip"));
921
922 log = new OptionTreeNode(Dictionary.get("CreatePane.Log"));
923 log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip"));
924 options = new OptionTreeNode(Dictionary.get("CreatePane.Options"));
925
926 model = new DefaultTreeModel(options);
927 setModel(model);
928 model.insertNodeInto(importing, options, 0);
929 model.insertNodeInto(building, options, 1);
930 model.insertNodeInto(scheduling, options, 2);
931 model.insertNodeInto(log, options, 3);
932 // Expand the root node
933 expandPath(new TreePath(options));
934 }
935 /** 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.
936 * @param event A <Strong>TreeSelectionEvent</strong> which contains all the information garnered when the event occured.
937 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
938 */
939 public void valueChanged(TreeSelectionEvent event) {
940 TreePath path = null;
941 OptionTreeNode node = null;
942 //if(event != null) {
943 //path = event.getPath();
944 path = getSelectionPath();
945 if(path != null) {
946 node = (OptionTreeNode)path.getLastPathComponent();
947 }
948 //}
949 if(previous_pane != null) {
950 //target_pane.remove(previous_pane);
951 options_pane.update(previous_pane);
952 if(scroll_pane != null) {
953 right.remove(scroll_pane);
954 }
955 else {
956 right.remove(previous_pane);
957 }
958 previous_pane = null;
959 scroll_pane = null;
960 }
961 if(node != null && node.equals(building)) {
962 previous_pane = options_pane.buildBuild(null);
963 scroll_pane = new JScrollPane(previous_pane);
964 right.add(scroll_pane, BorderLayout.CENTER);
965 //target_pane.add(previous_pane, BorderLayout.CENTER);
966 }
967 else if(node != null && node.equals(importing)) {
968 previous_pane = options_pane.buildImport(null);
969 scroll_pane = new JScrollPane(previous_pane);
970 right.add(scroll_pane, BorderLayout.CENTER);
971 //target_pane.add(previous_pane, BorderLayout.CENTER);
972 }
973 else if(node != null && node.equals(scheduling)) {
974 //build_button.setActionCommand(Dictionary.get("CreatePane.Schedule_Build"));
975 //build_button.setText(Dictionary.get("CreatePane.Schedule_Build"));
976
977 previous_pane = options_pane.buildSchedule(null);
978 scroll_pane = new JScrollPane(previous_pane);
979 right.add(scroll_pane, BorderLayout.CENTER);
980 }
981 else {
982 if (options_pane != null) {
983 previous_pane = options_pane.buildLog();
984 right.add(previous_pane, BorderLayout.CENTER);
985 right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time
986 ///ystem.err.println("I've added the log back to the right pane again.");
987 //target_pane.add(previous_pane, BorderLayout.CENTER);
988 }
989 }
990 //scroll_pane.setViewportView(previous_pane);
991 //previous_pane.validate();
992 right.validate();
993 //System.err.println("Current pane size: " + previous_pane.getSize());
994 //System.err.println("While its preferred size is: " + previous_pane.getPreferredSize());
995 }
996 }
997
998 /** The <strong>OptionTree</strong> is built from these nodes, each of which has several methods used in creating the option panes.
999 */
1000 private class OptionTreeNode
1001 extends DefaultMutableTreeNode
1002 implements Comparable {
1003 /** The text label given to this node in the tree. */
1004 private String title = null;
1005 /** a tool tip to be used for this node in the tree */
1006 private String tool_tip = null;
1007 /** Constructor.
1008 * @param title The <strong>String</strong> which serves as this nodes title.
1009 */
1010 public OptionTreeNode(String title) {
1011 super();
1012 this.title = title;
1013 }
1014
1015 /** This method compares two nodes for ordering.
1016 * @param obj The <strong>Object</strong> to compare to.
1017 * @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.
1018 */
1019 public int compareTo(Object obj) {
1020 return title.compareTo(obj.toString());
1021 }
1022
1023 /** This method checks if two nodes are equivalent.
1024 * @param obj The <strong>Object</strong> to be tested against.
1025 * @return A <strong>boolean</strong> which is <i>true</i> if the objects are equal, <i>false</i> otherwise.
1026 */
1027 public boolean equals(Object obj) {
1028 if(compareTo(obj) == 0) {
1029 return true;
1030 }
1031 return false;
1032 }
1033
1034 /** get the tool tip */
1035 public String getToolTipText() {
1036 return tool_tip;
1037 }
1038
1039 /** set the tool tip */
1040 public void setToolTipText(String tip) {
1041 tool_tip = tip;
1042 }
1043
1044 /** Method to translate this node into a textual representation.
1045 * @return A <strong>String</strong> which in this case is the title.
1046 */
1047 public String toString() {
1048 return title;
1049 }
1050 }
1051
1052 // Adds tooltips to the tree nodes
1053 private class ToolTipTreeCellRenderer
1054 extends DefaultTreeCellRenderer {
1055
1056 public Component getTreeCellRendererComponent(JTree tree,
1057 Object value,
1058 boolean sel,
1059 boolean expanded,
1060 boolean leaf,
1061 int row,
1062 boolean hasFocus) {
1063
1064 super.getTreeCellRendererComponent(tree, value, sel,
1065 expanded, leaf, row,
1066 hasFocus);
1067 if (value instanceof OptionTreeNode) {
1068 String tip = ((OptionTreeNode) value).getToolTipText();
1069 if (tip != null) {
1070 setToolTipText(tip);
1071 }
1072 }
1073 return this;
1074 }
1075 }
1076}
Note: See TracBrowser for help on using the repository browser.