Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have given below a simple example on how to use <a href="http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Foperation%2FIRunnableWithProgress.html" rel="nofollow">IRunnableWithProgress</a> along with a <a href="http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fdialogs%2FProgressMonitorDialog.html" rel="nofollow">ProgressMonitorDialog</a> to perform a task of unknown quantity. To start with, have an implementation to IRunnableWithProgress from where the actual task is performed. This implementation could be an inner class.</p> <pre class="lang-java prettyprint-override"><code>public class MyRunnableWithProgress implements IRunnableWithProgress { private String _fileName; public MyRunnableWithProgress(String fileName) { _fileName = fileName; } @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { int totalUnitsOfWork = IProgressMonitor.UNKNOWN; monitor.beginTask("Performing read. Please wait...", totalUnitsOfWork); performRead(_fileName, monitor); // This only performs the tasks monitor.done(); } } </code></pre> <p>Now, a generic implementation to <em>ProgressMonitorDialog</em> can be created as below which could be used for other places where a progress monitor dialog is required.</p> <pre class="lang-java prettyprint-override"><code>public class MyProgressMonitorDialog extends ProgressMonitorDialog { private boolean cancellable; public MyProgressMonitorDialog(Shell parent, boolean cancellable) { super(parent); this.cancellable = cancellable; } @Override public Composite createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); setCancelable(cancellable); return container; } } </code></pre> <p>Having got the required implementation, the task can be invoked as below to get it processed with a progress dialog.</p> <pre class="lang-java prettyprint-override"><code>boolean cancellable = false; IRunnableWithProgress myRunnable = new MyRunnableWithProgress(receivedFileName); ProgressMonitorDialog progressMonitorDialog = new MyProgressMonitorDialog(getShell(), cancellable); try { progressMonitorDialog.run(true, true, myRunnable); } catch (InvocationTargetException e) { // Catch in your best way throw new RuntimeException(e); } catch (InterruptedException e) { //Catch in your best way Thread.currentThread().interrupt(); } </code></pre> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload