Class ProgressMonitorTask

  • All Implemented Interfaces:
    Runnable
    Direct Known Subclasses:
    GetDataTask

    public abstract class ProgressMonitorTask
    extends Object
    implements Runnable
    Subclass this for use in a ProgressMonitor. Responsibilities of your subclass:
    • You must provide the run method, which actually does the work that the ProgressMonitor is showing progress for.
    • You must set the done flag for the ProgressMonitor to complete. To avoid race conditions, do eveything else before you set the done flag.
    • You should override setProgress() and return a real count that corresponds to progressMaxCount in ProgressMonitor.start().
    • If possible, you should stop working if isCancel(). Usually this means checking the cancel flag in an iteration.
    • You should set the success flag if everything worked ok.
    • You should set an error message if there is an error. Normally you would also set done=true, and stop working. The ProgressMonitor will detect this and exit.
    The ProgressMonitor will:
    • Call cancel() if the user pressed cancel.
    • Set progress value by counting elapsed seconds. You may overrride this by overridding getProgress() and/or getNote().
    Also can be adapted as a CancelTask implementation.
    See Also:
    ProgressMonitor
    • Field Detail

      • done

        protected boolean done
      • success

        protected boolean success
      • cancel

        protected boolean cancel
      • error

        protected String error
      • progress

        protected int progress
    • Constructor Detail

      • ProgressMonitorTask

        public ProgressMonitorTask()
    • Method Detail

      • run

        public abstract void run()
        Here is where the work gets done.
        Specified by:
        run in interface Runnable
      • isSuccess

        public boolean isSuccess()
        Application calls to see if task is success.
      • isCancel

        public boolean isCancel()
        Application calls to see if task is cancelled.
      • isError

        public boolean isError()
        Applications call this to find out if there was an error.
      • getErrorMessage

        public String getErrorMessage()
        Applications call this to get an error message.
      • isDone

        public boolean isDone()
        ProgressMonitor calls to see if task is done.
      • cancel

        public void cancel()
        ProgressMonitor will call this when the user cancels.
      • getNote

        public String getNote()
        ProgressMonitor displays this note in the ProgressMonitor. If null, ProgressMonitor will show elasped seconds.
      • getProgress

        public int getProgress()
        ProgressMonitor displays this progress value in the ProgressMonitor. If <0, ProgressMonitor will show elasped seconds.
      • setError

        public void setError​(String error)
        for compatibility with ucar.nc2.CancelTask
      • setProgress

        public void setProgress​(String msg,
                                int progress)
      • setDone

        public void setDone​(boolean done)