View Javadoc

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