KickJava   Java API By Example, From Geeks To Geeks.

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


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  * The <code>IProgressMonitor</code> interface is implemented
15  * by objects that monitor the progress of an activity; the methods
16  * in this interface are invoked by code that performs the activity.
17  * <p>
18  * All activity is broken down into a linear sequence of tasks against
19  * which progress is reported. When a task begins, a <code>beginTask(String, int)
20  * </code> notification is reported, followed by any number and mixture of
21  * progress reports (<code>worked()</code>) and subtask notifications
22  * (<code>subTask(String)</code>). When the task is eventually completed, a
23  * <code>done()</code> notification is reported. After the <code>done()</code>
24  * notification, the progress monitor cannot be reused; i.e., <code>
25  * beginTask(String, int)</code> cannot be called again after the call to
26  * <code>done()</code>.
27  * </p>
28  * <p>
29  * A request to cancel an operation can be signaled using the
30  * <code>setCanceled</code> method. Operations taking a progress
31  * monitor are expected to poll the monitor (using <code>isCanceled</code>)
32  * periodically and abort at their earliest convenience. Operation can however
33  * choose to ignore cancelation requests.
34  * </p>
35  * <p>
36  * Since notification is synchronous with the activity itself, the listener should
37  * provide a fast and robust implementation. If the handling of notifications would
38  * involve blocking operations, or operations which might throw uncaught exceptions,
39  * the notifications should be queued, and the actual processing deferred (or perhaps
40  * delegated to a separate thread).
41  * </p><p>
42  * This interface can be used without OSGi running.
43  * </p><p>
44  * Clients may implement this interface.
45  * </p>
46  */

47 public interface IProgressMonitor {
48
49     /** Constant indicating an unknown amount of work.
50      */

51     public final static int UNKNOWN = -1;
52
53     /**
54      * Notifies that the main task is beginning. This must only be called once
55      * on a given progress monitor instance.
56      *
57      * @param name the name (or description) of the main task
58      * @param totalWork the total number of work units into which
59      * the main task is been subdivided. If the value is <code>UNKNOWN</code>
60      * the implementation is free to indicate progress in a way which
61      * doesn't require the total number of work units in advance.
62      */

63     public void beginTask(String JavaDoc name, int totalWork);
64
65     /**
66      * Notifies that the work is done; that is, either the main task is completed
67      * or the user canceled it. This method may be called more than once
68      * (implementations should be prepared to handle this case).
69      */

70     public void done();
71
72     /**
73      * Internal method to handle scaling correctly. This method
74      * must not be called by a client. Clients should
75      * always use the method </code>worked(int)</code>.
76      *
77      * @param work the amount of work done
78      */

79     public void internalWorked(double work);
80
81     /**
82      * Returns whether cancelation of current operation has been requested.
83      * Long-running operations should poll to see if cancelation
84      * has been requested.
85      *
86      * @return <code>true</code> if cancellation has been requested,
87      * and <code>false</code> otherwise
88      * @see #setCanceled(boolean)
89      */

90     public boolean isCanceled();
91
92     /**
93      * Sets the cancel state to the given value.
94      *
95      * @param value <code>true</code> indicates that cancelation has
96      * been requested (but not necessarily acknowledged);
97      * <code>false</code> clears this flag
98      * @see #isCanceled()
99      */

100     public void setCanceled(boolean value);
101
102     /**
103      * Sets the task name to the given value. This method is used to
104      * restore the task label after a nested operation was executed.
105      * Normally there is no need for clients to call this method.
106      *
107      * @param name the name (or description) of the main task
108      * @see #beginTask(java.lang.String, int)
109      */

110     public void setTaskName(String JavaDoc name);
111
112     /**
113      * Notifies that a subtask of the main task is beginning.
114      * Subtasks are optional; the main task might not have subtasks.
115      *
116      * @param name the name (or description) of the subtask
117      */

118     public void subTask(String JavaDoc name);
119
120     /**
121      * Notifies that a given number of work unit of the main task
122      * has been completed. Note that this amount represents an
123      * installment, as opposed to a cumulative amount of work done
124      * to date.
125      *
126      * @param work a non-negative number of work units just completed
127      */

128     public void worked(int work);
129 }
130
Popular Tags