Time for action – using null progress monitors and sub monitors

When a method uses progress monitors extensively, it is inelegant to keep checking whether the monitor is null or not. Instead, the progress monitor can be replaced with a NullProgressMonitor, which acts as a no-op for all monitor calls.

  1. Update the checkDozen to use a NullProgressMonitor if null is passed:
    private void checkDozen(IProgressMonitor monitor) {
      if (monitor == null)
        monitor = new NullProgressMonitor();

    This allows the remainder of the method to run without modification and saves any NullPointerException errors that may result.

  2. A similar result to both the NullProgressMonitor and a SubProgressMonitor with a wrapper/factory class called SubMonitor. This provides factory methods ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.