comparison dwtx/core/runtime/jobs/ProgressProvider.d @ 122:9d0585bcb7aa

Add core.jobs package
author Frank Benoit <benoit@tionex.de>
date Tue, 12 Aug 2008 02:34:21 +0200
parents
children
comparison
equal deleted inserted replaced
121:c0304616ea23 122:9d0585bcb7aa
1 /*******************************************************************************
2 * Copyright (c) 2003, 2006 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 dwtx.core.runtime.jobs.ProgressProvider;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.core.runtime.IProgressMonitor;
18 import dwtx.core.runtime.NullProgressMonitor;
19 import dwtx.core.runtime.SubProgressMonitor;
20
21 import dwtx.core.runtime.jobs.Job;
22
23 /**
24 * The progress provider supplies the job manager with progress monitors for
25 * running jobs. There can only be one progress provider at any given time.
26 * <p>
27 * This class is intended for use by the currently executing Eclipse application.
28 * Plug-ins outside the currently running application should not reference or
29 * subclass this class.
30 * </p>
31 *
32 * @see IJobManager#setProgressProvider(ProgressProvider)
33 * @since 3.0
34 */
35 public abstract class ProgressProvider {
36 /**
37 * Provides a new progress monitor instance to be used by the given job.
38 * This method is called prior to running any job that does not belong to a
39 * progress group. The returned monitor will be supplied to the job's
40 * <code>run</code> method.
41 *
42 * @see #createProgressGroup()
43 * @see Job#setProgressGroup(IProgressMonitor, int)
44 * @param job the job to create a progress monitor for
45 * @return a progress monitor, or <code>null</code> if no progress monitoring
46 * is needed.
47 */
48 public abstract IProgressMonitor createMonitor(Job job);
49
50 /**
51 * Returns a progress monitor that can be used to provide
52 * aggregated progress feedback on a set of running jobs.
53 * This method implements <code>IJobManager.createProgressGroup</code>,
54 * and must obey all rules specified in that contract.
55 * <p>
56 * This default implementation returns a new
57 * <code>NullProgressMonitor</code> Subclasses may override.
58 *
59 * @see IJobManager#createProgressGroup()
60 * @return a progress monitor
61 */
62 public IProgressMonitor createProgressGroup() {
63 return new NullProgressMonitor();
64 }
65
66 /**
67 * Returns a progress monitor that can be used by a running job
68 * to report progress in the context of a progress group. This method
69 * implements <code>Job.setProgressGroup</code>. One of the
70 * two <code>createMonitor</code> methods will be invoked
71 * prior to each execution of a job, depending on whether a progress
72 * group was specified for the job.
73 * <p>
74 * The provided monitor must be a monitor returned by the method
75 * <code>createProgressGroup</code>. This method is responsible
76 * for asserting this and throwing an appropriate runtime exception
77 * if an invalid monitor is provided.
78 * <p>
79 * This default implementation returns a new
80 * <code>SubProgressMonitor</code>. Subclasses may override.
81 *
82 * @see IJobManager#createProgressGroup()
83 * @see Job#setProgressGroup(IProgressMonitor, int)
84 * @param job the job to create a progress monitor for
85 * @param group the progress monitor group that this job belongs to
86 * @param ticks the number of ticks of work for the progress monitor
87 * @return a progress monitor, or <code>null</code> if no progress monitoring
88 * is needed.
89 */
90 public IProgressMonitor createMonitor(Job job, IProgressMonitor group, int ticks) {
91 return new SubProgressMonitor(group, ticks);
92 }
93
94 /**
95 * Returns a progress monitor to use when none has been provided
96 * by the client running the job.
97 * <p>
98 * This default implementation returns a new
99 * <code>NullProgressMonitor</code> Subclasses may override.
100 *
101 * @return a progress monitor
102 */
103 public IProgressMonitor getDefaultMonitor() {
104 return new NullProgressMonitor();
105 }
106 }