Class ProgressHandleMonitor

  • All Implemented Interfaces:
    ProgressMonitor, org.openide.util.Cancellable

    public class ProgressHandleMonitor
    extends Object
    implements ProgressMonitor, org.openide.util.Cancellable
    A progress monitor that notifies a ProgressHandle instance (of the NetBeans Progress API).

    Use case 1:

         ProgressHandleMonitor pm = ProgressHandleMonitor.create("Training");
         Runnable operation = () -> {
             pm.beginTask("Classifier training...", 100);
             try {
                 session.startTraining(queryPatches, pm);
             } catch (Exception e) {
                 SnapApp.getDefault().handleError("Failed to train classifier", e);
             } finally {
                 pm.done();
             }
        };
        ProgressUtils.runOffEventThreadWithProgressDialog(operation, "Extracting Features", pm.getProgressHandle(), true, 50, 1000);
     

    Use case 2:

        RequestProcessor.getDefault().post(() -> {
            ProgressHandle handle = ProgressHandleFactory.createHandle("Performing time consuming task");
            ProgressMonitor pm = new ProgressHandleMonitor(handle);
            performTimeConsumingTask(pm);
        });
     
    Since:
    SNAP 2
    • Constructor Detail

      • ProgressHandleMonitor

        public ProgressHandleMonitor​(org.netbeans.api.progress.ProgressHandle progressHandle)
    • Method Detail

      • getProgressHandle

        public org.netbeans.api.progress.ProgressHandle getProgressHandle()
        Returns:
        The progress handle.
      • setProgressHandle

        public void setProgressHandle​(org.netbeans.api.progress.ProgressHandle progressHandle)
        Parameters:
        progressHandle - The progress handle.
      • cancel

        public boolean cancel()
        Specified by:
        cancel in interface org.openide.util.Cancellable