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

Last change on this file since 10531 was 10531, checked in by kjdon, 19 years ago

changed the preview args for lucene collections

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