comparison org.eclipse.jface/src/org/eclipse/jface/viewers/deferred/FastProgressReporter.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2004, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.jface.viewers.deferred.FastProgressReporter;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16
17 import java.lang.all;
18 import java.util.Set;
19
20 /**
21 * A more efficient alternative to an IProgressMonitor. In particular, the implementation
22 * is designed to make isCanceled() run as efficiently as possible. Currently package-visible
23 * because the implementation is incomplete.
24 *
25 * @since 3.1
26 */
27 final class FastProgressReporter {
28 private IProgressMonitor monitor;
29 private /+volatile+/ bool canceled = false;
30 private int cancelCheck = 0;
31 // private String taskName;
32 //
33 // private int taskDepth = 0;
34 // private int subTaskSize = 1;
35 // private int totalWork = 1;
36 // private int parentWork = 1;
37 // private int monitorUnitsRemaining;
38
39 private static int CANCEL_CHECK_PERIOD = 40;
40
41 /**
42 * Constructs a null FastProgressReporter
43 */
44 public this() {
45 }
46
47 /**
48 * Constructs a FastProgressReporter that wraps the given progress monitor
49 *
50 * @param monitor the monitor to wrap
51 * @param totalProgress the total progress to be reported
52 */
53 public this(IProgressMonitor monitor, int totalProgress) {
54 this.monitor = monitor;
55 //monitorUnitsRemaining = totalProgress;
56 canceled = monitor.isCanceled();
57 }
58
59 // /**
60 // * Every call to beginTask must have a corresponding call to endTask, with the
61 // * same argument.
62 // *
63 // * @param totalWork
64 // * @since 3.1
65 // */
66 // public void beginTask(int totalWork) {
67 //
68 // if (monitor is null) {
69 // return;
70 // }
71 //
72 // taskDepth++;
73 //
74 // if (totalWork is 0) {
75 // return;
76 // }
77 //
78 // this.totalWork *= totalWork;
79 // }
80 //
81 // public void beginSubTask(int subTaskWork) {
82 // subTaskSize *= subTaskWork;
83 // }
84 //
85 // public void endSubTask(int subTaskWork) {
86 // subTaskSize /= subTaskWork;
87 // }
88 //
89 // public void worked(int amount) {
90 // amount *= subTaskSize;
91 //
92 // if (amount > totalWork) {
93 // amount = totalWork;
94 // }
95 //
96 // int consumed = monitorUnitsRemaining * amount / totalWork;
97 //
98 // if (consumed > 0) {
99 // monitor.worked(consumed);
100 // monitorUnitsRemaining -= consumed;
101 // }
102 // totalWork -= amount;
103 // }
104 //
105 // public void endTask(int totalWork) {
106 // taskDepth--;
107 //
108 // if (taskDepth is 0) {
109 // if (monitor !is null && monitorUnitsRemaining > 0) {
110 // monitor.worked(monitorUnitsRemaining);
111 // }
112 // }
113 //
114 // if (totalWork is 0) {
115 // return;
116 // }
117 //
118 // this.totalWork /= totalWork;
119 //
120 // }
121
122 /**
123 * Return whether the progress monitor has been canceled.
124 *
125 * @return <code>true</code> if the monitor has been cancelled, <code>false</code> otherwise.
126 */
127 public bool isCanceled() {
128 if (monitor is null) {
129 return canceled;
130 }
131
132 cancelCheck++;
133 if (cancelCheck > CANCEL_CHECK_PERIOD) {
134 canceled = monitor.isCanceled();
135 cancelCheck = 0;
136 }
137 return canceled;
138 }
139
140 /**
141 * Cancel the progress monitor.
142 */
143 public void cancel() {
144 canceled = true;
145
146 if (monitor is null) {
147 return;
148 }
149 monitor.setCanceled(true);
150 }
151 }