1 /*******************************************************************************
2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * See LICENSE for the full license text, also available.
7 *******************************************************************************/
8 package org
.spearce
.egit
.core
;
10 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
11 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
12 import org
.spearce
.jgit
.lib
.ProgressMonitor
;
14 /** Create a new Git to Eclipse progress monitor. */
15 public class EclipseGitProgressTransformer
implements ProgressMonitor
{
16 private final IProgressMonitor root
;
18 private IProgressMonitor task
;
22 private int lastWorked
;
24 private int totalWork
;
27 * Create a new progress monitor.
29 * @param eclipseMonitor
30 * the Eclipse monitor we update.
32 public EclipseGitProgressTransformer(final IProgressMonitor eclipseMonitor
) {
33 root
= eclipseMonitor
;
36 public void start(final int totalTasks
) {
37 root
.beginTask("", totalTasks
* 1000);
40 public void beginTask(final String name
, final int total
) {
45 task
= new SubProgressMonitor(root
, 1000);
46 if (totalWork
== UNKNOWN
)
47 task
.beginTask("", IProgressMonitor
.UNKNOWN
);
49 task
.beginTask("", totalWork
);
53 public void update(final int work
) {
57 final int cmp
= lastWorked
+ work
;
58 if (lastWorked
== UNKNOWN
&& cmp
> 0) {
59 task
.subTask(msg
+ ", " + cmp
);
60 } else if (totalWork
<= 0) {
61 // Do nothing to update the task.
62 } else if (cmp
* 100 / totalWork
!= lastWorked
* 100 / totalWork
) {
63 final StringBuilder m
= new StringBuilder();
66 while (m
.length() < 25)
69 if (totalWork
== UNKNOWN
) {
72 final String twstr
= String
.valueOf(totalWork
);
73 String cmpstr
= String
.valueOf(cmp
);
74 while (cmpstr
.length() < twstr
.length())
75 cmpstr
= " " + cmpstr
;
76 final int pcnt
= (cmp
* 100 / totalWork
);
88 task
.subTask(m
.toString());
94 public void endTask() {
104 public boolean isCancelled() {
106 return task
.isCanceled();
107 return root
.isCanceled();