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

Last change on this file since 8257 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

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