source: trunk/gli/src/org/greenstone/gatherer/shell/GBuildProgressMonitor.java@ 11076

Last change on this file since 11076 was 11076, checked in by mdewsnip, 18 years ago

Used GProgressBars instead of JProgressBars, because they're safer when setting indeterminate.

  • Property svn:keywords set to Author Date Id Revision
File size: 23.3 KB
RevLine 
[4293]1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
[5581]37package org.greenstone.gatherer.shell;
38
[4293]39import java.awt.Component;
[6388]40import java.util.ArrayList;
41import org.greenstone.gatherer.Configuration;
[8236]42import org.greenstone.gatherer.DebugStream;
[6388]43import org.greenstone.gatherer.Dictionary;
[4293]44import org.greenstone.gatherer.Gatherer;
[6006]45import org.greenstone.gatherer.cdm.CollectionDesignManager;
[11076]46import org.greenstone.gatherer.gui.GProgressBar;
[6388]47import org.greenstone.gatherer.util.StaticStrings;
[4293]48/** This implementation of <i>GShellProgressMonitor</i> is designed to parse and translate the progress of a buildcol.pl call.
49 * @author John Thompson, Greenstone Digital Library, University of Waikato
[6388]50 * @version 2.3
[4293]51 */
52public class GBuildProgressMonitor
[4364]53 implements GShellProgressMonitor {
[6388]54 /** The minimum value = 0 */
55 static final private int MIN = 0;
56 /** In order to get a smoothish progress bar, set the maximum to a large number = 1000000 */
57 static final private int MAX = 1000000;
58 /** The various states the build progress state machine can be in, starting at the base state. */
59 static final int BASE = -1;
60 static final int BUILD = 0;
61 static final int COMPRESSTEXT = 10;
62 static final int COMPRESSTEXT_COLLECTTEXTSTATS = 11;
63 static final int COMPRESSTEXT_CREATINGCOMPRESS = 12;
64 static final int COMPRESSTEXT_COMPRESSINGTEXT = 13;
65 static final int INDEX = 20;
66 static final int INDEX_CREATINGINDEXDIC = 21;
67 static final int INDEX_INVERTINGTEXT = 22;
68 static final int INDEX_CREATETHEWEIGHTS = 23;
69 static final int INDEX_CREATESTEMMEDDIC = 24;
70 static final int INDEX_CREATINGSTEMINDX = 25;
71 static final int CREATEINFODATA = 30;
72 static final int PHIND = 40;
73 static final int PHIND_EXTRACTINGVOCAB = 41;
74 static final int PHIND_EXTRACTINGPHRASE = 42;
75 static final int PHIND_SORTANDRENUMBER = 43;
76 static final int PHIND_PHRASEDATABASES = 44;
77 static final int PHIND_WORDLEVELINDEXES = 45;
78 static final int PHIND_DOCINFODATABASES = 46;
79 static final int CREATINGAUXILARY = 50;
80 /** Now the language independant sentinel strings. */
[10618]81 static final String BADARGUMENT_ELEMENT = "BadArgument";
82 static final String BADARGUMENTVALUE_ELEMENT = "BadArgumentValue";
83 static final String BADCLASSIFIER_ELEMENT = "BadClassifier";
84 static final String BADPLUGIN_ELEMENT = "BadPlugin";
[6388]85 static final String BUILD_ELEMENT = "Build";
86 static final String COLLECTTEXTSTATS_VALUE = "CollectTextStats";
87 static final String COMPRESSINGTEXT_VALUE = "CompressingText";
88 static final String COMPRESSTEXT_VALUE = "CompressText";
89 static final String CREATINGAUXILARY_VALUE = "CreatingAuxilary";
90 static final String CREATINGCOMPRESS_VALUE = "CreatingCompress";
91 static final String CREATINGINDEXDIC_VALUE = "CreatingIndexDic";
92 static final String CREATINGSTEMINDX_VALUE = "CreatingStemIndx";
93 static final String CREATEINFODATA_VALUE = "CreateInfoData";
94 static final String CREATESTEMMEDDIC_VALUE = "CreateStemmedDic";
95 static final String CREATETHEWEIGHTS_VALUE = "CreateTheWeights";
96 static final String DOCINFODATABASES_VALUE = "DocInfoDatabases";
97 static final String EXTRACTINGPHRASE_VALUE = "ExtractingPhrase";
98 static final String EXTRACTINGVOCAB_VALUE = "ExtractingVocab";
99 static final String FATALERROR_ELEMENT = "FatalError";
100 static final String INDEX_VALUE = "Index";
101 static final String INVERTINGTEXT_VALUE = "InvertingText";
102 static final String NAME_ATTRIBUTE = "name";
103 static final String PHASE_ELEMENT = "Phase";
104 static final String PHIND_VALUE = "Phind";
105 static final String PHRASEDATABASES_VALUE = "PhraseDatabases";
106 static final String SKIPCREATINGCOMP_VALUE = "SkipCreatingComp";
107 static final String SORTANDRENUMBER_VALUE = "SortAndRenumber";
108 static final String SOURCE_ATTRIBUTE = "source";
109 static final String STAGE_ELEMENT = "Stage";
110 static final String WARNING_ELEMENT = "Warning";
111 static final String WORDLEVELINDEXES_VALUE = "WordLevelIndexes";
[10618]112
113 static final private String ARGUMENT_ATTRIBUTE = "a";
114 static final private String CLASSIFIER_ATTRIBUTE = "c";
115 static final private String PLUGIN_ATTRIBUTE = "p";
116
[4364]117 /** Indicates if the GUI has asked the process this object monitors to stop. */
118 private boolean stop = false;
[6388]119 /** The current number of stages we have completed. */
120 private int current_stages = 0;
121 /** The number of stages we are expecting to complete. */
122 private int expected_stages = 0;
[4293]123
[6388]124 private int threshold = Configuration.SYSTEMS_MODE;
125 /** The current state we are in. The state will change depending on the next flag recieved. */
126 private int state = BASE;
[5581]127 /** The progress bar this monitor updates. */
[11076]128 private GProgressBar progress_bar;
[6533]129 /** A progress bar that is shared between this this listener and the Import monitor. */
[11076]130 private GProgressBar shared_progress_bar;
[4293]131
[6388]132 /** Construct a new GBuildProgressMonitor. */
[11076]133 public GBuildProgressMonitor(GProgressBar shared_progress_bar) {
[6533]134 this.shared_progress_bar = shared_progress_bar;
[11076]135 progress_bar = new GProgressBar();
[4364]136 progress_bar.setMaximum(MAX);
137 progress_bar.setMinimum(MIN);
[6533]138 progress_bar.setString(null);
139 progress_bar.setStringPainted(true);
140 setValue(MIN);
[4364]141 }
[4293]142
[4364]143 /** Method to register a new progress bar with this monitor.
[11076]144 * @param progress_bar The new <strong>GProgressBar</strong>.
[5581]145 */
[11076]146 public void addProgressBar(GProgressBar progress_bar) {
[4364]147 this.progress_bar = progress_bar;
148 progress_bar.setMaximum(MAX);
149 progress_bar.setMinimum(MIN);
[6533]150 progress_bar.setStringPainted(false);
151 progress_bar.setString(null);
152 setValue(MIN);
[4364]153 }
[5581]154
[4364]155 /** Determine the script exit value according to the progress monitor. This gets around a problem where several script failures actually result with a successful exit value.
[5581]156 * @return A <i>int</i> with a value of zero if and only if the script was successful.
157 */
[4364]158 public int exitValue() {
159 if(state == BASE) {
160 return 0;
161 }
162 return 1;
163 }
[11076]164 /** Method to retrieve whatever control is being used as the progress indicator. Usually a <strong>GProgressBar</strong> but there may be others implemented later.
[5581]165 * @return A <strong>Component</strong> on which the progress of the process is being displayed.
166 */
[4364]167 public Component getProgress() {
168 return progress_bar;
169 }
[6533]170
[11076]171 public GProgressBar getSharedProgress() {
[6533]172 return shared_progress_bar;
173 }
174
[7924]175 public void messageOnProgressBar(String message)
176 {
177 if ((message!=null) & (message!="")) {
178 progress_bar.setString(message);
179 shared_progress_bar.setString(message);
180 }
181 else {
182 progress_bar.setString(null);
183 shared_progress_bar.setString(null);
184 }
185 }
186
[4364]187 /** Method to determine the state of the stop flag, which may be set by the visual component that created this monitor.
[5581]188 * @return A <strong>boolean</strong> indicating if the process has been asked to stop.
189 */
[6533]190 public synchronized boolean hasSignalledStop() {
[4364]191 return stop;
192 }
193 /** Inform the progress bar that it should programatically increment progress by one step. */
194 public void increment() {
195 // There is no reason this should be called for a build.
196 }
[4293]197
[4364]198 /** This method is used to 'feed in' a line of text captured from the process.
[6388]199 * @param queue a queue which at the moment should contain a single GShellEvent
[5581]200 */
[6388]201 public void process(ArrayList queue) {
202 GShellEvent event = (GShellEvent) queue.get(0);
203 // Remove 'build.pl> ' bit
204 String line = event.getMessage();
205 line = line.substring(line.indexOf(StaticStrings.GREATER_THAN_CHARACTER) + 1);
206 line = line.trim();
207 // We are only really interested in processing pseudo-XML tags
208 if(line.startsWith(StaticStrings.LESS_THAN_CHARACTER) && line.endsWith(StaticStrings.GREATER_THAN_CHARACTER)) {
209 // All events are vetoed
210 event.veto();
211
212 // Create a new element from it
213 GShellElement element = new GShellElement(line);
214 // Now change states within the state machine as appropriate. A state change may subsequently incur a progress update.
215 String name = null;
216 String value = null;
[4364]217 switch(state) {
218 case BASE:
[6388]219 // The only thing we would expect is a build message
220 name = element.getElementName();
221 if(name.equals(BUILD_ELEMENT)) {
222 progress_bar.setIndeterminate(false);
223 state = BUILD;
224 // Produce a lower detail message if required
[8231]225 if(Configuration.getMode() <= threshold && !stop) {
[6388]226 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildBegun1"), event.getStatus()));
227 }
[4364]228 }
[6388]229 else {
230 // Unknown command, go indeterminate
[8236]231 DebugStream.println("Unknown name: " + name);
[6388]232 progress_bar.setIndeterminate(true);
[4364]233 }
[6388]234 name = null;
[4364]235 break;
[6388]236 case BUILD:
[10618]237 // The only thing we would expect is a stage element or a
238 // bad classifier arg name
[6388]239 name = element.getElementName();
[10618]240
[6388]241 if(name.equals(STAGE_ELEMENT)) {
242 progress_bar.setIndeterminate(false);
243 // Now we determine what stage we are moving to
244 value = element.getAttribute(NAME_ATTRIBUTE);
245 if(value.equals(COMPRESSTEXT_VALUE)) {
246 state = COMPRESSTEXT;
[8231]247 if(Configuration.getMode() <= threshold) {
[6388]248 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.CompressText"), event.getStatus()));
249 }
250 }
251 else if(value.equals(INDEX_VALUE)) {
252 state = INDEX;
[8231]253 if(Configuration.getMode() <= threshold) {
[6388]254 String args[] = new String[1];
255 args[0] = element.getAttribute(SOURCE_ATTRIBUTE);
256 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Index", args), event.getStatus()));
257 args = null;
258 }
259 }
260 else if(value.equals(CREATEINFODATA_VALUE)) {
261 state = CREATEINFODATA;
[8231]262 if(Configuration.getMode() <= threshold) {
[6388]263 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.InfoDatabase"), event.getStatus()));
264 }
265 }
266 else if(value.equals(PHIND_VALUE)) {
267 state = PHIND;
[8231]268 if(Configuration.getMode() <= threshold) {
[6388]269 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Phind"), event.getStatus()));
270 }
271 }
272 else if(value.equals(CREATINGAUXILARY_VALUE)) {
273 state = CREATINGAUXILARY;
[8231]274 if(Configuration.getMode() <= threshold) {
[6388]275 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.Auxilary"), event.getStatus()));
276 }
277 }
278 else {
279 // Unknown command, go indeterminate
[8236]280 DebugStream.println("Unknown value: " + value);
[6388]281 progress_bar.setIndeterminate(true);
282 }
283 value = null;
[4364]284 }
[6388]285 // The build end message indicates a successfulish build.
286 else if(name.equals(BUILD_ELEMENT) && element.isClosed()) {
287 progress_bar.setIndeterminate(false);
[6533]288 setValue(MAX);
[6388]289 state = BASE;
[8231]290 if(Configuration.getMode() <= threshold) {
[6388]291 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.BuildComplete1"), event.getStatus()));
292 }
[4364]293 }
[10618]294 // We had a bad argument to a plugin/classifier
295 else if (name.equals(BADARGUMENT_ELEMENT)) {
296 if(Configuration.getMode() <= threshold) {
297 String args[] = new String[1];
298 args[0] = element.getAttribute(ARGUMENT_ATTRIBUTE);
299 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadArgument", args), event.getStatus()));
300 args = null;
301 }
302 }
303 // We had a bad argument value to a plugin/clasifier
304 else if (name.equals(BADARGUMENTVALUE_ELEMENT)) {
305 if(Configuration.getMode() <= threshold) {
306 String args[] = new String[1];
307 args[0] = element.getAttribute(ARGUMENT_ATTRIBUTE);
308 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadArgumentValue", args), event.getStatus()));
309 args = null;
310 }
311 }
312 // And this one tellsa us the plugin
313 else if (name.equals(BADPLUGIN_ELEMENT)) {
314 if(Configuration.getMode() <= threshold) {
315 String args[] = new String[1];
316 args[0] = element.getAttribute(PLUGIN_ATTRIBUTE);
317 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadPluginOptions", args), event.getStatus()));
318 args = null;
319 }
320 }
321 // or the classifier
322 else if (name.equals(BADCLASSIFIER_ELEMENT)) {
323 if(Configuration.getMode() <= threshold) {
324 String args[] = new String[1];
325 args[0] = element.getAttribute(CLASSIFIER_ATTRIBUTE);
326 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.BadClassifierOptions", args), event.getStatus()));
327 args = null;
328 }
329 }
330
[6388]331 else {
332 // Unknown command, go indeterminate
[8236]333 DebugStream.println("Unknown name: " + name);
[6388]334 progress_bar.setIndeterminate(true);
[4364]335 }
[6388]336 name = null;
[4364]337 break;
[6388]338 case COMPRESSTEXT:
339 // We are either dealing with a phase, aa fatal error or an end stage
340 name = element.getElementName();
341 if(name.equals(PHASE_ELEMENT)) {
342 // There are three phases within compressing text (or of four possible ones)
343 value = element.getAttribute(NAME_ATTRIBUTE);
344 if(value.equals(COLLECTTEXTSTATS_VALUE)) {
345 // Nothing to do
346 }
347 else if(value.equals(CREATINGCOMPRESS_VALUE) || value.equals(SKIPCREATINGCOMP_VALUE)) {
348 // One third complete
349 progress_bar.setIndeterminate(false);
[6533]350 setValue((int)(((double)current_stages + 0.3d) * MAX) / expected_stages);
[6388]351 }
352 else if(value.equals(COMPRESSINGTEXT_VALUE)) {
353 // Two thirds complete
354 progress_bar.setIndeterminate(false);
[6533]355 setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
[6388]356 }
357 else {
358 // Unknown command, go indeterminate
[8236]359 DebugStream.println("Unknown value: " + value);
[6388]360 progress_bar.setIndeterminate(true);
361 }
362 value = null;
[4364]363 }
[6388]364 // Note that a fatal error is always followed by an end-stage, but not an end build. Thus the final state will be build (not base) and calls to exitValue() with indicate failure.
365 else if(name.equals(FATALERROR_ELEMENT)) {
366 // On simplier modes produce a meaningful message
367 queue.add(new GShellEvent(event.getSource(), 0, event.getType(), Dictionary.get("GShell.Build.FatalError"), event.getStatus()));
[4364]368 }
[6388]369 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
370 // Increase progress so that stage is complete.
371 current_stages++;
372 progress_bar.setIndeterminate(false);
[6533]373 setValue((current_stages * MAX) / expected_stages);
[6388]374 state = BUILD;
[4364]375 }
[6388]376 else {
377 // Unknown command, go indeterminate
[8236]378 DebugStream.println("Unknown name: " + name);
[6388]379 progress_bar.setIndeterminate(true);
[4364]380 }
[6388]381 name = null;
[4364]382 break;
[6388]383 case INDEX:
384 /** @todo - If on lower modes output a meaningful message. */
385 name = element.getElementName();
386 if(name.equals(PHASE_ELEMENT)) {
387 value = element.getAttribute(NAME_ATTRIBUTE);
388 if(value.equals(CREATINGINDEXDIC_VALUE)) {
389 // Nothing to do
390 }
391 else if(value.equals(INVERTINGTEXT_VALUE)) {
392 // One fifth complete
393 progress_bar.setIndeterminate(false);
[6533]394 setValue((int)(((double)current_stages + 0.2d) * MAX) / expected_stages);
[6388]395 }
396 else if(value.equals(CREATETHEWEIGHTS_VALUE)) {
397 // Two fifths complete
398 progress_bar.setIndeterminate(false);
[6533]399 setValue((int)(((double)current_stages + 0.4d) * MAX) / expected_stages);
[6388]400 }
401 else if(value.equals(CREATESTEMMEDDIC_VALUE)) {
402 // Three fifths complete
403 progress_bar.setIndeterminate(false);
[6533]404 setValue((int)(((double)current_stages + 0.6d) * MAX) / expected_stages);
[6388]405 }
406 else if(value.equals(CREATINGSTEMINDX_VALUE)) {
407 // Four fifths complete
408 progress_bar.setIndeterminate(false);
[6533]409 setValue((int)(((double)current_stages + 0.8d) * MAX) / expected_stages);
[6388]410 }
411 else {
412 // Unknown command, go indeterminate
[8236]413 DebugStream.println("Unknown value: " + value);
[6388]414 progress_bar.setIndeterminate(true);
415 }
416 value = null;
[4364]417 }
[6388]418 else if(name.equals(WARNING_ELEMENT)) {
419 /** @todo - If on lower modes output a meaningful message. */
[4364]420 }
[6388]421 // Note that a fatal error is always followed by an end-stage, but not an end build. Thus the final state will be build (not base) and calls to exitValue() with indicate failure.
422 else if(name.equals(FATALERROR_ELEMENT)) {
423 // On lower modes output a meaningful message.
424
[4364]425 }
[6388]426 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
427 // Increase progress so that stage is complete.
428 current_stages++;
429 progress_bar.setIndeterminate(false);
[6533]430 setValue((current_stages * MAX) / expected_stages);
[6388]431 state = BUILD;
[4364]432 }
[6388]433 else {
434 // Unknown command, go indeterminate
[8236]435 DebugStream.println("Unknown name: " + name);
[6388]436 progress_bar.setIndeterminate(true);
[4364]437 }
[6388]438 name = null;
[4364]439 break;
[6388]440 case PHIND:
441 name = element.getElementName();
442 if(name.equals(PHASE_ELEMENT)) {
443 value = element.getAttribute(NAME_ATTRIBUTE);
444 if(value.equals(EXTRACTINGVOCAB_VALUE)) {
445 // Nothing to do
446 }
447 else if(value.equals(EXTRACTINGPHRASE_VALUE)) {
448 // One sixth complete
449 progress_bar.setIndeterminate(false);
[6533]450 setValue((int)(((double)current_stages + 0.16d) * MAX) / expected_stages);
[6388]451 }
452 else if(value.equals(SORTANDRENUMBER_VALUE)) {
453 // Two sixths complete
454 progress_bar.setIndeterminate(false);
[6533]455 setValue((int)(((double)current_stages + 0.33d) * MAX) / expected_stages);
[6388]456 }
457 else if(value.equals(PHRASEDATABASES_VALUE)) {
458 // Three sixths complete
459 progress_bar.setIndeterminate(false);
[6533]460 setValue((int)(((double)current_stages + 0.5d) * MAX) / expected_stages);
[6388]461 }
462 else if(value.equals(WORDLEVELINDEXES_VALUE)) {
463 // Four sixths complete
464 progress_bar.setIndeterminate(false);
[6533]465 setValue((int)(((double)current_stages + 0.66d) * MAX) / expected_stages);
[6388]466 }
467 else if(value.equals(DOCINFODATABASES_VALUE)) {
468 // Five sixths complete
469 progress_bar.setIndeterminate(false);
[6533]470 setValue((int)(((double)current_stages + 0.83d) * MAX) / expected_stages);
[6388]471 }
472 else {
473 // Unknown command, go indeterminate
[8236]474 DebugStream.println("Unknown value: " + value);
[6388]475 progress_bar.setIndeterminate(true);
476 }
477 value = null;
[4364]478 }
[6388]479 else if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
480 // Increase progress so that stage is complete.
481 current_stages++;
482 progress_bar.setIndeterminate(false);
[6533]483 setValue((current_stages * MAX) / expected_stages);
[6388]484 state = BUILD;
[4364]485 }
[6388]486 else {
487 // Unknown command, go indeterminate
[8236]488 DebugStream.println("Unknown name: " + name);
[6388]489 progress_bar.setIndeterminate(true);
[4364]490 }
[6388]491 name = null;
[4364]492 break;
[6388]493 case CREATEINFODATA:
494 case CREATINGAUXILARY:
495 name = element.getElementName();
496 if(name.equals(STAGE_ELEMENT) && element.isClosed()) {
497 // Another stage complete
498 current_stages++;
499 progress_bar.setIndeterminate(false);
[6533]500 setValue((current_stages * MAX) / expected_stages);
[6388]501 state = BUILD;
[4364]502 }
[6388]503 else {
504 // Unknown command, go indeterminate
[8236]505 DebugStream.println("Unknown name: " + name);
[6388]506 progress_bar.setIndeterminate(true);
[4364]507 }
[6388]508 name = null;
[4364]509 break;
[6388]510 default:
511 // Unknown command, go indeterminate
[8236]512 DebugStream.println("Unknown name: " + name);
[6388]513 progress_bar.setIndeterminate(true);
[4364]514 }
515 }
[6388]516 // If we are dealing with lower detail modes then veto any other messages. We do this here as the progress monitors are garuenteed to recieve this message before anything else
[8231]517 else if(Configuration.getMode() <= threshold) {
[6388]518 event.veto();
[4364]519 }
520 }
[4293]521
[4364]522 public void reset() {
[6388]523 current_stages = 0;
524 expected_stages = 0;
525 progress_bar.setIndeterminate(false);
[6533]526 progress_bar.setString(null);
527 setValue(MIN);
[4364]528 state = BASE;
[6388]529 progress_bar.updateUI();
[4364]530 }
[4293]531
[5034]532 public void saving() {
533 }
534
[11076]535 public void setSharedProgressBar(GProgressBar shared_progress_bar) {
[6533]536 this.shared_progress_bar = shared_progress_bar;
537 }
538
[4364]539 /** Since the creator of this process monitor is actually in the GUI, this class provides the simpliest way to send a cancel process message between the two.
[5581]540 * @param state The desired state of the stop flag as a <strong>boolean</strong>.
541 */
[6533]542 public synchronized void setStop(boolean state) {
543 this.stop = state;
[4364]544 progress_bar.setIndeterminate(false);
545 }
546 /** This method resets this monitor to the start, reseting the process parsing and progress bar.
[5581]547 * TODO Everthing.
548 */
[4364]549 public void start() {
[6533]550 stop = false;
551 setValue(MIN);
[6388]552 expected_stages = 3; // Always compress text, create info database and auxiliary creation
553 // Retrieve cdm.
[6006]554 CollectionDesignManager cdm = Gatherer.c_man.getCollection().cdm;
[6388]555 // If we are using MGPP the number of indexes is always 1
[10530]556 if(cdm.searchtype_manager.isMGPP()) {
[6388]557 expected_stages = expected_stages + 1;
[10530]558 } else if (cdm.searchtype_manager.isLucene()) {
559 // lucene no of indexes == number of levels
560 int num_levels = cdm.index_manager.getNumLevels();
561 if (num_levels == 0) num_levels = 1;
562 expected_stages = expected_stages + num_levels;
[6006]563 }
[6388]564 else {
565 int num_indexes = cdm.index_manager.getSize();
566 int num_partitions = cdm.subcollectionindex_manager.getSize();
567 if(num_partitions > 0) {
568 num_indexes = num_indexes * num_partitions;
569 }
570 int num_languages = cdm.language_manager.getSize();
571 if(num_languages > 0) {
572 num_indexes = num_indexes * num_languages;
573 }
574 expected_stages = expected_stages + num_indexes;
[6006]575 }
[6388]576 // And if we have a phind classifier, we have one further index
577 if(cdm.classifier_manager.isPhindClassifierAssigned()) {
578 expected_stages = expected_stages + 1;
579 }
[6006]580 cdm = null;
[4364]581 }
582 /** This method indicates the process is complete.
[5581]583 * TODO Everthing.
584 */
[4364]585 public void stop() {
586 progress_bar.setIndeterminate(false);
[6533]587 setValue(MAX);
[4364]588 }
[6533]589
590 private void setValue(int value) {
591 progress_bar.setValue(value);
592 // Incrementing the shared progress bar is a little more problematic as we may very well be trying to set it to MIN but instead set it to halfway if we're not careful.
593 if(value > MIN) {
594 shared_progress_bar.setValue(MAX + value);
595 }
596 }
[4293]597}
[6388]598
Note: See TracBrowser for help on using the repository browser.