| package org.eclipse.team.internal.ccvs.core.util; |
| |
| /* |
| * (c) Copyright IBM Corp. 2000, 2002. |
| * All Rights Reserved. |
| */ |
| |
| import org.eclipse.core.runtime.IProgressMonitor; |
| import org.eclipse.core.runtime.SubProgressMonitor; |
| |
| /** |
| * Provides an infinite progress monitor by subdividing by half repeatedly. |
| * |
| * The ticks parameter represents the number of ticks shown in the progress dialog. |
| * However, the number of ticks that can actually be worked is n*ticks/2 where |
| * 2^n = ticks. What this means is that if you provide a ticks of 32 (2^5) than |
| * the maximum number of ticks is 5*32/2 = 80. |
| * |
| */ |
| public class InfiniteSubProgressMonitor extends SubProgressMonitor { |
| |
| int totalWork; |
| int halfWay; |
| int currentIncrement; |
| int nextProgress; |
| int worked; |
| |
| /** |
| * Constructor for InfiniteSubProgressMonitor. |
| * @param monitor |
| * @param ticks |
| */ |
| public InfiniteSubProgressMonitor(IProgressMonitor monitor, int ticks) { |
| this(monitor, ticks, 0); |
| } |
| |
| /** |
| * Constructor for InfiniteSubProgressMonitor. |
| * @param monitor |
| * @param ticks |
| * @param style |
| */ |
| public InfiniteSubProgressMonitor(IProgressMonitor monitor, int ticks, int style) { |
| super(monitor, ticks, style); |
| } |
| |
| public void beginTask(String name, int totalWork) { |
| super.beginTask(name, totalWork); |
| this.totalWork = totalWork; |
| this.halfWay = totalWork / 2; |
| this.currentIncrement = 1; |
| this.nextProgress = currentIncrement; |
| this.worked = 0; |
| } |
| |
| public void worked(int work) { |
| if (worked >= totalWork) return; |
| if (--nextProgress <= 0) { |
| super.worked(1); |
| worked++; |
| if (worked >= halfWay) { |
| // we have passed the current halfway point, so double the |
| // increment and reset the halfway point. |
| currentIncrement *= 2; |
| halfWay += (totalWork - halfWay) / 2; |
| } |
| // reset the progress counter to another full increment |
| nextProgress = currentIncrement; |
| } |
| } |
| |
| } |