EMMA Coverage Report (generated Mon Sep 29 15:05:28 EDT 2008)
[all classes][org.eclipse.jface.operation]

COVERAGE SUMMARY FOR SOURCE FILE [AccumulatingProgressMonitor.java]

nameclass, %method, %block, %line, %
AccumulatingProgressMonitor.java57%  (4/7)64%  (16/25)60%  (191/317)67%  (48.9/73)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccumulatingProgressMonitor$30%   (0/1)0%   (0/2)0%   (0/21)0%   (0/5)
AccumulatingProgressMonitor$3 (AccumulatingProgressMonitor, String): void 0%   (0/1)0%   (0/9)0%   (0/2)
run (): void 0%   (0/1)0%   (0/12)0%   (0/3)
     
class AccumulatingProgressMonitor$40%   (0/1)0%   (0/2)0%   (0/16)0%   (0/5)
AccumulatingProgressMonitor$4 (AccumulatingProgressMonitor, IProgressMonitor)... 0%   (0/1)0%   (0/9)0%   (0/2)
run (): void 0%   (0/1)0%   (0/7)0%   (0/3)
     
class AccumulatingProgressMonitor$50%   (0/1)0%   (0/2)0%   (0/28)0%   (0/5)
AccumulatingProgressMonitor$5 (AccumulatingProgressMonitor, IProgressMonitor,... 0%   (0/1)0%   (0/12)0%   (0/2)
run (): void 0%   (0/1)0%   (0/16)0%   (0/3)
     
class AccumulatingProgressMonitor100% (1/1)73%  (8/11)63%  (105/166)66%  (28.5/43)
clearBlocked (): void 0%   (0/1)0%   (0/16)0%   (0/5)
setBlocked (IStatus): void 0%   (0/1)0%   (0/17)0%   (0/5)
setTaskName (String): void 0%   (0/1)0%   (0/22)0%   (0/4)
done (): void 100% (1/1)86%  (18/21)94%  (3.8/4)
beginTask (String, int): void 100% (1/1)87%  (20/23)94%  (3.8/4)
AccumulatingProgressMonitor (IProgressMonitor, Display): void 100% (1/1)100% (12/12)100% (5/5)
clearCollector (AccumulatingProgressMonitor$Collector): void 100% (1/1)100% (8/8)100% (3/3)
createCollector (String, double): void 100% (1/1)100% (16/16)100% (3/3)
internalWorked (double): void 100% (1/1)100% (13/13)100% (4/4)
subTask (String): void 100% (1/1)100% (13/13)100% (4/4)
worked (int): void 100% (1/1)100% (5/5)100% (2/2)
     
class AccumulatingProgressMonitor$1100% (1/1)100% (2/2)100% (26/26)100% (5/5)
AccumulatingProgressMonitor$1 (AccumulatingProgressMonitor, String, int): void 100% (1/1)100% (12/12)100% (2/2)
run (): void 100% (1/1)100% (14/14)100% (3/3)
     
class AccumulatingProgressMonitor$2100% (1/1)100% (2/2)100% (11/11)100% (4/4)
AccumulatingProgressMonitor$2 (AccumulatingProgressMonitor): void 100% (1/1)100% (6/6)100% (2/2)
run (): void 100% (1/1)100% (5/5)100% (2/2)
     
class AccumulatingProgressMonitor$Collector100% (1/1)100% (4/4)100% (49/49)100% (15/15)
AccumulatingProgressMonitor$Collector (AccumulatingProgressMonitor, String, d... 100% (1/1)100% (15/15)100% (5/5)
run (): void 100% (1/1)100% (23/23)100% (6/6)
subTask (String): void 100% (1/1)100% (4/4)100% (2/2)
worked (double): void 100% (1/1)100% (7/7)100% (2/2)

1/*******************************************************************************
2 * Copyright (c) 2000, 2007 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 *******************************************************************************/
11package org.eclipse.jface.operation;
12 
13import org.eclipse.core.runtime.IProgressMonitor;
14import org.eclipse.core.runtime.IProgressMonitorWithBlocking;
15import org.eclipse.core.runtime.IStatus;
16import org.eclipse.core.runtime.ProgressMonitorWrapper;
17import org.eclipse.jface.dialogs.Dialog;
18import org.eclipse.core.runtime.Assert;
19import org.eclipse.swt.widgets.Display;
20 
21/**
22 * A progress monitor that accumulates <code>worked</code> and <code>subtask</code> 
23 * calls in the following way by wrapping a standard progress monitor:
24 * <ul>
25 * <li> When a <code>worked</code> or <code>subtask</code> call occurs the first time,
26 *                the progress monitor posts a runnable into the asynchronous SWT event queue.
27 * </li>
28 * <li> Subsequent calls to <code>worked</code> or <code>subtask</code> do not post
29 *                a new runnable as long as a previous runnable still exists in the SWT event
30 *                queue. In this case, the progress monitor just updates the internal state of
31 *                the runnable that waits in the SWT event queue for its execution. If no runnable
32 *                exists, a new one is created and posted into the event queue.
33 * </ul>
34 * <p>
35 * This class is internal to the framework; clients outside JFace should not
36 * use this class.
37 * </p>
38 */
39/* package */class AccumulatingProgressMonitor extends ProgressMonitorWrapper {
40 
41    /**
42     * The display.
43     */
44    private Display display;
45 
46    /**
47     * The collector, or <code>null</code> if none.
48     */
49    private Collector collector;
50 
51    private String currentTask = ""; //$NON-NLS-1$
52 
53    private class Collector implements Runnable {
54        private String subTask;
55 
56        private double worked;
57 
58        private IProgressMonitor monitor;
59 
60        /**
61         * Create a new collector.
62         * @param subTask
63         * @param work
64         * @param monitor
65         */
66        public Collector(String subTask, double work, IProgressMonitor monitor) {
67            this.subTask = subTask;
68            this.worked = work;
69            this.monitor = monitor;
70        }
71 
72        /**
73         * Add worked to the work.
74         * @param workedIncrement
75         */
76        public void worked(double workedIncrement) {
77            this.worked = this.worked + workedIncrement;
78        }
79 
80        /**
81         * Set the subTask name.
82         * @param subTaskName
83         */
84        public void subTask(String subTaskName) {
85            this.subTask = subTaskName;
86        }
87 
88        /**
89         * Run the collector.
90         */
91        public void run() {
92            clearCollector(this);
93            if (subTask != null) {
94                                monitor.subTask(subTask);
95                        }
96            if (worked > 0) {
97                                monitor.internalWorked(worked);
98                        }
99        }
100    }
101 
102    /**
103     * Creates an accumulating progress monitor wrapping the given one
104     * that uses the given display.
105     * 
106     * @param monitor the actual progress monitor to be wrapped
107     * @param display the SWT display used to forward the calls 
108     *  to the wrapped progress monitor
109     */
110    public AccumulatingProgressMonitor(IProgressMonitor monitor, Display display) {
111        super(monitor);
112        Assert.isNotNull(display);
113        this.display = display;
114    }
115 
116    /* (non-Javadoc)
117     * Method declared on IProgressMonitor.
118     */
119    public void beginTask(final String name, final int totalWork) {
120        synchronized (this) {
121            collector = null;
122        }
123        display.asyncExec(new Runnable() {
124            public void run() {
125                currentTask = name;
126                getWrappedProgressMonitor().beginTask(name, totalWork);
127            }
128        });
129    }
130 
131    /**
132     * Clears the collector object used to accumulate work and subtask calls
133     * if it matches the given one.
134     * @param collectorToClear
135     */
136    private synchronized void clearCollector(Collector collectorToClear) {
137        // Check if the accumulator is still using the given collector.
138        // If not, don't clear it.
139        if (this.collector == collectorToClear) {
140                        this.collector = null;
141                }
142    }
143 
144    /**
145     *  Creates a collector object to accumulate work and subtask calls.
146     * @param subTask
147     * @param work
148     */
149    private void createCollector(String subTask, double work) {
150        collector = new Collector(subTask, work, getWrappedProgressMonitor());
151        display.asyncExec(collector);
152    }
153 
154    /* (non-Javadoc)
155     * Method declared on IProgressMonitor.
156     */
157    public void done() {
158        synchronized (this) {
159            collector = null;
160        }
161        display.asyncExec(new Runnable() {
162            public void run() {
163                getWrappedProgressMonitor().done();
164            }
165        });
166    }
167 
168    /* (non-Javadoc)
169     * Method declared on IProgressMonitor.
170     */
171    public synchronized void internalWorked(final double work) {
172        if (collector == null) {
173            createCollector(null, work);
174        } else {
175            collector.worked(work);
176        }
177    }
178 
179    /* (non-Javadoc)
180     * Method declared on IProgressMonitor.
181     */
182    public void setTaskName(final String name) {
183        synchronized (this) {
184            collector = null;
185        }
186        display.asyncExec(new Runnable() {
187            public void run() {
188                currentTask = name;
189                getWrappedProgressMonitor().setTaskName(name);
190            }
191        });
192    }
193 
194    /* (non-Javadoc)
195     * Method declared on IProgressMonitor.
196     */
197    public synchronized void subTask(final String name) {
198        if (collector == null) {
199            createCollector(name, 0);
200        } else {
201            collector.subTask(name);
202        }
203    }
204 
205    /* (non-Javadoc)
206     * Method declared on IProgressMonitor.
207     */
208    public synchronized void worked(int work) {
209        internalWorked(work);
210    }
211 
212    /* (non-Javadoc)
213     * @see org.eclipse.core.runtime.ProgressMonitorWrapper#clearBlocked()
214     */
215    public void clearBlocked() {
216 
217        //If this is a monitor that can report blocking do so.
218        //Don't bother with a collector as this should only ever
219        //happen once and prevent any more progress.
220        final IProgressMonitor pm = getWrappedProgressMonitor();
221        if (!(pm instanceof IProgressMonitorWithBlocking)) {
222                        return;
223                }
224 
225        display.asyncExec(new Runnable() {
226            /* (non-Javadoc)
227             * @see java.lang.Runnable#run()
228             */
229            public void run() {
230                ((IProgressMonitorWithBlocking) pm).clearBlocked();
231                Dialog.getBlockedHandler().clearBlocked();
232            }
233        });
234    }
235 
236    /* (non-Javadoc)
237     * @see org.eclipse.core.runtime.ProgressMonitorWrapper#setBlocked(org.eclipse.core.runtime.IStatus)
238     */
239    public void setBlocked(final IStatus reason) {
240        //If this is a monitor that can report blocking do so.
241        //Don't bother with a collector as this should only ever
242        //happen once and prevent any more progress.
243        final IProgressMonitor pm = getWrappedProgressMonitor();
244        if (!(pm instanceof IProgressMonitorWithBlocking)) {
245                        return;
246                }
247 
248        display.asyncExec(new Runnable() {
249            /* (non-Javadoc)
250             * @see java.lang.Runnable#run()
251             */
252            public void run() {
253                ((IProgressMonitorWithBlocking) pm).setBlocked(reason);
254                //Do not give a shell as we want it to block until it opens.
255                Dialog.getBlockedHandler().showBlocked(pm, reason, currentTask);
256            }
257        });
258    }
259}

[all classes][org.eclipse.jface.operation]
EMMA 2.0.5312 EclEmma Fix 1 (C) Vladimir Roubtsov