예제 #1
0
  /**
   * Checks if there was an error.
   *
   * @param caller The caller or <code>null</code>.
   * @param status The status. <code>null</code> if status should not be checked.
   * @param callback The callback to call on cancel or error.
   * @return <code>false</code> if everything is OK.
   */
  public static final boolean isError(Object caller, IStatus status, ICallback callback) {
    if (status == null) status = Status.OK_STATUS;

    if (!status.isOK() && status.getSeverity() != IStatus.CANCEL) {
      if (status.getSeverity() == IStatus.ERROR) {
        Throwable e = status.getException();
        try {
          throw e;
        } catch (Throwable thrown) {
          e = thrown;
        }
        CoreBundleActivator.getTraceHandler()
            .trace(
                status.getMessage(),
                1,
                ITraceIds.TRACE_CALLBACKS,
                status.getSeverity(),
                caller != null ? caller.getClass() : ProgressHelper.class);
        status =
            new Status(IStatus.ERROR, status.getPlugin(), status.getCode(), status.getMessage(), e);
      }

      if (callback != null) {
        if (caller instanceof ICallback) {
          Callback.copyProperties((ICallback) caller, callback);
        }
        callback.done(caller, status);
      }
      return true;
    }
    return false;
  }
예제 #2
0
  /**
   * Checks if the operation was canceled.
   *
   * @param caller The caller or <code>null</code>.
   * @param status The status. <code>null</code> if status should not be checked.
   * @param progress The progress monitor. <code>null</code> if cancel should not be checked.
   * @param callback The callback to call on cancel or error.
   * @return <code>false</code> if everything is OK.
   */
  public static final boolean isCancel(
      Object caller, IStatus status, IProgressMonitor progress, ICallback callback) {
    if (status == null) status = Status.OK_STATUS;

    if (status.getSeverity() == IStatus.CANCEL || (progress != null && progress.isCanceled())) {
      status =
          new Status(
              IStatus.CANCEL,
              status.getPlugin(),
              status.getCode(),
              status.getMessage(),
              new OperationCanceledException());

      if (callback != null) {
        if (caller instanceof ICallback) {
          Callback.copyProperties((ICallback) caller, callback);
        }
        callback.done(caller, status);
      }
      return true;
    }
    return false;
  }