1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpeclipse.wiki.preferences;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.SubProgressMonitor;
18 * Provides an infinite progress monitor by subdividing by half repeatedly.
20 * The ticks parameter represents the number of ticks shown in the progress dialog
21 * (or propogated up to a parent IProgressMonitor). The totalWork parameter provided
22 * in actually a hint used to determine how work is translated into ticks.
23 * The number of totalWork that can actually be worked is n*totalWork/2 where
24 * 2^n = totalWork. What this means is that if you provide a totalWork of 32 (2^5) than
25 * the maximum number of ticks is 5*32/2 = 80.
28 public class InfiniteSubProgressMonitor extends SubProgressMonitor {
37 * Constructor for InfiniteSubProgressMonitor.
41 public InfiniteSubProgressMonitor(IProgressMonitor monitor, int ticks) {
42 this(monitor, ticks, 0);
46 * Constructor for InfiniteSubProgressMonitor.
51 public InfiniteSubProgressMonitor(IProgressMonitor monitor, int ticks, int style) {
52 super(monitor, ticks, style);
55 public void beginTask(String name, int totalWork) {
56 super.beginTask(name, totalWork);
57 this.totalWork = totalWork;
58 this.halfWay = totalWork / 2;
59 this.currentIncrement = 1;
60 this.nextProgress = currentIncrement;
64 public void worked(int work) {
65 if (worked >= totalWork) return;
66 if (--nextProgress <= 0) {
69 if (worked >= halfWay) {
70 // we have passed the current halfway point, so double the
71 // increment and reset the halfway point.
72 currentIncrement *= 2;
73 halfWay += (totalWork - halfWay) / 2;
75 // reset the progress counter to another full increment
76 nextProgress = currentIncrement;
81 * Don't allow clearing of the subtask. This will stop the flickering
82 * of the subtask in the progress dialogs.
84 * @see IProgressMonitor#subTask(String)
86 public void subTask(String name) {
87 if(name != null && ! name.equals("")) { //$NON-NLS-1$