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

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

in processComplete, after OK from build, the preview_button was enabled, but the simple_preview_button wasn't. So have enabled both

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