Index: gli/trunk/src/org/greenstone/gatherer/gui/CreatePane.java
===================================================================
--- gli/trunk/src/org/greenstone/gatherer/gui/CreatePane.java	(revision 16133)
+++ gli/trunk/src/org/greenstone/gatherer/gui/CreatePane.java	(revision 16134)
@@ -53,4 +53,5 @@
 import org.greenstone.gatherer.shell.GBuildProgressMonitor;
 import org.greenstone.gatherer.shell.GImportProgressMonitor;
+import org.greenstone.gatherer.shell.GScheduleProgressMonitor; 
 import org.greenstone.gatherer.shell.GShell;
 import org.greenstone.gatherer.shell.GShellEvent;
@@ -93,8 +94,12 @@
     /** This monitor tracks the import processes progress. */
     private GShellProgressMonitor import_monitor = null;
+    /** This monitor tracks the schedule processes progress. */ 
+    private GShellProgressMonitor schedule_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 setting up scheduling */
+    private JButton schedule_button = null; 
     /** The button for viewing the collection. */
     private JButton preview_button = null;
@@ -186,4 +191,11 @@
 	Gatherer.c_man.registerBuildMonitor(build_monitor);
 
+	//We only need a schedule monitor for text output. No use for a progress bar!
+	
+	//progress_schedule_label = new JLabel(Dictionary.get("CreatePane.Schedule_Progress")); 
+	
+	schedule_monitor = new GScheduleProgressMonitor(); 
+	Gatherer.c_man.registerScheduleMonitor(schedule_monitor); 
+
 	// And the simple panel
 	slower_panel = new JPanel();
@@ -222,7 +234,8 @@
 	}
 	
+	BuildSimpleButtonListener bsbl = new BuildSimpleButtonListener(); 
 	simple_build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip"));
-	simple_build_button.addActionListener(bbl);
-	
+	simple_build_button.addActionListener(bsbl);
+
 	simple_cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip"));
 	simple_cancel_button.addActionListener(cbl);
@@ -239,4 +252,5 @@
 	
 	bbl = null;
+	bsbl = null; 
 	cbl = null;
 	//pbl = null;
@@ -350,4 +364,5 @@
 	    sargument_configuration_panel = options_pane.buildImport(null);
 	    sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
+	    sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel); 
 	}
 	else {
@@ -469,4 +484,5 @@
 		sargument_configuration_panel = options_pane.buildImport(null);
 		sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
+		sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);
 	    }
 	    else {
@@ -514,9 +530,30 @@
 	DebugStream.println("In CreatePane::processComplete(" + event.getType() + ")...");
 	if(event.getStatus() == GShell.OK) {
-	    if(event.getType() == GShell.BUILD) {
+	    if(event.getType() == GShell.SCHEDULE) {
+		
+		processing = false; 
+		build_button.setEnabled(true);
+		cancel_button.setEnabled(false);
+		preview_button.setEnabled(true);
+		//only enable preview if the collection has been built. 
+		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()); 
+		int status = event.getStatus();
+		document.setSpecialCharacter(OptionsPane.SCHEDULED); 
+		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); 
+		}
+	    }
+	    else if(event.getType() == GShell.BUILD) {
 		processing = false;
 		build_button.setEnabled(true);
 		cancel_button.setEnabled(false);
-		//preview_button.setEnabled(true);
+		preview_button.setEnabled(true);
 		simple_build_button.setEnabled(true);
 		simple_cancel_button.setEnabled(false);
@@ -539,9 +576,9 @@
 	    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());
+	    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());
+	    simple_preview_button.setEnabled(Gatherer.c_man.built());
 	    if(event.getStatus() == GShell.CANCELLED) {
 		document.setSpecialCharacter(OptionsPane.CANCELLED);
@@ -573,5 +610,5 @@
 	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);
+	    this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options, current_collection.schedule_options);
 	    if (previous_collection != null) {
 		// clear the log
@@ -589,4 +626,5 @@
 	    sargument_configuration_panel = options_pane.buildImport(null);
 	    sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel);
+	    sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel); 
 	    sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel);
 	    sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE);
@@ -622,33 +660,46 @@
 	    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.BUILDCOL) {
-		    // Just run the buildcol command.
-		    DebugStream.println("Just want to run buildcol.pl");
-		    prepareForBuild();
-		    Gatherer.c_man.buildCollection(isIncremental());
-		}
-		else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
-		    // Do both import and buildcol
-		    DebugStream.println("Want to do a complete build");
+
+	    //if button is labelled for Building
+	    if(event.getActionCommand().equals(Dictionary.get("CreatePane.Build_Collection"))) { 
+
+		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.BUILDCOL) {
+			// Just run the buildcol command.
+			DebugStream.println("Just want to run buildcol.pl");
+			prepareForBuild();
+			Gatherer.c_man.buildCollection(isIncremental());
+		    }
+		    else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
+			// Do both import and buildcol
+			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?
+			JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
+		    }
+		}
+		else {
+		    //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?
-		    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
-		}
-	    }
-	    else {
-		//Do a complete build.
-		prepareForBuild();
-		Gatherer.c_man.importCollection(); //This starts the building process.
-	    }
+		} 
+
+	    } else {   //button is labelled for setting up scheduling
+
+		//this needs to be called to configure buttons... but no building is done
+		prepareForBuild(); 
+	
+		Gatherer.c_man.scheduleBuild(isIncremental()); 
+	    }
+		
 	    //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent)
 	}
-
+	    
 	/**
 	 * This does some stuff that is needed before a collection can be built.
@@ -689,5 +740,108 @@
     }
     
+    /** I hope this works. Wendy */ 
+    private class BuildSimpleButtonListener
+	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 <strong>ActionEvent</strong> 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();
+
+		//prepareForBuild(); 
+		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.BUILDCOL) {
+			// Just run the buildcol command.
+			DebugStream.println("Just want to run buildcol.pl");
+			prepareForBuild();
+			Gatherer.c_man.buildCollection(isIncremental());
+		    }
+		    else if (rebuildTypeRequired == CollectionDesignManager.ALL) {
+			// Do both import and buildcol
+			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?
+			JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required"));
+		    }
+		}
+		else {
+		    //Do a complete build.
+		    prepareForBuild();
+		    Gatherer.c_man.importCollection(); //This starts the building process.
+		}
+		
+		//only schedule in SYSTEM mode - also done in EXPERT mode, but that is handled elsewhere
+		if(Configuration.getMode() ==  Configuration.SYSTEMS_MODE) {
+		   if(Gatherer.c_man.getCollection().schedule_options.getValueEnabled("schedule")) {
+		    Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"add"); 
+		    Gatherer.c_man.getCollection().schedule_options.setValue("email",false, null); 
+		    Gatherer.c_man.getCollection().schedule_options.setValue("smtp",false, null);
+		    Gatherer.c_man.getCollection().schedule_options.setValue("toaddr",false, null);  
+		    Gatherer.c_man.getCollection().schedule_options.setValue("fromaddr",false, null); 	
+	 	    Gatherer.c_man.getCollection().schedule_options.setValue("frequency",false, null); 	
+		    Gatherer.c_man.scheduleBuild(isIncremental()); 
+		} else {
+		    //need to turn off existing scheduling
+		    Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"delete"); 
+		    Gatherer.c_man.scheduleBuild(isIncremental()); 
+		    
+		}
+		}
+	    //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);
+	}
+    }
     
+
     /** This class serves as the listener for actions on the cancel button. */
     private class CancelButtonListener
@@ -739,4 +893,6 @@
 	/** The node corresponding to the importing options view. */
 	private OptionTreeNode importing = null;
+	/** The node corresponding to the scheduling options view. */ 
+	private OptionTreeNode scheduling = null; 
 	/** The node corresponding to the log view. */
 	private OptionTreeNode log       = null;
@@ -761,4 +917,7 @@
 	    importing = new OptionTreeNode(Dictionary.get("CreatePane.Import"));
 	    importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip"));
+	    scheduling = new OptionTreeNode(Dictionary.get("CreatePane.Schedule"));
+	    scheduling.setToolTipText(Dictionary.get("CreatePane.Schedule_Tooltip")); 
+
 	    log = new OptionTreeNode(Dictionary.get("CreatePane.Log"));
 	    log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip"));
@@ -769,5 +928,6 @@
 	    model.insertNodeInto(importing, options, 0);
 	    model.insertNodeInto(building, options, 1);
-	    model.insertNodeInto(log, options, 2);
+	    model.insertNodeInto(scheduling, options, 2); 
+	    model.insertNodeInto(log, options, 3);
 	    // Expand the root node
 	    expandPath(new TreePath(options));
@@ -810,4 +970,12 @@
 		right.add(scroll_pane, BorderLayout.CENTER);
 		//target_pane.add(previous_pane, BorderLayout.CENTER);
+	    }
+	    else if(node != null && node.equals(scheduling)) { 
+		//build_button.setActionCommand(Dictionary.get("CreatePane.Schedule_Build")); 
+		//build_button.setText(Dictionary.get("CreatePane.Schedule_Build"));
+ 
+		previous_pane = options_pane.buildSchedule(null); 
+		scroll_pane = new JScrollPane(previous_pane);
+		right.add(scroll_pane, BorderLayout.CENTER);
 	    }
 	    else {
