1
|
|
2
|
package eu.etaxonomy.cdm.common.monitor;
|
3
|
|
4
|
import java.io.Serializable;
|
5
|
|
6
|
|
7
|
|
8
|
/**
|
9
|
* This progress monitor interface is ad adaptation of the eclipse
|
10
|
* org.eclipse.core.runtime.IProgressMonitor ;
|
11
|
*
|
12
|
* The <code>IProgressMonitor</code> interface is implemented
|
13
|
* by objects that monitor the progress of an activity; the methods
|
14
|
* in this interface are invoked by code that performs the activity.
|
15
|
* <p>
|
16
|
* All activity is broken down into a linear sequence of tasks against
|
17
|
* which progress is reported. When a task begins, a <code>beginTask(String, int)
|
18
|
* </code> notification is reported, followed by any number and mixture of
|
19
|
* progress reports (<code>worked()</code>) and subtask notifications
|
20
|
* (<code>subTask(String)</code>). When the task is eventually completed, a
|
21
|
* <code>done()</code> notification is reported. After the <code>done()</code>
|
22
|
* notification, the progress monitor cannot be reused; i.e., <code>
|
23
|
* beginTask(String, int)</code> cannot be called again after the call to
|
24
|
* <code>done()</code>.
|
25
|
* </p>
|
26
|
* <p>
|
27
|
* A request to cancel an operation can be signaled using the
|
28
|
* <code>setCanceled</code> method. Operations taking a progress
|
29
|
* monitor are expected to poll the monitor (using <code>isCanceled</code>)
|
30
|
* periodically and abort at their earliest convenience. Operation can however
|
31
|
* choose to ignore cancelation requests.
|
32
|
* </p>
|
33
|
* <p>
|
34
|
* Since notification is synchronous with the activity itself, the listener should
|
35
|
* provide a fast and robust implementation. If the handling of notifications would
|
36
|
* involve blocking operations, or operations which might throw uncaught exceptions,
|
37
|
* the notifications should be queued, and the actual processing deferred (or perhaps
|
38
|
* delegated to a separate thread).
|
39
|
* </p><p>
|
40
|
* This interface can be used without OSGi running.
|
41
|
* </p><p>
|
42
|
* Clients may implement this interface.
|
43
|
* </p>
|
44
|
*/
|
45
|
public interface IProgressMonitor extends Serializable {
|
46
|
|
47
|
/** Constant indicating an unknown amount of work.
|
48
|
*/
|
49
|
public final static int UNKNOWN = -1;
|
50
|
|
51
|
/**
|
52
|
* Notifies that the main task is beginning. This must only be called once
|
53
|
* on a given progress monitor instance.
|
54
|
*
|
55
|
* @param name the name (or description) of the main task
|
56
|
* @param totalWork the total number of work units into which
|
57
|
* the main task is been subdivided. If the value is <code>UNKNOWN</code>
|
58
|
* the implementation is free to indicate progress in a way which
|
59
|
* doesn't require the total number of work units in advance.
|
60
|
*/
|
61
|
public void beginTask(String name, int totalWork);
|
62
|
|
63
|
/**
|
64
|
* Notifies that the work is done; that is, either the main task is completed
|
65
|
* or the user canceled it. This method may be called more than once
|
66
|
* (implementations should be prepared to handle this case).
|
67
|
*/
|
68
|
public void done();
|
69
|
|
70
|
|
71
|
/**
|
72
|
* Returns whether cancelation of current operation has been requested.
|
73
|
* Long-running operations should poll to see if cancelation
|
74
|
* has been requested.
|
75
|
*
|
76
|
* @return <code>true</code> if cancellation has been requested,
|
77
|
* and <code>false</code> otherwise
|
78
|
* @see #setCanceled(boolean)
|
79
|
*/
|
80
|
public boolean isCanceled();
|
81
|
|
82
|
/**
|
83
|
* Sets the cancel state to the given value.
|
84
|
*
|
85
|
* @param value <code>true</code> indicates that cancelation has
|
86
|
* been requested (but not necessarily acknowledged);
|
87
|
* <code>false</code> clears this flag
|
88
|
* @see #isCanceled()
|
89
|
*/
|
90
|
public void setCanceled(boolean value);
|
91
|
|
92
|
/**
|
93
|
* Sets the task name to the given value. This method is used to
|
94
|
* restore the task label after a nested operation was executed.
|
95
|
* Normally there is no need for clients to call this method.
|
96
|
*
|
97
|
* @param name the name (or description) of the main task
|
98
|
* @see #beginTask(java.lang.String, int)
|
99
|
*/
|
100
|
public void setTaskName(String name);
|
101
|
|
102
|
/**
|
103
|
* Notifies that a subtask of the main task is beginning.
|
104
|
* Subtasks are optional; the main task might not have subtasks.
|
105
|
*
|
106
|
* @param name the name (or description) of the subtask
|
107
|
*/
|
108
|
public void subTask(String name);
|
109
|
|
110
|
/**
|
111
|
* Notifies that a given number of work unit of the main task
|
112
|
* has been completed. Note that this amount represents an
|
113
|
* installment, as opposed to a cumulative amount of work done
|
114
|
* to date.
|
115
|
*
|
116
|
* @param work a non-negative number of work units just completed
|
117
|
*/
|
118
|
public void worked(int work);
|
119
|
|
120
|
/**
|
121
|
* Internal method to handle scaling correctly. This method
|
122
|
* must not be called by a client. Clients should
|
123
|
* always use the method </code>worked(int)</code>.
|
124
|
*
|
125
|
* @param work the amount of work done
|
126
|
*/
|
127
|
public void internalWorked(double work);
|
128
|
|
129
|
|
130
|
/**
|
131
|
* Notifies about a warning
|
132
|
* @param message
|
133
|
*/
|
134
|
public void warning(String message);
|
135
|
|
136
|
/**
|
137
|
* Notifies about a warning that was caused by an exception.
|
138
|
* @param message
|
139
|
* @param throwable
|
140
|
*/
|
141
|
public void warning(String message, Throwable throwable);
|
142
|
|
143
|
}
|
144
|
|
145
|
|