KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > runtime > ProgressMonitorWrapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 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  *******************************************************************************/

11 package org.eclipse.core.runtime;
12
13 /**
14  * An abstract wrapper around a progress monitor which,
15  * unless overridden, forwards <code>IProgressMonitor</code>
16  * and <code>IProgressMonitorWithBlocking</code> methods to the wrapped progress monitor.
17  * <p>
18  * This class can be used without OSGi running.
19  * </p><p>
20  * Clients may subclass.
21  * </p>
22  */

23 public abstract class ProgressMonitorWrapper implements IProgressMonitor, IProgressMonitorWithBlocking {
24
25     /** The wrapped progress monitor. */
26     private IProgressMonitor progressMonitor;
27
28     /**
29      * Creates a new wrapper around the given monitor.
30      *
31      * @param monitor the progress monitor to forward to
32      */

33     protected ProgressMonitorWrapper(IProgressMonitor monitor) {
34         Assert.isNotNull(monitor);
35         progressMonitor = monitor;
36     }
37
38     /**
39      * This implementation of a <code>IProgressMonitor</code>
40      * method forwards to the wrapped progress monitor.
41      * Clients may override this method to do additional
42      * processing.
43      *
44      * @see IProgressMonitor#beginTask(String, int)
45      */

46     public void beginTask(String JavaDoc name, int totalWork) {
47         progressMonitor.beginTask(name, totalWork);
48     }
49
50     /**
51      * This implementation of a <code>IProgressMonitorWithBlocking</code>
52      * method forwards to the wrapped progress monitor.
53      * Clients may override this method to do additional
54      * processing.
55      *
56      * @see IProgressMonitorWithBlocking#clearBlocked()
57      * @since 3.0
58      */

59     public void clearBlocked() {
60         if (progressMonitor instanceof IProgressMonitorWithBlocking)
61             ((IProgressMonitorWithBlocking) progressMonitor).clearBlocked();
62     }
63
64     /**
65      * This implementation of a <code>IProgressMonitor</code>
66      * method forwards to the wrapped progress monitor.
67      * Clients may override this method to do additional
68      * processing.
69      *
70      * @see IProgressMonitor#done()
71      */

72     public void done() {
73         progressMonitor.done();
74     }
75
76     /**
77      * Returns the wrapped progress monitor.
78      *
79      * @return the wrapped progress monitor
80      */

81     public IProgressMonitor getWrappedProgressMonitor() {
82         return progressMonitor;
83     }
84
85     /**
86      * This implementation of a <code>IProgressMonitor</code>
87      * method forwards to the wrapped progress monitor.
88      * Clients may override this method to do additional
89      * processing.
90      *
91      * @see IProgressMonitor#internalWorked(double)
92      */

93     public void internalWorked(double work) {
94         progressMonitor.internalWorked(work);
95     }
96
97     /**
98      * This implementation of a <code>IProgressMonitor</code>
99      * method forwards to the wrapped progress monitor.
100      * Clients may override this method to do additional
101      * processing.
102      *
103      * @see IProgressMonitor#isCanceled()
104      */

105     public boolean isCanceled() {
106         return progressMonitor.isCanceled();
107     }
108
109     /**
110      * This implementation of a <code>IProgressMonitorWithBlocking</code>
111      * method forwards to the wrapped progress monitor.
112      * Clients may override this method to do additional
113      * processing.
114      *
115      * @see IProgressMonitorWithBlocking#setBlocked(IStatus)
116      * @since 3.0
117      */

118     public void setBlocked(IStatus reason) {
119         if (progressMonitor instanceof IProgressMonitorWithBlocking)
120             ((IProgressMonitorWithBlocking) progressMonitor).setBlocked(reason);
121     }
122
123     /**
124      * This implementation of a <code>IProgressMonitor</code>
125      * method forwards to the wrapped progress monitor.
126      * Clients may override this method to do additional
127      * processing.
128      *
129      * @see IProgressMonitor#setCanceled(boolean)
130      */

131     public void setCanceled(boolean b) {
132         progressMonitor.setCanceled(b);
133     }
134
135     /**
136      * This implementation of a <code>IProgressMonitor</code>
137      * method forwards to the wrapped progress monitor.
138      * Clients may override this method to do additional
139      * processing.
140      *
141      * @see IProgressMonitor#setTaskName(String)
142      */

143     public void setTaskName(String JavaDoc name) {
144         progressMonitor.setTaskName(name);
145     }
146
147     /**
148      * This implementation of a <code>IProgressMonitor</code>
149      * method forwards to the wrapped progress monitor.
150      * Clients may override this method to do additional
151      * processing.
152      *
153      * @see IProgressMonitor#subTask(String)
154      */

155     public void subTask(String JavaDoc name) {
156         progressMonitor.subTask(name);
157     }
158
159     /**
160      * This implementation of a <code>IProgressMonitor</code>
161      * method forwards to the wrapped progress monitor.
162      * Clients may override this method to do additional
163      * processing.
164      *
165      * @see IProgressMonitor#worked(int)
166      */

167     public void worked(int work) {
168         progressMonitor.worked(work);
169     }
170 }
171
Popular Tags