/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * *

* * Author: John Thompson, Greenstone Digital Library, University of Waikato * *

* * Copyright (C) 1999 New Zealand Digital Library Project * *

* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * *

* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * *

* * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.gui; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.tree.*; import org.greenstone.gatherer.DebugStream; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.RemoteGreenstoneServer; import org.greenstone.gatherer.cdm.SearchTypeManager; import org.greenstone.gatherer.cdm.CollectionDesignManager; import org.greenstone.gatherer.collection.Collection; import org.greenstone.gatherer.util.Utility; import org.greenstone.gatherer.util.ZipTools; import org.greenstone.gatherer.shell.GBasicProgressMonitor; import org.greenstone.gatherer.shell.GBuildProgressMonitor; import org.greenstone.gatherer.shell.GImportProgressMonitor; import org.greenstone.gatherer.shell.GShell; import org.greenstone.gatherer.shell.GShellEvent; import org.greenstone.gatherer.shell.GShellListener; import org.greenstone.gatherer.shell.GShellProgressMonitor; import org.greenstone.gatherer.util.AppendLineOnlyFileDocument; import org.greenstone.gatherer.util.StaticStrings; /** 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.

* @author John Thompson, Greenstone Digital Library, University of Waikato * @version 2.3 */ public class CreatePane extends JPanel implements GShellListener { static private Dimension ARGUMENT_SIZE = new Dimension(800,90); /** The threshold for when the simple view is replaced by the complex one. */ static private final int THRESHOLD = Configuration.EXPERT_MODE; /** An identifier for the control panel within the card layout. */ static private String CONTROL = "Control"; /** An identifier for the progress panel within the card layout. */ static private String PROGRESS = "Progress"; /** An identifier for the simple panel within the card layout. */ static private String SIMPLE = "Simple"; /** Determines the current view that should be shown for this pane. */ public boolean processing = false; /** The options pane generates all the various option sheet configuations. */ public OptionsPane options_pane = null; private AppendLineOnlyFileDocument document; /** A card layout is used to store the separate configuration and progress panes. */ private CardLayout card_layout = null; /** Stores a reference to the current collection. */ private Collection previous_collection = null; /** This monitor tracks the build processes progress. */ private GShellProgressMonitor build_monitor = null; /** This monitor tracks the import processes progress. */ private GShellProgressMonitor import_monitor = null; /** The button for begining the building processes. */ private JButton build_button = null; /** The button for stopping the building processes. */ private JButton cancel_button = null; /** The button for viewing the collection. */ private JButton preview_button = null; private JButton simple_build_button; private JButton simple_cancel_button; private JButton simple_preview_button; /** The radio buttons for chnaging the build type (incremental/full) */ private JRadioButton full_build_radio_button; private JRadioButton incremental_build_radio_button; private JRadioButton sfull_build_radio_button; private JRadioButton sincremental_build_radio_button; /** The label displaying the number of documents in this collection. */ private JLabel document_count = null; /** The label alongside the build progress bar gets some special treatment so... */ private JLabel progress_build_label = null; /** The label alongside the import progress bar gets some special treatment so... */ private JLabel progress_import_label = null; private JPanel bar_area; /** The panel on which buttons are rendered on higher detail modes. */ private JPanel button_pane; /** The pane which contains the controls for configuration. */ private JPanel control_pane = null; /** The pane which has the card layout as its manager. */ private JPanel main_pane = null; /** The pane which contains the progress information. */ private JPanel progress_pane = null; /** The pane on the right-hand side - shows the requested options view */ private JPanel right = null; /** The simple panel on which all of the available arguments are rendered. */ private JPanel sargument_configuration_panel; /** The panel on which buttons are rendered on lower details modes. */ private JPanel sbutton_panel; /** A simplified version for lower detail modes containing both the control and progress panes smooshed together. */ private JPanel simple_panel; /** The inner panel of the simple pane which is global so that the bar_area can be added and removed from it. */ private JPanel sinner_panel; /** The outer panel of the simple pane which is global so that the arguments pane can be added and removed from it. */ private JPanel souter_panel; /** The scrolling pane for the log. */ private JScrollPane log_scroll; /** The scrolling pane the simple arguments are rendered within. */ private JScrollPane sargument_configuration_scroll; /** 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 */ private JScrollPane scroll_pane; /** The message log for the entire session. */ private JTextArea log_textarea; /** A tree used to display the currently available option views. */ private OptionTree tree = null; /** An array used to pass arguments with dictionary calls. */ private String args[] = null; /** The homepage address of the current collection */ private String homepage = null; /** The constructor creates important helper classes, and initializes all the components. * @see org.greenstone.gatherer.collection.CollectionManager * @see org.greenstone.gatherer.gui.BuildOptions * @see org.greenstone.gatherer.gui.CreatePane.BuildButtonListener * @see org.greenstone.gatherer.gui.CreatePane.CancelButtonListener * @see org.greenstone.gatherer.gui.CreatePane.OptionTree * @see org.greenstone.gatherer.gui.OptionsPane * @see org.greenstone.gatherer.shell.GBasicProgressMonitor * @see org.greenstone.gatherer.shell.GBuildProgressMonitor * @see org.greenstone.gatherer.shell.GImportProgressMonitor * @see org.greenstone.gatherer.shell.GShellProgressMonitor */ public CreatePane() { Collection collection = Gatherer.c_man.getCollection(); log_textarea = new JTextArea(); log_scroll = new JScrollPane(log_textarea); // Create components card_layout = new CardLayout(); // Control Pane control_pane = new JPanel(); tree = new OptionTree(); button_pane = new JPanel(); // Progress Pane progress_pane = new JPanel(); // One owner of the bar component bar_area = new JPanel(); // This component will be shared about progress_import_label = new JLabel(); Dictionary.registerText(progress_import_label, "CreatePane.Import_Progress"); import_monitor = new GImportProgressMonitor(); //GBasicProgressMonitor(); Gatherer.c_man.registerImportMonitor(import_monitor); progress_build_label = new JLabel(); Dictionary.registerText(progress_build_label, "CreatePane.Build_Progress"); build_monitor = new GBuildProgressMonitor(import_monitor.getSharedProgress()); //GBasicProgressMonitor(); Gatherer.c_man.registerBuildMonitor(build_monitor); // And the simple panel simple_panel = new JPanel(); sbutton_panel = new JPanel(); sinner_panel = new JPanel(); //Radio buttons incremental_build_radio_button = new JRadioButton(); Dictionary.registerBoth(incremental_build_radio_button, "CreatePane.Incremental_Build", "CreatePane.Incremental_Build_Tooltip"); full_build_radio_button = new JRadioButton(); Dictionary.registerBoth(full_build_radio_button, "CreatePane.Full_Build", "CreatePane.Full_Build_Tooltip"); sincremental_build_radio_button = new JRadioButton(); Dictionary.registerBoth(sincremental_build_radio_button, "CreatePane.Incremental_Build", "CreatePane.Incremental_Build_Tooltip"); sfull_build_radio_button = new JRadioButton(); Dictionary.registerBoth(sfull_build_radio_button, "CreatePane.Full_Build", "CreatePane.Full_Build_Tooltip"); // Buttons BuildButtonListener bbl = new BuildButtonListener(); CancelButtonListener cbl = new CancelButtonListener(); PreviewButtonListener pbl = new PreviewButtonListener(); build_button = new GLIButton(); build_button.addActionListener(bbl); build_button.setMnemonic(KeyEvent.VK_B); Dictionary.registerBoth(build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip"); cancel_button = new GLIButton(); cancel_button.addActionListener(cbl); cancel_button.setEnabled(false); cancel_button.setMnemonic(KeyEvent.VK_C); Dictionary.registerBoth(cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip"); preview_button = new GLIButton(); preview_button.addActionListener(pbl); if(Gatherer.c_man != null) { preview_button.setEnabled(Gatherer.c_man.built()); } else { preview_button.setEnabled(false); } preview_button.setMnemonic(KeyEvent.VK_P); Dictionary.registerBoth(preview_button, "CreatePane.Preview_Collection", "CreatePane.Preview_Collection_Tooltip"); simple_build_button = new GLIButton(); simple_build_button.addActionListener(bbl); simple_build_button.setMnemonic(KeyEvent.VK_B); Dictionary.registerBoth(simple_build_button, "CreatePane.Build_Collection", "CreatePane.Build_Collection_Tooltip"); simple_cancel_button = new GLIButton(); simple_cancel_button.addActionListener(cbl); simple_cancel_button.setEnabled(false); simple_cancel_button.setMnemonic(KeyEvent.VK_C); Dictionary.registerBoth(simple_cancel_button, "CreatePane.Cancel_Build", "CreatePane.Cancel_Build_Tooltip"); simple_preview_button = new GLIButton(); simple_preview_button.addActionListener(pbl); if(Gatherer.c_man != null) { simple_preview_button.setEnabled(Gatherer.c_man.built()); } else { simple_preview_button.setEnabled(false); } simple_preview_button.setMnemonic(KeyEvent.VK_P); Dictionary.registerBoth(simple_preview_button, "CreatePane.Preview_Collection", "CreatePane.Preview_Collection_Tooltip"); bbl = null; cbl = null; pbl = null; } public void destroy() { if(document != null) { document.destroy(); } } /** This method is called to actually layout the components. * @see org.greenstone.gatherer.Configuration * @see org.greenstone.gatherer.Gatherer */ public void display() { int current_mode = Configuration.getMode(); //Complete/incremental build options panel //For some reason I need to create seperate objects for each mode. Is there a better way?? ButtonGroup build_type_group = new ButtonGroup(); build_type_group.add(incremental_build_radio_button); incremental_build_radio_button.setSelected(true); //Have incremental rebuild on by default build_type_group.add(full_build_radio_button); ButtonGroup sbuild_type_group = new ButtonGroup(); sbuild_type_group.add(sincremental_build_radio_button); sincremental_build_radio_button.setSelected(true); sbuild_type_group.add(sfull_build_radio_button); JPanel build_type_pane = new JPanel(new GridLayout(2,1)); build_type_pane.add(full_build_radio_button); build_type_pane.add(incremental_build_radio_button); JPanel sbuild_type_pane = new JPanel(new GridLayout(2,1)); sbuild_type_pane.add(sfull_build_radio_button); sbuild_type_pane.add(sincremental_build_radio_button); // Build control_pane JPanel left = new JPanel(); left.setBorder(BorderFactory.createEmptyBorder(0,5,5,5)); left.setLayout(new BorderLayout()); left.add(tree, BorderLayout.CENTER); left.add(build_type_pane, BorderLayout.SOUTH); //left.add(full_build_radio_button, BorderLayout.SOUTH); right = new JPanel(); right.setBorder(BorderFactory.createEmptyBorder(0,0,5,5)); right.setLayout(new BorderLayout()); JPanel options_area = new JPanel(); options_area.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createTitledBorder(Dictionary.get("CreatePane.Options_Title")))); options_area.setLayout(new BorderLayout()); options_area.add(left, BorderLayout.WEST); options_area.add(right, BorderLayout.CENTER); button_pane = new JPanel(); button_pane.setBorder(BorderFactory.createEmptyBorder(5,10,10,10)); button_pane.setLayout(new GridLayout(1,4)); button_pane.add(build_button); button_pane.add(cancel_button); button_pane.add(preview_button); control_pane.setLayout(new BorderLayout()); control_pane.add(options_area, BorderLayout.CENTER); control_pane.add(button_pane, BorderLayout.SOUTH); // Build progress_pane JPanel labels_pane = new JPanel(); labels_pane.setLayout(new GridLayout(2,1,0,5)); labels_pane.add(progress_import_label); labels_pane.add(progress_build_label); JPanel monitors_pane = new JPanel(); monitors_pane.setLayout(new GridLayout(2,1,0,5)); monitors_pane.add(import_monitor.getProgress()); monitors_pane.add(build_monitor.getProgress()); bar_area.setBorder(BorderFactory.createEmptyBorder(10,10,5,10)); bar_area.setLayout(new BorderLayout(5,5)); bar_area.add(labels_pane, BorderLayout.WEST); bar_area.add(monitors_pane, BorderLayout.CENTER); progress_pane.setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); progress_pane.setLayout(new BorderLayout()); progress_pane.add(bar_area, BorderLayout.NORTH); if(current_mode >= THRESHOLD) { progress_pane.add(log_scroll, BorderLayout.CENTER); } // Simple panel sbutton_panel.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); sbutton_panel.setLayout(new GridLayout(1,3)); sbutton_panel.add(simple_build_button); sbutton_panel.add(simple_cancel_button); sbutton_panel.add(simple_preview_button); JPanel simple_bar_area = new JPanel(new GridLayout(2,1)); simple_bar_area.setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); simple_bar_area.add(import_monitor.getSharedProgress()); simple_bar_area.add(sbutton_panel); sinner_panel.setBorder(BorderFactory.createEmptyBorder(5,0,5,0)); sinner_panel.setLayout(new BorderLayout()); sinner_panel.add(sbuild_type_pane, BorderLayout.WEST); //sinner_panel.add(full_build_radio_button, BorderLayout.WEST); sinner_panel.add(simple_bar_area, BorderLayout.CENTER); if(options_pane != null) { sargument_configuration_panel = options_pane.buildImport(null); sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); } else { sargument_configuration_panel = new JPanel(); } sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel); sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE); souter_panel = new JPanel(); souter_panel.setSize(new Dimension(400,800)); souter_panel.setLayout(new GridLayout(2,1)); souter_panel.add(sargument_configuration_scroll); souter_panel.add(sinner_panel); simple_panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); simple_panel.setLayout(new BorderLayout()); simple_panel.add(souter_panel, BorderLayout.NORTH); if(current_mode < THRESHOLD) { simple_panel.add(log_scroll, BorderLayout.CENTER); } // Main pane main_pane = new JPanel(card_layout); if(current_mode < THRESHOLD) { // Simple mode - add first main_pane.add(simple_panel, SIMPLE); } main_pane.add(control_pane, CONTROL); main_pane.add(progress_pane, PROGRESS); if(current_mode >= THRESHOLD) { // Expert mode - add last main_pane.add(simple_panel, SIMPLE); } this.setLayout(new BorderLayout()); this.add(main_pane, BorderLayout.CENTER); } /** 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. * @see org.greenstone.gatherer.Gatherer * @see org.greenstone.gatherer.collection.CollectionManager * @see org.greenstone.gatherer.gui.CreatePane.OptionTree */ public void gainFocus() { if(Configuration.getMode() < THRESHOLD) { card_layout.show(main_pane, SIMPLE); } else if(!processing) { // Move the buttons to control control_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, CONTROL); } else { // Move the buttons to progress progress_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, PROGRESS); } // Refresh the set of controls. TreePath path = tree.getSelectionPath(); tree.clearSelection(); tree.setSelectionPath(path); //Disable the full/incremental buttons if the collection has not been built. if(Gatherer.c_man.built()) { full_build_radio_button.setEnabled(true); incremental_build_radio_button.setEnabled(true); sfull_build_radio_button.setEnabled(true); sincremental_build_radio_button.setEnabled(true); } else { full_build_radio_button.setEnabled(false); incremental_build_radio_button.setEnabled(false); sfull_build_radio_button.setEnabled(false); sincremental_build_radio_button.setEnabled(false); } } /** We are informed when this view pane loses focus so we can update build options. */ public void loseFocus() { tree.valueChanged(null); } /** * Check to see if doing an incremental build is chosen. * If not, the full rebuild option must be chosen. * @return boolean - true if the collection should be rebuilt incrementally. */ public boolean isIncremental() { boolean incremental = false; //This is horrible. What if the mode is changed, and different options are chosen on different modes?? if(Gatherer.c_man.built()) { if(Configuration.getMode() >= THRESHOLD) { incremental = incremental_build_radio_button.isSelected(); } else { incremental = sincremental_build_radio_button.isSelected(); } } else { incremental = false; //The collection has not yet been built } return incremental; } /** All implementation of GShellListener must include this method so the listener can be informed of messages from the GShell. * @param event A GShellEvent that contains, amoung other things, the message. */ public synchronized void message(GShellEvent event) { // Ignore the messages from RecPlug with 'show_progress' set (used for progress bars) if (event.getMessage().startsWith("import.pl> RecPlug - ")) { return; } document.appendLine(event.getMessage()); log_textarea.setCaretPosition(document.getLengthToNearestLine()); } /** Called when the detail mode has changed which in turn may cause several import/build configuration arguments to be available/hidden * @param mode the new mode as an int */ public void modeChanged(int mode) { // If we are below the complexity threshold ensure the simple controls are being shown if(Configuration.getMode() < THRESHOLD) { // Update the arguments souter_panel.remove(sargument_configuration_scroll); souter_panel.remove(sinner_panel); if(options_pane != null) { sargument_configuration_panel = options_pane.buildImport(null); sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); } else { sargument_configuration_panel = new JPanel(); } sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel); sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE); souter_panel.add(sargument_configuration_scroll); souter_panel.add(sinner_panel); // Remove the shared components from the expert panels progress_pane.remove(log_scroll); // And add to simple one simple_panel.add(log_scroll, BorderLayout.CENTER); // And bring the card to the front card_layout.show(main_pane, SIMPLE); } // And if we are above the threshold change to the complex controls else { // Remove the shared components from the simple panel simple_panel.remove(log_scroll); // And add then to the expert ones progress_pane.add(log_scroll, BorderLayout.CENTER); // And bring the appropriate card to the front if(!processing) { control_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, CONTROL); } else { progress_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, PROGRESS); } } tree.valueChanged(null); // Ensure tree argument panels are rebuilt } /** 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. * @param event A GShellEvent that contains details of the initial state of the GShell before task comencement. */ public synchronized void processBegun(GShellEvent event) { // We don't care. We'll get a more acurate start from the progress monitors. } /** All implementation of GShellListener must include this method so the listener can be informed when a GShell completes its task. * @param event A GShellEvent that contains details of the final state of the GShell after task completion. */ public synchronized void processComplete(GShellEvent event) { if(event.getStatus() == GShell.OK) { if(event.getType() == GShell.BUILD) { processing = false; build_button.setEnabled(true); cancel_button.setEnabled(false); //preview_button.setEnabled(true); simple_build_button.setEnabled(true); simple_cancel_button.setEnabled(false); //simple_preview_button.setEnabled(true); int status = event.getStatus(); document.setSpecialCharacter(OptionsPane.SUCCESSFUL); options_pane.resetFileEntry(); build_monitor.reset(); import_monitor.reset(); if(Configuration.getMode() >= THRESHOLD) { control_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, CONTROL); } } // Otherwise its completed import but still got build to go } else { processing = false; cancel_button.setEnabled(false); build_button.setEnabled(true); // The build may have failed, but a previous index may still be in place //preview_button.setEnabled(Gatherer.c_man.built()); simple_build_button.setEnabled(true); simple_cancel_button.setEnabled(false); //simple_preview_button.setEnabled(Gatherer.c_man.built()); if(event.getStatus() == GShell.CANCELLED) { document.setSpecialCharacter(OptionsPane.CANCELLED); } else { document.setSpecialCharacter(OptionsPane.UNSUCCESSFUL); } options_pane.resetFileEntry(); if(Configuration.getMode() >= THRESHOLD) { control_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, CONTROL); } } } /** This method is invoked at any time there has been a significant change in the collection, such as saving, loading or creating. * @param ready A boolean indicating if a collection is currently available. * @see org.greenstone.gatherer.Gatherer * @see org.greenstone.gatherer.collection.CollectionManager * @see org.greenstone.gatherer.gui.BuildOptions * @see org.greenstone.gatherer.gui.OptionsPane */ public void refresh(int refresh_reason, boolean ready) { if (Gatherer.c_man == null || !ready) { return; } Collection current_collection = Gatherer.c_man.getCollection(); if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) { this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options); if (previous_collection != null) { // clear the log Document log_document = log_textarea.getDocument(); if (log_document instanceof AppendLineOnlyFileDocument) { ((AppendLineOnlyFileDocument) log_document).destroy(); } } previous_collection = current_collection; } // If we are in simple mode, we have to rebuild the simple arguments list if(Configuration.getMode() < THRESHOLD) { souter_panel.remove(sargument_configuration_scroll); souter_panel.remove(sinner_panel); sargument_configuration_panel = options_pane.buildImport(null); sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel); sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE); souter_panel.add(sargument_configuration_scroll); souter_panel.add(sinner_panel); } tree.valueChanged(null); // Validate the preview button if (Gatherer.c_man.built() && Configuration.library_url != null) { preview_button.setEnabled(true); simple_preview_button.setEnabled(true); } else { preview_button.setEnabled(false); simple_preview_button.setEnabled(false); } } private void configureHomeURL() { // set up the home page for the current collection Collection current_collection = Gatherer.c_man.getCollection(); String site = Configuration.site_name; // for GS3 colls String extra_args = ""; SearchTypeManager st_man = current_collection.cdm.searchtype_manager; if (!Gatherer.GS3 && st_man.isMGPPEnabled()) { // we need some more args on the url String search_types = st_man.getSearchTypes(); if (search_types.equals("")) { extra_args = "&ct=1&qt=0&qto=3"; } else if (search_types.equals("plain")) { extra_args = "&ct=1&qt=0&qto=1"; } else if (search_types.equals("form")) { extra_args = "&ct=1&qt=1&qto=2"; } else if (search_types.equals("plain,form")) { extra_args = "&ct=1&qt=0&qto=3"; } else if (search_types.equals("form,plain")) { extra_args = "&ct=1&qt=1&qto=3"; } } // Remember to add unique timestamp if (Gatherer.GS3) { 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(); } else { homepage = Configuration.library_url.toString() + "?a=p&p=about&c=" + current_collection.getName()+"&l="+Configuration.getLanguage()+extra_args + StaticStrings.TIMESTAMP_ARGUMENT + System.currentTimeMillis(); } } /** This class serves as the listener for actions on the build button. */ private class BuildButtonListener implements ActionListener { /** * This method checks to see what needs to be done for a build, and starts the process off. * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection. * However, this doesn't always happen, as sometimes an incremental build will do :-) * @param event An ActionEvent who, thanks to the power of object oriented programming, we don't give two hoots about. * @see org.greenstone.gatherer.Gatherer * @see org.greenstone.gatherer.collection.CollectionManager * @see org.greenstone.gatherer.gui.BuildOptions * @see org.greenstone.gatherer.shell.GShellProgressMonitor */ public void actionPerformed(ActionEvent event) { Collection collection = Gatherer.c_man.getCollection(); String collection_name = collection.getName(); if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) { //Only design options have changes, and we want to be smart in the way we handle them. int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired(); if(rebuildTypeRequired == CollectionDesignManager.UPDATE_COLLECT_CFG && Gatherer.isGsdlRemote) { //Special case when the GLI is an applet: Upload the collect.cfg to server //This is already handled by CollectionDesignManager.save() DebugStream.println("Just want to upload collect.cfg, but this has already been done"); } else if(rebuildTypeRequired == CollectionDesignManager.BUILDCOL) { //First upload the collect.cfg file ZipTools.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null, "", ""); RemoteGreenstoneServer.upload_url_zip(collection_name, "etc", "", null); //Just run the buildcol command. DebugStream.println("Just want to run buildcol.pl"); prepareForBuild(); Gatherer.c_man.buildCollection(); } else if(rebuildTypeRequired == CollectionDesignManager.ALL) { //Do a usual build. DebugStream.println("Want to do a complete build"); prepareForBuild(); Gatherer.c_man.importCollection(); //This starts the building process. } else { //Nothing at all needs doing. //This is bad HCI. Maybe should disable the build button in this situation? System.err.println("Want to build the collection but nothing needs doing."); } } else { //Do a complete build. prepareForBuild(); Gatherer.c_man.importCollection(); //This starts the building process. } //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent) } /** * This does some stuff that is needed before a collection can be built. * For example, buttons are enabled/disabled, and certain flags are set. * This is called from {@link actionPerformed(ActionEvent)} */ private void prepareForBuild() { // First we force the build options to be updated if we haven't already. tree.valueChanged(null); // Remember that for lower thresholds the above doesn't work, so try this instead if(Configuration.getMode() < THRESHOLD) { options_pane.update(sargument_configuration_panel); } // Now go about building. build_button.setEnabled(false); cancel_button.setEnabled(true); preview_button.setEnabled(false); simple_build_button.setEnabled(false); simple_cancel_button.setEnabled(true); simple_preview_button.setEnabled(false); document = options_pane.createNewLogDocument(); log_textarea.setDocument(document); options_pane.log_textarea.setDocument(document); // Change the view. processing = true; if(Configuration.getMode() >= THRESHOLD) { progress_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, PROGRESS); } // Reset the stop flag in all the process monitors, just incase. ((GBuildProgressMonitor)build_monitor).reset(); import_monitor.setStop(false); // Set removeold automatically. if(Gatherer.c_man.ready() && Gatherer.c_man.built()) { Gatherer.c_man.getCollection().import_options.setValue("removeold", true, null); } } } /** This class serves as the listener for actions on the cancel button. */ private class CancelButtonListener implements ActionListener { /** 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. * @param event An ActionEvent who, thanks to the power of object oriented programming, we don't give two hoots about. * @see org.greenstone.gatherer.Gatherer * @see org.greenstone.gatherer.collection.CollectionManager * @see org.greenstone.gatherer.gui.BuildOptions * @see org.greenstone.gatherer.shell.GShellProgressMonitor */ public void actionPerformed(ActionEvent event) { build_button.setEnabled(false); cancel_button.setEnabled(false); preview_button.setEnabled(false); simple_build_button.setEnabled(false); simple_cancel_button.setEnabled(false); simple_preview_button.setEnabled(false); processing = false; document.setSpecialCharacter(OptionsPane.CANCELLED); if(Configuration.getMode() >= THRESHOLD) { control_pane.add(button_pane, BorderLayout.SOUTH); card_layout.show(main_pane, CONTROL); } // Set the stop flag in all the process monitor. import_monitor.setStop(true); import_monitor.reset(); build_monitor.setStop(true); build_monitor.reset(); // Set removeold automatically. Gatherer.c_man.getCollection().import_options.setValue("removeold", true, null); // Remove the collection lock. //Gatherer.g_man.lockCollection(false, false); } } private class PreviewButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { Gatherer.c_man.getCollection().cdm.save(); // save the config file just in case configureHomeURL(); Gatherer.self.spawnBrowser(homepage); } } /** 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. */ private class OptionTree extends JTree implements TreeSelectionListener { /** The model behind the tree. */ private DefaultTreeModel model = null; /** The previous options view displayed, which is sometimes needed to refresh properly. */ private JPanel previous_pane = null; /** The node corresponding to the building options view. */ private OptionTreeNode building = null; /** The node corresponding to the importing options view. */ private OptionTreeNode importing = null; /** The node corresponding to the log view. */ private OptionTreeNode log = null; /** The root node of the options tree, which has no associated options view. */ private OptionTreeNode options = null; /** Constructor. * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode */ public OptionTree() { super(); ToolTipManager.sharedInstance().registerComponent(this); addTreeSelectionListener(this); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setCellRenderer(new ToolTipTreeCellRenderer()); setRootVisible(false); setToggleClickCount(1); // Create tree. building = new OptionTreeNode(Dictionary.get("CreatePane.Build")); building.setToolTipText(Dictionary.get("CreatePane.Build_Tooltip")); importing = new OptionTreeNode(Dictionary.get("CreatePane.Import")); importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip")); log = new OptionTreeNode(Dictionary.get("CreatePane.Log")); log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip")); options = new OptionTreeNode(Dictionary.get("CreatePane.Options")); model = new DefaultTreeModel(options); setModel(model); model.insertNodeInto(importing, options, 0); model.insertNodeInto(building, options, 1); model.insertNodeInto(log, options, 2); // Expand the root node expandPath(new TreePath(options)); } /** 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. * @param event A TreeSelectionEvent which contains all the information garnered when the event occured. * @see org.greenstone.gatherer.gui.CreatePane.OptionTreeNode */ public void valueChanged(TreeSelectionEvent event) { TreePath path = null; OptionTreeNode node = null; //if(event != null) { //path = event.getPath(); path = getSelectionPath(); if(path != null) { node = (OptionTreeNode)path.getLastPathComponent(); } //} if(previous_pane != null) { //target_pane.remove(previous_pane); options_pane.update(previous_pane); if(scroll_pane != null) { right.remove(scroll_pane); } else { right.remove(previous_pane); } previous_pane = null; scroll_pane = null; } if(node != null && node.equals(building)) { previous_pane = options_pane.buildBuild(null); scroll_pane = new JScrollPane(previous_pane); right.add(scroll_pane, BorderLayout.CENTER); //target_pane.add(previous_pane, BorderLayout.CENTER); } else if(node != null && node.equals(importing)) { previous_pane = options_pane.buildImport(null); scroll_pane = new JScrollPane(previous_pane); right.add(scroll_pane, BorderLayout.CENTER); //target_pane.add(previous_pane, BorderLayout.CENTER); } else { if (options_pane != null) { previous_pane = options_pane.buildLog(); right.add(previous_pane, BorderLayout.CENTER); right.updateUI(); // we need to repaint the log pane, cos it hasn't changed since last time ///ystem.err.println("I've added the log back to the right pane again."); //target_pane.add(previous_pane, BorderLayout.CENTER); } } //scroll_pane.setViewportView(previous_pane); //previous_pane.validate(); right.validate(); //System.err.println("Current pane size: " + previous_pane.getSize()); //System.err.println("While its preferred size is: " + previous_pane.getPreferredSize()); } } /** The OptionTree is built from these nodes, each of which has several methods used in creating the option panes. */ private class OptionTreeNode extends DefaultMutableTreeNode implements Comparable { /** The text label given to this node in the tree. */ private String title = null; /** a tool tip to be used for this node in the tree */ private String tool_tip = null; /** Constructor. * @param title The String which serves as this nodes title. */ public OptionTreeNode(String title) { super(); this.title = title; } /** This method compares two nodes for ordering. * @param obj The Object to compare to. * @return An int 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. */ public int compareTo(Object obj) { return title.compareTo(obj.toString()); } /** This method checks if two nodes are equivalent. * @param obj The Object to be tested against. * @return A boolean which is true if the objects are equal, false otherwise. */ public boolean equals(Object obj) { if(compareTo(obj) == 0) { return true; } return false; } /** get the tool tip */ public String getToolTipText() { return tool_tip; } /** set the tool tip */ public void setToolTipText(String tip) { tool_tip = tip; } /** Method to translate this node into a textual representation. * @return A String which in this case is the title. */ public String toString() { return title; } } // Adds tooltips to the tree nodes private class ToolTipTreeCellRenderer extends DefaultTreeCellRenderer { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof OptionTreeNode) { String tip = ((OptionTreeNode) value).getToolTipText(); if (tip != null) { setToolTipText(tip); } } return this; } } }