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

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

removed a few commented out bits of code. Only display the schedule options tab if CollectionManager.canDoScheduling(). this effectively removes it for gs3 - need to update schedule.pl to work in gs3 context before it will work.

  • Property svn:keywords set to Author Date Id Revision
File size: 46.3 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 }
410 else {
411 sargument_configuration_panel = new JPanel();
412 }
413 sargument_configuration_panel.setComponentOrientation(Dictionary.getOrientation());
414 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
415 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
416 sargument_configuration_scroll.setComponentOrientation(Dictionary.getOrientation());
417
418 slower_panel.setLayout(new BorderLayout());
419 slower_panel.add(sinner_panel, BorderLayout.NORTH);
420 if(current_mode < THRESHOLD) {
421 slower_panel.add(log_scroll, BorderLayout.CENTER);
422 }
423
424 simple_panel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, sargument_configuration_scroll, slower_panel);
425 simple_panel.setComponentOrientation(Dictionary.getOrientation());
426 // Main pane
427 main_pane = new JPanel(card_layout);
428 main_pane.setComponentOrientation(Dictionary.getOrientation());
429 if(current_mode < THRESHOLD) { // Simple mode - add first
430 main_pane.add(simple_panel, SIMPLE);
431 }
432 main_pane.add(control_pane, CONTROL);
433 main_pane.add(progress_pane, PROGRESS);
434 if(current_mode >= THRESHOLD) { // Expert mode - add last
435 main_pane.add(simple_panel, SIMPLE);
436 }
437
438 this.setLayout(new BorderLayout());
439 this.add(main_pane, BorderLayout.CENTER);
440 }
441
442 /** 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.
443 * @see org.greenstone.gatherer.Gatherer
444 * @see org.greenstone.gatherer.collection.CollectionManager
445 * @see org.greenstone.gatherer.gui.CreatePane.OptionTree
446 */
447 public void gainFocus() {
448 if(Configuration.getMode() < THRESHOLD) {
449 card_layout.show(main_pane, SIMPLE);
450 }
451 else if(!processing) {
452 // Move the buttons to control
453 control_pane.add(button_pane, BorderLayout.SOUTH);
454 card_layout.show(main_pane, CONTROL);
455 }
456 else {
457 // Move the buttons to progress
458 progress_pane.add(button_pane, BorderLayout.SOUTH);
459 card_layout.show(main_pane, PROGRESS);
460 }
461 // Refresh the set of controls.
462 TreePath path = tree.getSelectionPath();
463 tree.clearSelection();
464 tree.setSelectionPath(path);
465
466 }
467
468 /** We are informed when this view pane loses focus so we can update build options. */
469 public void loseFocus() {
470 tree.valueChanged(null);
471 }
472
473 /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell.
474 * @param event A <strong>GShellEvent</strong> that contains, amoung other things, the message.
475 */
476 public synchronized void message(GShellEvent event) {
477 // Ignore the messages from RecPlug (used for progress bars)
478 if (event.getMessage().startsWith("import.pl> RecPlug - ")) {
479 return;
480 }
481 document.appendLine(event.getMessage());
482 log_textarea.setCaretPosition(document.getLengthToNearestLine());
483 }
484
485 /** Called when the detail mode has changed which in turn may cause several import/build configuration arguments to be available/hidden
486 * @param mode the new mode as an int
487 */
488 public void modeChanged(int mode) {
489 // If we are below the complexity threshold ensure the simple controls are being shown
490 if(Configuration.getMode() < THRESHOLD) {
491 // Update the arguments
492 simple_panel.remove(sargument_configuration_scroll);
493 if(options_pane != null) {
494 sargument_configuration_panel = options_pane.buildImport(null);
495 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
496 }
497 else {
498 sargument_configuration_panel = new JPanel();
499 }
500 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
501 sargument_configuration_panel.setComponentOrientation(Dictionary.getOrientation());
502 sargument_configuration_scroll.setComponentOrientation(Dictionary.getOrientation());
503 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
504 simple_panel.setTopComponent(sargument_configuration_scroll);
505 // Remove the shared components from the expert panels
506 progress_pane.remove(log_scroll);
507 // And add to simple one
508 slower_panel.add(log_scroll, BorderLayout.CENTER);
509 // And bring the card to the front
510 card_layout.show(main_pane, SIMPLE);
511 }
512 // And if we are above the threshold change to the complex controls
513 else {
514 // Remove the shared components from the simple panel
515 slower_panel.remove(log_scroll);
516 // And add then to the expert ones
517 progress_pane.add(log_scroll, BorderLayout.CENTER);
518 // And bring the appropriate card to the front
519 if(!processing) {
520 control_pane.add(button_pane, BorderLayout.SOUTH);
521 card_layout.show(main_pane, CONTROL);
522 }
523 else {
524 progress_pane.add(button_pane, BorderLayout.SOUTH);
525 card_layout.show(main_pane, PROGRESS);
526 }
527 }
528 tree.valueChanged(null); // Ensure tree argument panels are rebuilt
529 }
530
531 /** 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.
532 * @param event A <strong>GShellEvent</strong> that contains details of the initial state of the <strong>GShell</strong> before task comencement.
533 */
534 public synchronized void processBegun(GShellEvent event) {
535 // We don't care. We'll get a more acurate start from the progress monitors.
536 }
537 /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task.
538 * @param event A <strong>GShellEvent</strong> that contains details of the final state of the <strong>GShell</strong> after task completion.
539 */
540 public synchronized void processComplete(GShellEvent event) {
541 DebugStream.println("In CreatePane::processComplete(" + event.getType() + ")...");
542 if(event.getStatus() == GShell.OK) {
543 if(event.getType() == GShell.SCHEDULE) {
544
545 processing = false;
546 build_button.setEnabled(true);
547 cancel_button.setEnabled(false);
548 //preview_button.setEnabled(true);
549 //only enable preview if the collection has been built.
550 preview_button.setEnabled(Gatherer.c_man.built());
551 simple_build_button.setEnabled(true);
552 simple_cancel_button.setEnabled(false);
553 simple_preview_button.setEnabled(Gatherer.c_man.built());
554 int status = event.getStatus();
555 document.setSpecialCharacter(OptionsPane.SCHEDULED);
556 options_pane.resetFileEntry();
557 build_monitor.reset();
558 import_monitor.reset();
559 if(Configuration.getMode() >= THRESHOLD) {
560 control_pane.add(button_pane, BorderLayout.SOUTH);
561 card_layout.show(main_pane, CONTROL);
562 }
563 }
564 else if(event.getType() == GShell.BUILD) {
565 processing = false;
566 build_button.setEnabled(true);
567 cancel_button.setEnabled(false);
568 preview_button.setEnabled(Gatherer.c_man.built());
569 simple_build_button.setEnabled(true);
570 simple_cancel_button.setEnabled(false);
571 simple_preview_button.setEnabled(Gatherer.c_man.built());
572 int status = event.getStatus();
573 document.setSpecialCharacter(OptionsPane.SUCCESSFUL);
574 options_pane.resetFileEntry();
575 build_monitor.reset();
576 import_monitor.reset();
577 if(Configuration.getMode() >= THRESHOLD) {
578 control_pane.add(button_pane, BorderLayout.SOUTH);
579 card_layout.show(main_pane, CONTROL);
580 }
581 }
582 // Otherwise its completed import but still got build to go
583 }
584 else {
585 processing = false;
586 cancel_button.setEnabled(false);
587 build_button.setEnabled(true);
588 // The build may have failed, but a previous index may still be in place
589 preview_button.setEnabled(Gatherer.c_man.built());
590
591 simple_build_button.setEnabled(true);
592 simple_cancel_button.setEnabled(false);
593 simple_preview_button.setEnabled(Gatherer.c_man.built());
594 if(event.getStatus() == GShell.CANCELLED) {
595 document.setSpecialCharacter(OptionsPane.CANCELLED);
596 }
597 else {
598 document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL);
599 }
600 options_pane.resetFileEntry();
601 if(Configuration.getMode() >= THRESHOLD) {
602 control_pane.add(button_pane, BorderLayout.SOUTH);
603 card_layout.show(main_pane, CONTROL);
604 }
605 }
606 }
607
608
609 /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating.
610 * @param ready A <strong>boolean</strong> indicating if a collection is currently available.
611 * @see org.greenstone.gatherer.Gatherer
612 * @see org.greenstone.gatherer.collection.CollectionManager
613 * @see org.greenstone.gatherer.gui.BuildOptions
614 * @see org.greenstone.gatherer.gui.OptionsPane
615 */
616 public void refresh(int refresh_reason, boolean ready)
617 {
618 if (Gatherer.c_man == null || !ready) {
619 return;
620 }
621 Collection current_collection = Gatherer.c_man.getCollection();
622 if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) {
623 this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options, current_collection.schedule_options);
624 if (previous_collection != null) {
625 // clear the log
626 Document log_document = log_textarea.getDocument();
627 if (log_document instanceof AppendLineOnlyFileDocument) {
628 ((AppendLineOnlyFileDocument) log_document).destroy();
629 }
630 }
631 previous_collection = current_collection;
632
633 }
634 // If we are in simple mode, we have to rebuild the simple arguments list
635 if(Configuration.getMode() < THRESHOLD) {
636 simple_panel.remove(sargument_configuration_scroll);
637 sargument_configuration_panel = options_pane.buildImport(null);
638 sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
639 //if(CollectionManager.canDoScheduling()) {
640 //sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);
641 //}
642 sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
643 sargument_configuration_scroll.setComponentOrientation(Dictionary.getOrientation());
644 sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
645 simple_panel.setTopComponent(sargument_configuration_scroll);
646 }
647 tree.valueChanged(null);
648
649 // Validate the preview button
650 if (Gatherer.c_man.built() && Configuration.library_url != null) {
651 preview_button.setEnabled(true);
652 simple_preview_button.setEnabled(true);
653 }
654 else {
655 preview_button.setEnabled(false);
656 simple_preview_button.setEnabled(false);
657 }
658 }
659
660 /** This class serves as the listener for actions on the build button. */
661 private class BuildButtonListener
662 implements ActionListener {
663 /**
664 * This method checks to see what needs to be done for a build, and starts the process off.
665 * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection.
666 * However, this doesn't always happen, as sometimes an incremental build will do :-)
667 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
668 * @see org.greenstone.gatherer.Gatherer
669 * @see org.greenstone.gatherer.collection.CollectionManager
670 * @see org.greenstone.gatherer.gui.BuildOptions
671 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
672 */
673 public void actionPerformed(ActionEvent event) {
674 Collection collection = Gatherer.c_man.getCollection();
675 String collection_name = collection.getName();
676
677 //if button is labelled for Building
678 if(event.getActionCommand().equals(Dictionary.get("CreatePane.Build_Collection"))) {
679
680 //set a static variable marking whether this is a "Complete" or "Minimal" build
681 CollectionDesignManager.setCompleteBuild( full_build_radio_button.isSelected() );
682
683 //do the import and build, skipping import if possible
684 /*if( !CollectionDesignManager.isCompleteBuild() &&
685 !collection.getMetadataChanged() && !collection.getFilesChanged() && Gatherer.c_man.imported() &&
686 CollectionDesignManager.getRebuildTypeRequired() <= CollectionDesignManager.BUILDCOL
687 ) {
688 // Just do build (no import)
689 DebugStream.println("Just want to run buildcol.pl");
690 prepareForBuild();
691 Gatherer.c_man.buildCollection();
692 }
693 else {
694 */
695 prepareForBuild();
696 Gatherer.c_man.importCollection(); //This starts the building process.
697 /*
698 }
699 */
700
701 } else { //button is labelled for setting up scheduling
702
703 //this needs to be called to configure buttons... but no building is done
704 prepareForBuild();
705 Gatherer.c_man.scheduleBuild();
706 }
707 //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
708 }
709
710
711 /**
712 * This does some stuff that is needed before a collection can be built.
713 * For example, buttons are enabled/disabled, and certain flags are set.
714 * This is called from {@link actionPerformed(ActionEvent)}
715 */
716 private void prepareForBuild() {
717 // First we force the build options to be updated if we haven't already.
718 tree.valueChanged(null);
719
720 // Remember that for lower thresholds the above doesn't work, so try this instead
721 if(Configuration.getMode() < THRESHOLD) {
722 options_pane.update(sargument_configuration_panel);
723 }
724
725 // Now go about building.
726 build_button.setEnabled(false);
727 cancel_button.setEnabled(true);
728 preview_button.setEnabled(false);
729
730 simple_build_button.setEnabled(false);
731 simple_cancel_button.setEnabled(true);
732 simple_preview_button.setEnabled(false);
733
734 document = options_pane.createNewLogDocument();
735 log_textarea.setDocument(document);
736 options_pane.log_textarea.setDocument(document);
737 // Change the view.
738 processing = true;
739 if(Configuration.getMode() >= THRESHOLD) {
740 progress_pane.add(button_pane, BorderLayout.SOUTH);
741 card_layout.show(main_pane, PROGRESS);
742 }
743 // Reset the stop flag in all the process monitors, just incase.
744 ((GBuildProgressMonitor)build_monitor).reset();
745 import_monitor.setStop(false);
746 }
747 }
748
749 /** I hope this works. Wendy */
750 private class BuildSimpleButtonListener
751 implements ActionListener {
752 /**
753 * This method checks to see what needs to be done for a build, and starts the process off.
754 * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection.
755 * However, this doesn't always happen, as sometimes an incremental build will do :-)
756 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
757 * @see org.greenstone.gatherer.Gatherer
758 * @see org.greenstone.gatherer.collection.CollectionManager
759 * @see org.greenstone.gatherer.gui.BuildOptions
760 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
761 */
762 public void actionPerformed(ActionEvent event) {
763 Collection collection = Gatherer.c_man.getCollection();
764 String collection_name = collection.getName();
765
766 //set a static variable marking whether this is a "Complete" or "Minimal" build
767 CollectionDesignManager.setCompleteBuild( full_build_radio_button.isSelected() );
768
769 //do the import and build, skipping import if possible
770 /*if( !CollectionDesignManager.isCompleteBuild() &&
771 !collection.getMetadataChanged() && !collection.getFilesChanged() && Gatherer.c_man.imported() &&
772 CollectionDesignManager.getRebuildTypeRequired() <= CollectionDesignManager.BUILDCOL
773 ) {
774 // Just do build (no import)
775 DebugStream.println("Just want to run buildcol.pl");
776 prepareForBuild();
777 Gatherer.c_man.buildCollection();
778 }
779 else {
780 */
781 prepareForBuild();
782 Gatherer.c_man.importCollection(); //This starts the building process.
783 /*
784 }
785 */
786
787 //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
788 }
789
790 /**
791 * This does some stuff that is needed before a collection can be built.
792 * For example, buttons are enabled/disabled, and certain flags are set.
793 * This is called from {@link actionPerformed(ActionEvent)}
794 */
795 private void prepareForBuild() {
796 // First we force the build options to be updated if we haven't already.
797 tree.valueChanged(null);
798
799 // Remember that for lower thresholds the above doesn't work, so try this instead
800 if(Configuration.getMode() < THRESHOLD) {
801 options_pane.update(sargument_configuration_panel);
802 }
803
804 // Now go about building.
805 build_button.setEnabled(false);
806 cancel_button.setEnabled(true);
807 preview_button.setEnabled(false);
808
809 simple_build_button.setEnabled(false);
810 simple_cancel_button.setEnabled(true);
811 simple_preview_button.setEnabled(false);
812
813 document = options_pane.createNewLogDocument();
814 log_textarea.setDocument(document);
815 options_pane.log_textarea.setDocument(document);
816 // Change the view.
817 processing = true;
818 if(Configuration.getMode() >= THRESHOLD) {
819 progress_pane.add(button_pane, BorderLayout.SOUTH);
820 card_layout.show(main_pane, PROGRESS);
821 }
822 // Reset the stop flag in all the process monitors, just incase.
823 ((GBuildProgressMonitor)build_monitor).reset();
824 import_monitor.setStop(false);
825 }
826 }
827
828
829 /** This class serves as the listener for actions on the cancel button. */
830 private class CancelButtonListener
831 implements ActionListener {
832 /** 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.
833 * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about.
834 * @see org.greenstone.gatherer.Gatherer
835 * @see org.greenstone.gatherer.collection.CollectionManager
836 * @see org.greenstone.gatherer.gui.BuildOptions
837 * @see org.greenstone.gatherer.shell.GShellProgressMonitor
838 */
839 public void actionPerformed(ActionEvent event) {
840 build_button.setEnabled(false);
841 cancel_button.setEnabled(false);
842 preview_button.setEnabled(false);
843
844 simple_build_button.setEnabled(false);
845 simple_cancel_button.setEnabled(false);
846 simple_preview_button.setEnabled(false);
847
848 processing = false;
849 document.setSpecialCharacter(OptionsPane.CANCELLED);
850 if(Configuration.getMode() >= THRESHOLD) {
851 control_pane.add(button_pane, BorderLayout.SOUTH);
852 card_layout.show(main_pane, CONTROL);
853 }
854 // Set the stop flag in all the process monitor.
855 import_monitor.setStop(true);
856 import_monitor.reset();
857 build_monitor.setStop(true);
858 build_monitor.reset();
859
860 // Remove the collection lock.
861 //Gatherer.g_man.lockCollection(false, false);
862 }
863 }
864
865
866 /** 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. */
867 private class OptionTree
868 extends JTree
869 implements TreeSelectionListener {
870 /** The model behind the tree. */
871 private DefaultTreeModel model = null;
872 /** The previous options view displayed, which is sometimes needed to refresh properly. */
873 private JPanel previous_pane = null;
874 /** The node corresponding to the building options view. */
875 private OptionTreeNode building = null;
876 /** The node corresponding to the importing options view. */
877 private OptionTreeNode importing = null;
878 /** The node corresponding to the scheduling options view. */
879 private OptionTreeNode scheduling = null;
880 /** The node corresponding to the log view. */
881 private OptionTreeNode log = null;
882 /** The root node of the options tree, which has no associated options view. */
883 private OptionTreeNode options = null;
884 /** Constructor.
885 * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode
886 */
887 public OptionTree() {
888 super();
889 this.setComponentOrientation(Dictionary.getOrientation());
890 ToolTipManager.sharedInstance().registerComponent(this);
891 addTreeSelectionListener(this);
892 getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
893 setCellRenderer(new ToolTipTreeCellRenderer());
894 setRootVisible(false);
895 setToggleClickCount(1);
896
897 // Create tree.
898 building = new OptionTreeNode(Dictionary.get("CreatePane.Build"));
899 building.setToolTipText(Dictionary.get("CreatePane.Build_Tooltip"));
900 importing = new OptionTreeNode(Dictionary.get("CreatePane.Import"));
901 importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip"));
902 if (CollectionManager.canDoScheduling()) {
903 scheduling = new OptionTreeNode(Dictionary.get("CreatePane.Schedule"));
904 scheduling.setToolTipText(Dictionary.get("CreatePane.Schedule_Tooltip"));
905
906 }
907 log = new OptionTreeNode(Dictionary.get("CreatePane.Log"));
908 log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip"));
909 options = new OptionTreeNode(Dictionary.get("CreatePane.Options"));
910
911 model = new DefaultTreeModel(options);
912 setModel(model);
913 model.insertNodeInto(importing, options, 0);
914 model.insertNodeInto(building, options, 1);
915 if (CollectionManager.canDoScheduling()) {
916 model.insertNodeInto(scheduling, options, 2);
917 model.insertNodeInto(log, options, 3);
918 } else {
919 model.insertNodeInto(log, options, 2);
920 }
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 && CollectionManager.canDoScheduling() && 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.