de.cau.cs.kieler.core.ui.util
Class MonitoredOperation

java.lang.Object
  extended by de.cau.cs.kieler.core.ui.util.MonitoredOperation

public abstract class MonitoredOperation
extends Object

An operation that can be tracked with a progress bar. This operation can be called from any thread, UI or non-UI, and adds only very little overhead for progress tracking compared to the usual synchronous tracking of the workbench progress service. Just implement execute(IProgressMonitor) and call runMonitored().

Rating proposed yellow
(2010-01-14) msp

Constructor Summary
MonitoredOperation()
           
 
Method Summary
protected abstract  IStatus execute(IProgressMonitor monitor)
          Execute the monitored operation.
 IStatus getStatus()
          Returns the status of the last operation run.
protected  void postUIexec(IStatus status)
          Executed in the UI thread after the operation has ended.
protected  void preUIexec()
          Executed in the UI thread before the operation starts.
static void runInUI(Runnable runnable, boolean synch)
          Execute the given runnable in the UI thread.
 void runMonitored()
          Run the operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonitoredOperation

public MonitoredOperation()
Method Detail

execute

protected abstract IStatus execute(IProgressMonitor monitor)
Execute the monitored operation.

Parameters:
monitor - the progress monitor for the operation
Returns:
a status indicating success or failure, or null

preUIexec

protected void preUIexec()
Executed in the UI thread before the operation starts. The default implementation does nothing.


postUIexec

protected void postUIexec(IStatus status)
Executed in the UI thread after the operation has ended. The default implementation does nothing.

Parameters:
status - the status returned by execute(IProgressMonitor)

runMonitored

public final void runMonitored()
Run the operation. If the current thread is the UI thread, the actual operation is executed in a new thread that runs in parallel. Otherwise the operation is executed directly and a handler for the progress monitor is executed in the parallel UI thread. In either case the method returns only after execution of the operation is done.


getStatus

public IStatus getStatus()
Returns the status of the last operation run.

Returns:
the last status, or null if the operation has not run yet

runInUI

public static final void runInUI(Runnable runnable,
                                 boolean synch)
Execute the given runnable in the UI thread. If the current thread is the UI thread, the runnable is simply run. Otherwise it is executed either synchronously or asynchronously in the UI thread.

Parameters:
runnable - a runnable
synch - if true or if the current thread is the UI thread, the method returns only after execution of the runnable, else it returns immediately