comparison org.eclipse.equinox.common/src/org/eclipse/core/runtime/SubProgressMonitor.d @ 105:bbe49769ec18

...
author Frank Benoit <benoit@tionex.de>
date Sun, 08 Nov 2009 12:42:30 +0100
parents bc29606a740c
children
comparison
equal deleted inserted replaced
104:88652073d1c2 105:bbe49769ec18
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/ 10 *******************************************************************************/
13 module org.eclipse.core.runtime.SubProgressMonitor; 11 // Port to the D programming language:
14 12 // Frank Benoit <benoit@tionex.de>
15 import org.eclipse.core.runtime.ProgressMonitorWrapper; 13 module org.eclipse.core.runtimeSubProgressMonitor;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 14
18 import java.lang.all; 15 import java.lang.all;
19 16
17 import org.eclipse.core.runtimeIProgressMonitor; // packageimport
18 import org.eclipse.core.runtimeProgressMonitorWrapper; // packageimport
19
20 /** 20 /**
21 * For new implementations consider using {@link SubMonitor}. 21 * For new implementations consider using {@link SubMonitor}.
22 * 22 *
23 * A progress monitor that uses a given amount of work ticks 23 * A progress monitor that uses a given amount of work ticks
24 * from a parent monitor. It can be used as follows: 24 * from a parent monitor. It can be used as follows:
25 * <pre> 25 * <pre>
26 * try { 26 * try {
27 * pm.beginTask("Main Task", 100); 27 * pm.beginTask("Main Task", 100);
41 * <p> 41 * <p>
42 * This class can be used without OSGi running. 42 * This class can be used without OSGi running.
43 * </p><p> 43 * </p><p>
44 * This class may be instantiated or subclassed by clients. 44 * This class may be instantiated or subclassed by clients.
45 * </p> 45 * </p>
46 * 46 *
47 * @see SubMonitor 47 * @see SubMonitor
48 */ 48 */
49 public class SubProgressMonitor : ProgressMonitorWrapper { 49 public class SubProgressMonitor : ProgressMonitorWrapper {
50 50
51 /** 51 /**
52 * Style constant indicating that calls to <code>subTask</code> 52 * Style constant indicating that calls to <code>subTask</code>
53 * should not have any effect. 53 * should not have any effect.
54 * 54 *
55 * @see #SubProgressMonitor(IProgressMonitor,int,int) 55 * @see #SubProgressMonitor(IProgressMonitor,int,int)
56 */ 56 */
57 public static const int SUPPRESS_SUBTASK_LABEL = 1 << 1; 57 public static final int SUPPRESS_SUBTASK_LABEL = 1 << 1;
58 /** 58 /**
59 * Style constant indicating that the main task label 59 * Style constant indicating that the main task label
60 * should be prepended to the subtask label. 60 * should be prepended to the subtask label.
61 * 61 *
62 * @see #SubProgressMonitor(IProgressMonitor,int,int) 62 * @see #SubProgressMonitor(IProgressMonitor,int,int)
63 */ 63 */
64 public static const int PREPEND_MAIN_LABEL_TO_SUBTASK = 1 << 2; 64 public static final int PREPEND_MAIN_LABEL_TO_SUBTASK = 1 << 2;
65 65
66 private int parentTicks = 0; 66 private int parentTicks = 0;
67 private double sentToParent = 0.0; 67 private double sentToParent = 0.0;
68 private double scale = 0.0; 68 private double scale = 0.0;
69 private int nestedBeginTasks = 0; 69 private int nestedBeginTasks = 0;
71 private bool hasSubTask = false; 71 private bool hasSubTask = false;
72 private int style; 72 private int style;
73 private String mainTaskLabel; 73 private String mainTaskLabel;
74 74
75 /** 75 /**
76 * Creates a new sub-progress monitor for the given monitor. The sub 76 * Creates a new sub-progress monitor for the given monitor. The sub
77 * progress monitor uses the given number of work ticks from its 77 * progress monitor uses the given number of work ticks from its
78 * parent monitor. 78 * parent monitor.
79 * 79 *
80 * @param monitor the parent progress monitor 80 * @param monitor the parent progress monitor
81 * @param ticks the number of work ticks allocated from the 81 * @param ticks the number of work ticks allocated from the
82 * parent monitor 82 * parent monitor
84 public this(IProgressMonitor monitor, int ticks) { 84 public this(IProgressMonitor monitor, int ticks) {
85 this(monitor, ticks, 0); 85 this(monitor, ticks, 0);
86 } 86 }
87 87
88 /** 88 /**
89 * Creates a new sub-progress monitor for the given monitor. The sub 89 * Creates a new sub-progress monitor for the given monitor. The sub
90 * progress monitor uses the given number of work ticks from its 90 * progress monitor uses the given number of work ticks from its
91 * parent monitor. 91 * parent monitor.
92 * 92 *
93 * @param monitor the parent progress monitor 93 * @param monitor the parent progress monitor
94 * @param ticks the number of work ticks allocated from the 94 * @param ticks the number of work ticks allocated from the
95 * parent monitor 95 * parent monitor
110 /* (Intentionally not javadoc'd) 110 /* (Intentionally not javadoc'd)
111 * Implements the method <code>IProgressMonitor.beginTask</code>. 111 * Implements the method <code>IProgressMonitor.beginTask</code>.
112 * 112 *
113 * Starts a new main task. Since this progress monitor is a sub 113 * Starts a new main task. Since this progress monitor is a sub
114 * progress monitor, the given name will NOT be used to update 114 * progress monitor, the given name will NOT be used to update
115 * the progress bar's main task label. That means the given 115 * the progress bar's main task label. That means the given
116 * string will be ignored. If style <code>PREPEND_MAIN_LABEL_TO_SUBTASK 116 * string will be ignored. If style <code>PREPEND_MAIN_LABEL_TO_SUBTASK
117 * <code> is specified, then the given string will be prepended to 117 * <code> is specified, then the given string will be prepended to
118 * every string passed to <code>subTask(String)</code>. 118 * every string passed to <code>subTask(String)</code>.
119 */ 119 */
120 public override void beginTask(String name, int totalWork) { 120 public void beginTask(String name, int totalWork) {
121 nestedBeginTasks++; 121 nestedBeginTasks++;
122 // Ignore nested begin task calls. 122 // Ignore nested begin task calls.
123 if (nestedBeginTasks > 1) { 123 if (nestedBeginTasks > 1) {
124 return; 124 return;
125 } 125 }
126 // be safe: if the argument would cause math errors (zero or 126 // be safe: if the argument would cause math errors (zero or
127 // negative), just use 0 as the scale. This disables progress for 127 // negative), just use 0 as the scale. This disables progress for
128 // this submonitor. 128 // this submonitor.
129 scale = totalWork <= 0 ? 0 : cast(double) parentTicks / cast(double) totalWork; 129 scale = totalWork <= 0 ? 0 : cast(double) parentTicks / cast(double) totalWork;
130 if ((style & PREPEND_MAIN_LABEL_TO_SUBTASK) !is 0) { 130 if ((style & PREPEND_MAIN_LABEL_TO_SUBTASK) !is 0) {
131 mainTaskLabel = name; 131 mainTaskLabel = name;
132 } 132 }
133 } 133 }
134 134
135 /* (Intentionally not javadoc'd) 135 /* (Intentionally not javadoc'd)
136 * Implements the method <code>IProgressMonitor.done</code>. 136 * Implements the method <code>IProgressMonitor.done</code>.
137 */ 137 */
138 public override void done() { 138 public void done() {
139 // Ignore if more done calls than beginTask calls or if we are still 139 // Ignore if more done calls than beginTask calls or if we are still
140 // in some nested beginTasks 140 // in some nested beginTasks
141 if (nestedBeginTasks is 0 || --nestedBeginTasks > 0) 141 if (nestedBeginTasks is 0 || --nestedBeginTasks > 0)
142 return; 142 return;
143 // Send any remaining ticks and clear out the subtask text 143 // Send any remaining ticks and clear out the subtask text
151 } 151 }
152 152
153 /* (Intentionally not javadoc'd) 153 /* (Intentionally not javadoc'd)
154 * Implements the internal method <code>IProgressMonitor.internalWorked</code>. 154 * Implements the internal method <code>IProgressMonitor.internalWorked</code>.
155 */ 155 */
156 public override void internalWorked(double work) { 156 public void internalWorked(double work) {
157 if (usedUp || nestedBeginTasks !is 1) { 157 if (usedUp || nestedBeginTasks !is 1) {
158 return; 158 return;
159 } 159 }
160 160
161 double realWork = (work > 0.0) ? scale * work : 0.0; 161 double realWork = (work > 0.0d) ? scale * work : 0.0d;
162 super.internalWorked(realWork); 162 super.internalWorked(realWork);
163 sentToParent += realWork; 163 sentToParent += realWork;
164 if (sentToParent >= parentTicks) { 164 if (sentToParent >= parentTicks) {
165 usedUp = true; 165 usedUp = true;
166 } 166 }
167 } 167 }
168 168
169 /* (Intentionally not javadoc'd) 169 /* (Intentionally not javadoc'd)
170 * Implements the method <code>IProgressMonitor.subTask</code>. 170 * Implements the method <code>IProgressMonitor.subTask</code>.
171 */ 171 */
172 public override void subTask(String name) { 172 public void subTask(String name) {
173 if ((style & SUPPRESS_SUBTASK_LABEL) !is 0) { 173 if ((style & SUPPRESS_SUBTASK_LABEL) !is 0) {
174 return; 174 return;
175 } 175 }
176 hasSubTask = true; 176 hasSubTask = true;
177 String label = name; 177 String label = name;
178 if ((style & PREPEND_MAIN_LABEL_TO_SUBTASK) !is 0 && mainTaskLabel !is null && mainTaskLabel.length > 0) { 178 if ((style & PREPEND_MAIN_LABEL_TO_SUBTASK) !is 0 && mainTaskLabel !is null && mainTaskLabel.length() > 0) {
179 label = mainTaskLabel ~ ' ' ~ label; 179 label = mainTaskLabel + ' ' + label;
180 } 180 }
181 super.subTask(label); 181 super.subTask(label);
182 } 182 }
183 183
184 /* (Intentionally not javadoc'd) 184 /* (Intentionally not javadoc'd)
185 * Implements the method <code>IProgressMonitor.worked</code>. 185 * Implements the method <code>IProgressMonitor.worked</code>.
186 */ 186 */
187 public override void worked(int work) { 187 public void worked(int work) {
188 internalWorked(work); 188 internalWorked(work);
189 } 189 }
190 } 190 }