/** * Starts a new main task. The string argument is ignored * if and only if the SUPPRESS_BEGINTASK flag has been set on this SubMonitor * instance. * * <p>This method is equivalent calling setWorkRemaining(...) on the receiver. Unless * the SUPPRESS_BEGINTASK flag is set, this will also be equivalent to calling * setTaskName(...) on the parent.</p> * * @param name new main task name * @param totalWork number of ticks to allocate * * @see org.eclipse.core.runtime.IProgressMonitor#beginTask(java.lang.String, int) */ @Override public void beginTask(String name, int totalWork) { if (TracingOptions.debugProgressMonitors && beginTaskCalled) { logProblem("beginTask was called on this instance more than once"); //$NON-NLS-1$ } beginTaskImpl(name, totalWork); }
/** * <p>Converts an unknown (possibly null) IProgressMonitor into a SubMonitor allocated * with the given number of ticks. It is not necessary to call done() on the result, * but the caller is responsible for calling done() on the argument. Calls beginTask * on the argument.</p> * * <p>This method should generally be called at the beginning of a method that accepts * an IProgressMonitor in order to convert the IProgressMonitor into a SubMonitor.</p> * * <p>Since it is illegal to call beginTask on the same IProgressMonitor more than once, * the same instance of IProgressMonitor must not be passed to convert more than once.</p> * * @param monitor to convert into a SubMonitor instance or null. If given a null argument, * the resulting SubMonitor will not report its progress anywhere. * @param taskName user readable name to pass to monitor.beginTask. Never null. * @param work initial number of ticks to allocate for children of the SubMonitor * @return a new SubMonitor instance that is a child of the given monitor */ public static SubMonitor convert(IProgressMonitor monitor, String taskName, int work) { if (monitor == null) monitor = new NullProgressMonitor(); // Optimization: if the given monitor already a SubMonitor, no conversion is necessary if (monitor instanceof SubMonitor) { SubMonitor subMonitor = (SubMonitor) monitor; subMonitor.beginTaskImpl(taskName, work); return subMonitor; } monitor.beginTask(taskName, MINIMUM_RESOLUTION); return new SubMonitor(new RootInfo(monitor), MINIMUM_RESOLUTION, work, SUPPRESS_NONE); }