Changeset 6325


Ignore:
Timestamp:
2003-12-19T14:54:25+13:00 (20 years ago)
Author:
jmt12
Message:

Rewrote GImportProgressMonitor to use the new GLI argument based messages from the import script - which are separate from multilingual issues. This required several changes to GShell, GShellEvents, and everything that makes use of them

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r6204 r6325  
    309309        count++;
    310310    }
    311     for(int i = 0; i < node.getChildCount(); i++) {
     311    for(int i = 0; !file.getName().equals("CVS") && i < node.getChildCount(); i++) {
    312312        count = count + getCount(node.getChildAt(i), count_folders, count_files);
    313313    }
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r6317 r6325  
    745745        String args[];
    746746        if(Utility.isWindows()) {
    747         args = new String[6];
     747        args = new String[7];
    748748        args[0] = Gatherer.config.perl_path;
    749749        args[1] = "-S";
    750750        args[2] = Gatherer.config.getScriptPath() + "import.pl";
    751         args[3] = "-importdir";
    752         args[4] = collection_import;
    753         args[5] = collection.getName();
     751        args[3] = "-gli";
     752        args[4] = "-importdir";
     753        args[5] = collection_import;
     754        args[6] = collection.getName();
    754755        }
    755756        else {
    756         args = new String[4];
     757        args = new String[5];
    757758        args[0] = Gatherer.config.getScriptPath() + "import.pl";
    758         args[1] = "-importdir";
    759         args[2] = collection_import;
    760         args[3] = collection.getName();
     759        args[1] = "-gli";
     760        args[2] = "-importdir";
     761        args[3] = collection_import;
     762        args[4] = collection.getName();
    761763        }
    762764        collection_import = null;
     
    10911093        }
    10921094        WarningDialog collection_built_warning_dialog = new WarningDialog("warning.CollectionBuilt", false);
     1095        collection_built_warning_dialog.setMessageOnly(true); // Not a warning
    10931096        collection_built_warning_dialog.display();
    10941097        collection_built_warning_dialog.dispose();
  • trunk/gli/src/org/greenstone/gatherer/msm/GreenstoneArchiveParser.java

    r6200 r6325  
    8888            args[0] = document_directories[i].getName();
    8989            args[1] = String.valueOf(count);
    90             shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Dictionary.get("GShell.Extracted", args), GShell.OK);
     90            shell.fireMessage(GShell.IMPORT, shell.typeAsString(GShell.IMPORT) + "> " + Dictionary.get("GShell.Extracted", args), GShell.OK, null);
    9191            args = null;
    9292            progress.increment();
  • trunk/gli/src/org/greenstone/gatherer/shell/GBasicProgressMonitor.java

    r5581 r6325  
    4949import java.awt.Component;
    5050import javax.swing.JProgressBar;
     51import org.greenstone.gatherer.shell.GShellEvent;
    5152import org.greenstone.gatherer.shell.GShellProgressMonitor;
    5253
     
    9192    }
    9293    /** The parse method is how more complex progress bars figure out how far they have progressed. However we don't.
    93      * @param line A String representing the latest line of output from
    94      * the external process we are monitoring.
     94     * @param event a GShellEvent containing information from the GShell
    9595     */
    96     public void parse(String line) {
     96    public void process(GShellEvent event) {
    9797    }
    9898
  • trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java

    r6006 r6325  
    4242import org.greenstone.gatherer.cdm.CollectionDesignManager;
    4343import org.greenstone.gatherer.shell.GImportProgressMonitor;
     44import org.greenstone.gatherer.shell.GShellEvent;
    4445import org.greenstone.gatherer.shell.GShellProgressMonitor;
    4546/** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a buildcol.pl call.
     
    150151
    151152    /** This method is used to 'feed in' a line of text captured from the process.
    152      * @param line A <strong>String</strong> of text captured from either standard out or standard error.
    153      */
    154     public void parse(String raw_line) {
    155     String line = raw_line.toLowerCase();
     153     * @param event a GShellEvent containing information from the GShell
     154     */
     155    public void process(GShellEvent event) {
     156    String line = event.getMessage().toLowerCase();
    156157    // We first check if we can parse, which depends on num_docs > 0 and num_indexes > 0.
    157158    if(num_docs > 0 && num_indexes > 0) {
  • trunk/gli/src/org/greenstone/gatherer/shell/GImportProgressMonitor.java

    r5593 r6325  
    4343import org.greenstone.gatherer.Gatherer;
    4444import org.greenstone.gatherer.shell.GShellProgressMonitor;
     45import org.greenstone.gatherer.util.StaticStrings;
    4546
    4647/** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a import.pl call.
     
    5051public class GImportProgressMonitor
    5152    implements GShellProgressMonitor {
     53    /** Indicates if the progress bar is currently showing a string. */
     54    private boolean showing_string = false;
    5255    /** Indicates if the GUI has asked the process this object monitors to stop. */
    5356    private boolean stop = false;
    54     private int file_num = 0;
     57    /** A count of the extracted files processed so far. */
     58    private int extracted_file_count;
     59    /** The number of documents processed (or rejected) so far. */
     60    private int file_count;
     61    /** The next value to be set for the progress bar - I use this rather than a compounding progress measure to try to limit rounding inaccuracies (nothing looks worse than the progress bar having to jump the last 10-15%) */
     62    private int next_progress_value;
    5563    /** The number of files expected to be scanned by this import process. */
    56     private int num_files = 0;
     64    private int num_expected_docs;
    5765    /** This holds the number of documents actually processed by the import command, as garnered from the final block of text output. */
    58     private int num_docs = 0;
     66    private int num_docs;
    5967    /** The progress bar this monitor updates. */
    6068    private JProgressBar progress_bar;
    61     /** The maximum value for this progress bar. */
    62     static final private int MAX = 1000000;
     69    /** */
     70    static final private String C = "c";
     71    /** */
     72    static final private String N = "n";
     73    /** */
     74    static final private String P = "p";
     75    /** The fixed portion of the progress bar used for the calculating of file size and other pre-import functions. */
     76    static final private int CALCULATION = 50000;
     77    /** The fixed portion of the progress bar used for extracted metadata. */
     78    static final private int EXTRACTED = 200000;
    6379    /** The minimum value for this progress bar. */
    6480    static final private int MIN = 0;
    65     /** A String fragment which is used to determine if the current output process line is referring to the number of documents actually processed by the import script. */
    66     static final private String NUM_DOCS_PROCESSED = "processed and included in the collection";
    67     /** The Sentinel value is the String fragment an output process line must start with to be considered a milestone. In this case we are counting directories, so the fragment refers to a directory scan. */
    68     static final private String SENTINEL = "recplug - ";
     81    /** The fixed portion of the progress bar used for processed documents. */
     82    static final private int PROCESSED = 750000;
     83    /** The element name of a file detected message. */
     84    static final private String FILE = "File";
     85    /** The element name of a file processing message. */
     86    static final private String FILE_PROCESSING = "Processing";
     87    /** The element name of an import complete message. */
     88    static final private String IMPORT_COMPLETE = "ImportComplete";
    6989
    7090    public GImportProgressMonitor() {
    7191    progress_bar = new JProgressBar();
    7292    progress_bar.setIndeterminate(false);
    73     progress_bar.setMaximum(MAX);
     93    progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED);
    7494    progress_bar.setMinimum(MIN);
    7595    progress_bar.setStringPainted(true);
    7696    progress_bar.setValue(MIN);
     97    next_progress_value = CALCULATION;
    7798    }
    7899
     
    82103    public void addProgressBar(JProgressBar progress_bar) {
    83104    this.progress_bar = progress_bar;
    84     progress_bar.setMaximum(MAX);
     105    progress_bar.setMaximum(CALCULATION + PROCESSED + EXTRACTED);
    85106    progress_bar.setMinimum(MIN);
    86107    progress_bar.setValue(MIN);
     108    next_progress_value = CALCULATION;
    87109    }
    88110
     
    120142    /** Inform the progress bar that it should programatically increment progress by one step. This is only called during the metadata archive extraction so each step should be (1000000 / 5) / num_docs. */
    121143    public void increment() {
    122     if(num_docs > 0) {
    123         progress_bar.setValue(progress_bar.getValue() + ((MAX / 5) / num_docs));
     144    extracted_file_count++;
     145    // The current progress is calculated to be:
     146    // The fixed calculation value plus the fixed processed value plus some portion of the fixed extracted value. This portion is the extracted_file_count over the total number of documents available. Note that this breaks badly for bibliographical files (for now).
     147    progress_bar.setValue(CALCULATION + PROCESSED + ((EXTRACTED * extracted_file_count) / num_docs));
     148    }
     149
     150    /** This method is used to 'feed in' a line of text captured from the process.
     151     * @param event the GShellEvent containing a message or other important shell information
     152     */
     153    public void process(GShellEvent event) {
     154    // We're into parsing output, so we don't need the 'calculating file size' etc string.
     155    if(showing_string) {
     156        progress_bar.setString("");
     157        showing_string = false;
    124158    }
    125     // else {
    126     // progress_bar.setIndeterminate(true);
    127     // }
    128     }
    129 
    130     /** This method is used to 'feed in' a line of text captured from the process.
    131      * @param line A <strong>String</strong> of text captured from either standard out or standard error.
    132      * TODO Everthing.
    133      */
    134     public void parse(String line_raw) {
    135     progress_bar.setString("");
    136     String line = line_raw.toLowerCase();
    137     if (line.indexOf(SENTINEL) == 0) {
    138         file_num = file_num + 1;
    139         ///ystem.err.println("Done " + file_num + " of " + num_files + "...");
    140         if (num_files > 0) {
    141         int base_val = MAX / 10;
    142         progress_bar.setValue(((((7 * MAX) / 10) * file_num) / num_files) + base_val);
     159    // Remove 'import.pl> ' bit
     160    String line = event.getMessage();
     161    line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1);
     162    line = line.trim();
     163    ///ystem.err.println("message = " + line);
     164    if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) {
     165        line = line.substring(1, line.length() - 1);
     166        // We may be reading a file. Remember we have to offset process as we recieve this message 'before' a document is processed. Hence the use of 'next_progress_value'
     167        if(line.startsWith(FILE)) {
     168        file_count++;
     169        ///ystem.err.println("File #" + file_count);
     170        // Set the next progress
     171        progress_bar.setValue(next_progress_value);
     172        // Now we calculate the next progress value
     173        next_progress_value = CALCULATION + ((PROCESSED * file_count) / num_expected_docs);
    143174        }
    144     }
    145     else if (line.indexOf(NUM_DOCS_PROCESSED) != -1) {
    146         num_docs = -1;
    147         StringTokenizer tokenizer = new StringTokenizer(line);
    148         while(num_docs == -1 && tokenizer.hasMoreTokens()) {
    149         String pos_num_docs_str = tokenizer.nextToken();
    150         try {
    151             num_docs = Integer.parseInt(pos_num_docs_str);
     175        // Or we're being told what plugin is actually processing the file
     176        else if(line.startsWith(FILE_PROCESSING)) {
     177        // If we are at lower mode settings fire a new 'dumbed down' event
     178        /** @todo */
     179        }
     180        // Or the import complete element
     181        else if(line.startsWith(IMPORT_COMPLETE)) {
     182        // Set the next progress
     183        progress_bar.setValue(next_progress_value);
     184        // Determine the number of documents processed by using the 'p' attribute
     185        StringTokenizer tokenizer = new StringTokenizer(line);
     186        boolean found = false;
     187        String token = tokenizer.nextToken(); // Drop the element name
     188        while(tokenizer.hasMoreTokens() && !found) {
     189            token = tokenizer.nextToken();
     190            if(token.startsWith(P)) {
     191            found = true;
     192            try {
     193                String num_docs_string = token.substring(3, token.length() - 1);
     194                num_docs = Integer.parseInt(num_docs_string);
     195            }
     196            catch(Exception exception) {
     197                Gatherer.println("Exception in GImportProgressMonitor.process() - Expected");
     198                Gatherer.printStackTrace(exception);
     199            }
     200            }
    152201        }
    153         catch (Exception error) {
    154         }
     202        tokenizer = null;
     203        // If we are at lower mode settings fire a new 'dumbed down' event
     204        /** @todo */
    155205        }
    156         ///ystem.err.println("Parsed num_docs to be " + num_docs);
     206
     207
     208        // We also veto this event to prevent other classes handling it (we ensure progress monitors are called first).
     209        event.veto();
    157210    }
    158211    }
     
    160213    public void saving() {
    161214    progress_bar.setString(Dictionary.get("SaveProgressDialog.Title"));
    162     progress_bar.setValue(MAX / (10 * 2));
     215    showing_string = true;
    163216    }
    164217
     
    171224
    172225    /** This method resets this monitor to the start, reseting the process parsing and progress bar.
    173      * TODO Everthing.
    174226     */
    175227    public void start() {
    176228    progress_bar.setString(Dictionary.get("FileActions.Calculating_Size"));
    177     progress_bar.setValue(MAX / 10);
    178     num_files = Gatherer.c_man.getCollection().getDocumentCount();
    179     ///ystem.err.println("Number of files: " + num_files);
    180     file_num = 0;
     229    showing_string = true;
     230    extracted_file_count = 0;
     231    file_count = 0;
     232    next_progress_value = -1;
     233    num_docs = -1;
     234    num_expected_docs = Gatherer.c_man.getCollection().getCount();
    181235    }
    182236
    183237    /** This method indicates the process is complete.
    184      * TODO Everthing.
    185238     */
    186239    public void stop() {
    187     progress_bar.setValue(MAX);
     240    progress_bar.setValue(CALCULATION + PROCESSED + EXTRACTED);
    188241    }
    189242}
  • trunk/gli/src/org/greenstone/gatherer/shell/GShell.java

    r6182 r6325  
    145145    /** Any threaded class must include this method to allow the thread body to be run. */
    146146    public void run() {
    147     if(progress != null) {
    148         progress.start();
    149     }
    150147    // Determine if the user has asked for an outfile.
    151148    String out_name = null;
     
    175172        }
    176173        ///ystem.err.println("Command: " + command);
    177         fireMessage(type, Dictionary.get("GShell.Command") + ": " + command, status);
     174        fireMessage(type, Dictionary.get("GShell.Command") + ": " + command, status, null);
    178175       
    179176        Runtime rt = Runtime.getRuntime();
     
    196193                String eline = eline_buffer.toString();
    197194                ///atherer.println("* " + eline + " *");
    198                 if(progress != null) {
    199                 progress.parse(eline);
    200                 }
    201                 if(bos != null) {
    202                 try {
    203                     bos.write(eline.getBytes(), 0, eline.length());
    204                 }
    205                 catch(Exception error) {
    206                     Gatherer.printStackTrace(error);
    207                 }
    208                 }
    209                 fireMessage(type, typeAsString(type) + "> " + eline, status);
     195                fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
    210196                eline = null;
    211197                eline_buffer = new StringBuffer();
     
    224210                String stdline = stdline_buffer.toString();
    225211                ///atherer.println("+ " + stdline + " +");
    226                 fireMessage(type, typeAsString(type) + "> " + stdline, status);
     212                fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
    227213                stdline = null;
    228214                stdline_buffer = new StringBuffer();
     
    250236            String eline = eline_buffer.toString();
    251237            ///atherer.println("* " + eline + " *");
    252             if(progress != null) {
    253                 progress.parse(eline);
    254             }
    255             if(bos != null) {
    256                 try {
    257                 bos.write(eline.getBytes(), 0, eline.length());
    258                 }
    259                 catch(Exception error) {
    260                 Gatherer.printStackTrace(error);
    261                 }
    262             }
    263             fireMessage(type, typeAsString(type) + "> " + eline, status);
     238            fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
    264239            eline = null;
    265240            eline_buffer = new StringBuffer();
     
    277252            String stdline = stdline_buffer.toString();
    278253            ///atherer.println("+ " + stdline + " +");
    279             fireMessage(type, typeAsString(type) + "> " + stdline, status);
     254            fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
    280255            stdline = null;
    281256            stdline_buffer = new StringBuffer();
     
    291266        String eline = eline_buffer.toString();
    292267        ///atherer.println("Last bit of eline: " + eline);
    293         if(progress != null) {
    294             progress.parse(eline);
    295         }
    296         if(bos != null) {
    297             try {
    298             bos.write(eline.getBytes(), 0, eline.length());
    299             }
    300             catch(Exception error) {
    301             Gatherer.printStackTrace(error);
    302             }
    303         }
    304         fireMessage(type, typeAsString(type) + "> " + eline, status);
     268        fireMessage(type, typeAsString(type) + "> " + eline, status, bos);
    305269        eline = null;
    306270        }
     
    309273        String stdline = stdline_buffer.toString();
    310274        ///atherer.println("Last bit of stdline: " + stdline);
    311         fireMessage(type, typeAsString(type) + "> " + stdline, status);
     275        fireMessage(type, typeAsString(type) + "> " + stdline, status, null);
    312276        stdline = null;
    313277        }
     
    319283        if(prcs.exitValue() == 0) {
    320284            status = OK;
    321             fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status);
     285            fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Success"), status, null);
    322286        }
    323287        else {
    324288            status = ERROR;
    325             fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Failure"), status);
     289            fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Failure"), status, null);
    326290        }
    327291        }
     
    336300    }
    337301    // Exception
    338     catch (Exception error) {
    339         Gatherer.printStackTrace(error);
     302    catch (Exception exception) {
     303        Gatherer.println("Exception in GShell.run() - unexpected");
     304        Gatherer.printStackTrace(exception);
    340305        status = ERROR;
    341306    }
    342307    // If no error occured, and this was an import process we now extract any new metadata from the archive directory.
    343308    if(status == OK && type == IMPORT) {
    344         fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Start"), status);
     309        fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Start"), status, null);
    345310        new GreenstoneArchiveParser(progress, this);
    346         fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status);
    347     }
    348     // Tidy up.
    349     if(progress != null) {
    350         progress.stop();
     311        fireMessage(type, typeAsString(type) + "> " + Dictionary.get("GShell.Parsing_Metadata_Complete"), status, null);
    351312    }
    352313    // We're done.
     
    368329     * @param status An <strong>int</strong> specifying the current status of the process.
    369330     */
    370     public void fireMessage(int type, String message, int status) {
     331    public void fireMessage(int type, String message, int status, BufferedOutputStream bos) {
    371332    GShellEvent event = new GShellEvent(this, 0, type, message, status);
    372     Object[] concerned = listeners.getListenerList();
    373     for(int i = 0; i < concerned.length ; i++) {
    374         if(concerned[i] == GShellListener.class) {
    375         ((GShellListener)concerned[i+1]).message(event);
    376         }
    377     }
     333    // If there is a progress monitor attached, pass the event to it first
     334    if(progress != null) {
     335        progress.process(event);
     336    }
     337    // If the event hasn't been vetoed, pass it on to other listeners
     338    if(!event.isVetoed()) {
     339        Object[] concerned = listeners.getListenerList();
     340        for(int i = 0; i < concerned.length ; i++) {
     341        if(concerned[i] == GShellListener.class) {
     342            ((GShellListener)concerned[i+1]).message(event);
     343        }
     344        }
     345        concerned = null;
     346        // And if we have a buffered output stream from error messages, send the message there
     347        if(bos != null) {
     348        try {
     349            bos.write(message.getBytes(), 0, message.length());
     350        }
     351        catch(Exception exception) {
     352            Gatherer.println("Exception in GShell.fireMessage() - unexpected");
     353            Gatherer.printStackTrace(exception);
     354        }
     355        }
     356    }
     357    event = null;
    378358    }
    379359
     
    383363     */
    384364    protected void fireProcessBegun(int type, int status) {
     365    // Start the progres monitor if available
     366    if(progress != null) {
     367        progress.start();
     368    }
     369    // Fire an event
    385370    GShellEvent event = new GShellEvent(this, 0, type, "", status);
    386371    Object[] concerned = listeners.getListenerList();
     
    396381     */
    397382    protected void fireProcessComplete(int type, int status) {
     383    // Tidy up by stopping the progress bar.
     384    if(progress != null) {
     385        progress.stop();
     386    }
     387    // And firing off an event
    398388    GShellEvent event = new GShellEvent(this, 0, type, "", status);
    399389    Object[] concerned = listeners.getListenerList();
  • trunk/gli/src/org/greenstone/gatherer/shell/GShellEvent.java

    r5581 r6325  
    5151public class GShellEvent
    5252    extends AWTEvent {
     53    /** Allows some part of the program to prevent this message being processed by other parts. */
     54    private boolean vetoed = false;
    5355    /** The status of the process at the completion of event. */
    5456    private int status = -1;
     
    9395    }
    9496
     97    /** Determine if this event has been vetoed by some other part of the GLI
     98     * @return true if the event has, and thus shouldn't be further processed, false otherwise.
     99     */
     100    public boolean isVetoed() {
     101    return vetoed;
     102    }
     103
    95104    public String toString() {
    96105    return "org.greenstone.gatherer.shell.GShellEvent[" + message + "," + status + "," + type + "]";
    97106    }
     107
     108    /** Prevent this event being processed by other parts of the GLI.
     109     */
     110    public void veto() {
     111    vetoed = true;
     112    }
    98113}
  • trunk/gli/src/org/greenstone/gatherer/shell/GShellProgressMonitor.java

    r5581 r6325  
    5050import java.awt.Component;
    5151import javax.swing.JProgressBar;
     52import org.greenstone.gatherer.shell.GShellEvent;
    5253
    5354/** When implemented, this interface allows another class to monitor the progress of a <strong>GShell</strong> process. Specifically implementing classes should be designed to take the textual output from the process and then translate that message into some quanitive measure of progress which can then be shown on the progress bar.
     
    7879
    7980    /** This method is used to 'feed in' a line of text captured from the process.
    80      * @param line A <strong>String</strong> of text captured from either standard out or standard error.
     81     * @param event a GShellEvent containing information from the GShell
    8182     */
    82     public void parse(String line);
     83    public void process(GShellEvent event);
    8384
    8485    public void saving();
Note: See TracChangeset for help on using the changeset viewer.