greenstone.org greenstone wiki greenstone trac planet greenstone

Changeset 16134

Show
Ignore:
Timestamp:
2008-06-24 18:54:27 (3 months ago)
Author:
osborn
Message:

Additions for Scheduling Component

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gli/trunk/src/org/greenstone/gatherer/gui/CreatePane.java

    r15862 r16134  
    5353import org.greenstone.gatherer.shell.GBuildProgressMonitor; 
    5454import org.greenstone.gatherer.shell.GImportProgressMonitor; 
     55import org.greenstone.gatherer.shell.GScheduleProgressMonitor;  
    5556import org.greenstone.gatherer.shell.GShell; 
    5657import org.greenstone.gatherer.shell.GShellEvent; 
     
    9394    /** This monitor tracks the import processes progress. */ 
    9495    private GShellProgressMonitor import_monitor = null; 
     96    /** This monitor tracks the schedule processes progress. */  
     97    private GShellProgressMonitor schedule_monitor = null;  
    9598    /** The button for begining the building processes. */ 
    9699    private JButton build_button = null; 
    97100    /** The button for stopping the building processes. */ 
    98101    private JButton cancel_button = null; 
     102    /** The button for setting up scheduling */ 
     103    private JButton schedule_button = null;  
    99104    /** The button for viewing the collection. */ 
    100105    private JButton preview_button = null; 
     
    186191        Gatherer.c_man.registerBuildMonitor(build_monitor); 
    187192 
     193        //We only need a schedule monitor for text output. No use for a progress bar! 
     194         
     195        //progress_schedule_label = new JLabel(Dictionary.get("CreatePane.Schedule_Progress"));  
     196         
     197        schedule_monitor = new GScheduleProgressMonitor();  
     198        Gatherer.c_man.registerScheduleMonitor(schedule_monitor);  
     199 
    188200        // And the simple panel 
    189201        slower_panel = new JPanel(); 
     
    222234        } 
    223235         
     236        BuildSimpleButtonListener bsbl = new BuildSimpleButtonListener();  
    224237        simple_build_button = new GLIButton(Dictionary.get("CreatePane.Build_Collection"), Dictionary.get("CreatePane.Build_Collection_Tooltip")); 
    225         simple_build_button.addActionListener(bbl); 
    226          
     238        simple_build_button.addActionListener(bsbl); 
     239 
    227240        simple_cancel_button = new GLIButton(Dictionary.get("CreatePane.Cancel_Build"), Dictionary.get("CreatePane.Cancel_Build_Tooltip")); 
    228241        simple_cancel_button.addActionListener(cbl); 
     
    239252         
    240253        bbl = null; 
     254        bsbl = null;  
    241255        cbl = null; 
    242256        //pbl = null; 
     
    350364            sargument_configuration_panel = options_pane.buildImport(null); 
    351365            sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); 
     366            sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);  
    352367        } 
    353368        else { 
     
    469484                sargument_configuration_panel = options_pane.buildImport(null); 
    470485                sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); 
     486                sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel); 
    471487            } 
    472488            else { 
     
    514530        DebugStream.println("In CreatePane::processComplete(" + event.getType() + ")..."); 
    515531        if(event.getStatus() == GShell.OK) { 
    516             if(event.getType() == GShell.BUILD) { 
     532            if(event.getType() == GShell.SCHEDULE) { 
     533                 
     534                processing = false;  
     535                build_button.setEnabled(true); 
     536                cancel_button.setEnabled(false); 
     537                preview_button.setEnabled(true); 
     538                //only enable preview if the collection has been built.  
     539                preview_button.setEnabled(Gatherer.c_man.built()); 
     540                simple_build_button.setEnabled(true); 
     541                simple_cancel_button.setEnabled(false); 
     542                simple_preview_button.setEnabled(Gatherer.c_man.built());  
     543                int status = event.getStatus(); 
     544                document.setSpecialCharacter(OptionsPane.SCHEDULED);  
     545                options_pane.resetFileEntry(); 
     546                build_monitor.reset(); 
     547                import_monitor.reset(); 
     548                if(Configuration.getMode() >= THRESHOLD) { 
     549                    control_pane.add(button_pane, BorderLayout.SOUTH);  
     550                    card_layout.show(main_pane, CONTROL);  
     551                } 
     552            } 
     553            else if(event.getType() == GShell.BUILD) { 
    517554                processing = false; 
    518555                build_button.setEnabled(true); 
    519556                cancel_button.setEnabled(false); 
    520                 //preview_button.setEnabled(true); 
     557                preview_button.setEnabled(true); 
    521558                simple_build_button.setEnabled(true); 
    522559                simple_cancel_button.setEnabled(false); 
     
    539576            build_button.setEnabled(true); 
    540577            // The build may have failed, but a previous index may still be in place 
    541             //preview_button.setEnabled(Gatherer.c_man.built()); 
     578            preview_button.setEnabled(Gatherer.c_man.built()); 
    542579 
    543580            simple_build_button.setEnabled(true); 
    544581            simple_cancel_button.setEnabled(false); 
    545             //simple_preview_button.setEnabled(Gatherer.c_man.built()); 
     582            simple_preview_button.setEnabled(Gatherer.c_man.built()); 
    546583            if(event.getStatus() == GShell.CANCELLED) { 
    547584                document.setSpecialCharacter(OptionsPane.CANCELLED); 
     
    573610        Collection current_collection = Gatherer.c_man.getCollection(); 
    574611        if (current_collection != previous_collection && !Gatherer.c_man.isImporting()) { 
    575             this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options); 
     612            this.options_pane = new OptionsPane(current_collection.import_options, current_collection.build_options, current_collection.schedule_options); 
    576613            if (previous_collection != null) { 
    577614                // clear the log 
     
    589626            sargument_configuration_panel = options_pane.buildImport(null); 
    590627            sargument_configuration_panel = options_pane.buildBuild(sargument_configuration_panel); 
     628            sargument_configuration_panel = options_pane.buildSchedule(sargument_configuration_panel);  
    591629            sargument_configuration_scroll = new JScrollPane(sargument_configuration_panel); 
    592630            sargument_configuration_scroll.setPreferredSize(ARGUMENT_SIZE); 
     
    622660            Collection collection = Gatherer.c_man.getCollection(); 
    623661            String collection_name = collection.getName(); 
    624             if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) { 
    625                 //Only design options have changes, and we want to be smart in the way we handle them. 
    626                 int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired(); 
    627                 if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) { 
    628                     // Just run the buildcol command. 
    629                     DebugStream.println("Just want to run buildcol.pl"); 
    630                     prepareForBuild(); 
    631                     Gatherer.c_man.buildCollection(isIncremental()); 
    632                 } 
    633                 else if (rebuildTypeRequired == CollectionDesignManager.ALL) { 
    634                     // Do both import and buildcol 
    635                     DebugStream.println("Want to do a complete build"); 
     662 
     663            //if button is labelled for Building 
     664            if(event.getActionCommand().equals(Dictionary.get("CreatePane.Build_Collection"))) {  
     665 
     666                if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) { 
     667                    //Only design options have changes, and we want to be smart in the way we handle them. 
     668                    int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired(); 
     669                    if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) { 
     670                        // Just run the buildcol command. 
     671                        DebugStream.println("Just want to run buildcol.pl"); 
     672                        prepareForBuild(); 
     673                        Gatherer.c_man.buildCollection(isIncremental()); 
     674                    } 
     675                    else if (rebuildTypeRequired == CollectionDesignManager.ALL) { 
     676                        // Do both import and buildcol 
     677                        DebugStream.println("Want to do a complete build"); 
     678                        prepareForBuild(); 
     679                        Gatherer.c_man.importCollection(); //This starts the building process. 
     680                    } 
     681                    else { 
     682                        //Nothing at all needs doing. 
     683                        //This is bad HCI. Maybe should disable the build button in this situation? 
     684                        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required")); 
     685                    } 
     686                } 
     687                else { 
     688                    //Do a complete build. 
    636689                    prepareForBuild(); 
    637690                    Gatherer.c_man.importCollection(); //This starts the building process. 
    638                 } 
    639                 else { 
    640                     //Nothing at all needs doing. 
    641                     //This is bad HCI. Maybe should disable the build button in this situation? 
    642                     JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required")); 
    643                 } 
    644             } 
    645             else { 
    646                 //Do a complete build. 
    647                 prepareForBuild(); 
    648                 Gatherer.c_man.importCollection(); //This starts the building process. 
    649             } 
     691                }  
     692 
     693            } else {   //button is labelled for setting up scheduling 
     694 
     695                //this needs to be called to configure buttons... but no building is done 
     696                prepareForBuild();  
     697         
     698                Gatherer.c_man.scheduleBuild(isIncremental());  
     699            } 
     700                 
    650701            //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent) 
    651702        } 
    652  
     703             
    653704        /** 
    654705         * This does some stuff that is needed before a collection can be built. 
     
    689740    } 
    690741     
     742    /** I hope this works. Wendy */  
     743    private class BuildSimpleButtonListener 
     744        implements ActionListener { 
     745        /** 
     746         * This method checks to see what needs to be done for a build, and starts the process off. 
     747         * A complete build proccess is started by {@link CollectionManager.importCollection()}, which then imports and builds the collection. 
     748         * However, this doesn't always happen, as sometimes an incremental build will do :-) 
     749         * @param event An <strong>ActionEvent</strong> who, thanks to the power of object oriented programming, we don't give two hoots about. 
     750         * @see org.greenstone.gatherer.Gatherer 
     751         * @see org.greenstone.gatherer.collection.CollectionManager 
     752         * @see org.greenstone.gatherer.gui.BuildOptions 
     753         * @see org.greenstone.gatherer.shell.GShellProgressMonitor 
     754         */ 
     755        public void actionPerformed(ActionEvent event) { 
     756            Collection collection = Gatherer.c_man.getCollection(); 
     757            String collection_name = collection.getName(); 
     758 
     759                //prepareForBuild();  
     760                if(!collection.getMetadataChanged() && !collection.getFilesChanged() && isIncremental()) { 
     761                    //Only design options have changes, and we want to be smart in the way we handle them. 
     762                    int rebuildTypeRequired = CollectionDesignManager.getRebuildTypeRequired(); 
     763                    if (rebuildTypeRequired == CollectionDesignManager.BUILDCOL) { 
     764                        // Just run the buildcol command. 
     765                        DebugStream.println("Just want to run buildcol.pl"); 
     766                        prepareForBuild(); 
     767                        Gatherer.c_man.buildCollection(isIncremental()); 
     768                    } 
     769                    else if (rebuildTypeRequired == CollectionDesignManager.ALL) { 
     770                        // Do both import and buildcol 
     771                        DebugStream.println("Want to do a complete build"); 
     772                        prepareForBuild(); 
     773                        Gatherer.c_man.importCollection(); //This starts the building process. 
     774                    } 
     775                    else { 
     776                        //Nothing at all needs doing. 
     777                        //This is bad HCI. Maybe should disable the build button in this situation? 
     778                        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CreatePane.Minimal_Build_Not_Required")); 
     779                    } 
     780                } 
     781                else { 
     782                    //Do a complete build. 
     783                    prepareForBuild(); 
     784                    Gatherer.c_man.importCollection(); //This starts the building process. 
     785                } 
     786                 
     787                //only schedule in SYSTEM mode - also done in EXPERT mode, but that is handled elsewhere 
     788                if(Configuration.getMode() ==  Configuration.SYSTEMS_MODE) { 
     789                   if(Gatherer.c_man.getCollection().schedule_options.getValueEnabled("schedule")) { 
     790                    Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"add");  
     791                    Gatherer.c_man.getCollection().schedule_options.setValue("email",false, null);  
     792                    Gatherer.c_man.getCollection().schedule_options.setValue("smtp",false, null); 
     793                    Gatherer.c_man.getCollection().schedule_options.setValue("toaddr",false, null);   
     794                    Gatherer.c_man.getCollection().schedule_options.setValue("fromaddr",false, null);    
     795                    Gatherer.c_man.getCollection().schedule_options.setValue("frequency",false, null);   
     796                    Gatherer.c_man.scheduleBuild(isIncremental());  
     797                } else { 
     798                    //need to turn off existing scheduling 
     799                    Gatherer.c_man.getCollection().schedule_options.setValue("action",true,"delete");  
     800                    Gatherer.c_man.scheduleBuild(isIncremental());  
     801                     
     802                } 
     803                } 
     804            //Re-setting the rebuildTypeRequired is handled by CollectionManager.processComplete(GShellEvent) 
     805        } 
     806 
     807        /** 
     808         * This does some stuff that is needed before a collection can be built. 
     809         * For example, buttons are enabled/disabled, and certain flags are set. 
     810         * This is called from {@link actionPerformed(ActionEvent)} 
     811         */ 
     812        private void prepareForBuild() { 
     813            // First we force the build options to be updated if we haven't already. 
     814            tree.valueChanged(null); 
     815             
     816            // Remember that for lower thresholds the above doesn't work, so try this instead 
     817            if(Configuration.getMode() < THRESHOLD) { 
     818                options_pane.update(sargument_configuration_panel); 
     819            } 
     820             
     821            // Now go about building. 
     822            build_button.setEnabled(false); 
     823            cancel_button.setEnabled(true); 
     824            preview_button.setEnabled(false); 
     825             
     826            simple_build_button.setEnabled(false); 
     827            simple_cancel_button.setEnabled(true); 
     828            simple_preview_button.setEnabled(false); 
     829             
     830            document = options_pane.createNewLogDocument(); 
     831            log_textarea.setDocument(document); 
     832            options_pane.log_textarea.setDocument(document); 
     833            // Change the view. 
     834            processing = true; 
     835            if(Configuration.getMode() >= THRESHOLD) { 
     836                progress_pane.add(button_pane, BorderLayout.SOUTH); 
     837                card_layout.show(main_pane, PROGRESS); 
     838            } 
     839            // Reset the stop flag in all the process monitors, just incase. 
     840            ((GBuildProgressMonitor)build_monitor).reset(); 
     841            import_monitor.setStop(false); 
     842        } 
     843    } 
    691844     
     845 
    692846    /** This class serves as the listener for actions on the cancel button. */ 
    693847    private class CancelButtonListener 
     
    739893        /** The node corresponding to the importing options view. */ 
    740894        private OptionTreeNode importing = null; 
     895        /** The node corresponding to the scheduling options view. */  
     896        private OptionTreeNode scheduling = null;  
    741897        /** The node corresponding to the log view. */ 
    742898        private OptionTreeNode log       = null; 
     
    761917            importing = new OptionTreeNode(Dictionary.get("CreatePane.Import")); 
    762918            importing.setToolTipText(Dictionary.get("CreatePane.Import_Tooltip")); 
     919            scheduling = new OptionTreeNode(Dictionary.get("CreatePane.Schedule")); 
     920            scheduling.setToolTipText(Dictionary.get("CreatePane.Schedule_Tooltip"));  
     921 
    763922            log = new OptionTreeNode(Dictionary.get("CreatePane.Log")); 
    764923            log.setToolTipText(Dictionary.get("CreatePane.Log_Tooltip")); 
     
    769928            model.insertNodeInto(importing, options, 0); 
    770929            model.insertNodeInto(building, options, 1); 
    771             model.insertNodeInto(log, options, 2); 
     930            model.insertNodeInto(scheduling, options, 2);  
     931            model.insertNodeInto(log, options, 3); 
    772932            // Expand the root node 
    773933            expandPath(new TreePath(options)); 
     
    810970                right.add(scroll_pane, BorderLayout.CENTER); 
    811971                //target_pane.add(previous_pane, BorderLayout.CENTER); 
     972            } 
     973            else if(node != null && node.equals(scheduling)) {  
     974                //build_button.setActionCommand(Dictionary.get("CreatePane.Schedule_Build"));  
     975                //build_button.setText(Dictionary.get("CreatePane.Schedule_Build")); 
     976  
     977                previous_pane = options_pane.buildSchedule(null);  
     978                scroll_pane = new JScrollPane(previous_pane); 
     979                right.add(scroll_pane, BorderLayout.CENTER); 
    812980            } 
    813981            else {