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 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9 package org
.eclipse
.egit
.core
;
11 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
12 import org
.eclipse
.core
.runtime
.SubProgressMonitor
;
13 import org
.eclipse
.jgit
.lib
.ProgressMonitor
;
15 /** Create a new Git to Eclipse progress monitor. */
16 public class EclipseGitProgressTransformer
implements ProgressMonitor
{
17 private final IProgressMonitor root
;
19 private IProgressMonitor task
;
23 private int lastWorked
;
25 private int totalWork
;
28 * Create a new progress monitor.
30 * @param eclipseMonitor
31 * the Eclipse monitor we update.
33 public EclipseGitProgressTransformer(final IProgressMonitor eclipseMonitor
) {
34 root
= eclipseMonitor
;
37 public void start(final int totalTasks
) {
38 root
.beginTask("", totalTasks
* 1000);
41 public void beginTask(final String name
, final int total
) {
46 task
= new SubProgressMonitor(root
, 1000);
47 if (totalWork
== UNKNOWN
)
48 task
.beginTask("", IProgressMonitor
.UNKNOWN
);
50 task
.beginTask("", totalWork
);
54 public void update(final int work
) {
58 final int cmp
= lastWorked
+ work
;
59 if (lastWorked
== UNKNOWN
&& cmp
> 0) {
60 task
.subTask(msg
+ ", " + cmp
);
61 } else if (totalWork
<= 0) {
62 // Do nothing to update the task.
63 } else if (cmp
* 100 / totalWork
!= lastWorked
* 100 / totalWork
) {
64 final StringBuilder m
= new StringBuilder();
67 while (m
.length() < 25)
70 if (totalWork
== UNKNOWN
) {
73 final String twstr
= String
.valueOf(totalWork
);
74 String cmpstr
= String
.valueOf(cmp
);
75 while (cmpstr
.length() < twstr
.length())
76 cmpstr
= " " + cmpstr
;
77 final int pcnt
= (cmp
* 100 / totalWork
);
89 task
.subTask(m
.toString());
95 public void endTask() {
105 public boolean isCancelled() {
107 return task
.isCanceled();
108 return root
.isCanceled();