示例#1
0
  /**
   * This method will print all given reports. It will either use the parameters set in {@link
   * #setNextRunParams(Map)} or ask the user to provide the report parameters.
   *
   * @param reportRegistryItems The ids of the reports to print.
   */
  public void runWithRegistryItemIDs(final Collection<ReportRegistryItemID> reportRegistryItems) {
    Job printJob =
        new Job(
            Messages.getString(
                "org.nightlabs.jfire.reporting.ui.layout.action.print.AbstractPrintReportLayoutAction.printJob.name")) { //$NON-NLS-1$
          @Override
          protected IStatus run(ProgressMonitor monitor) {
            monitor.beginTask(
                Messages.getString(
                    "org.nightlabs.jfire.reporting.ui.layout.action.print.AbstractPrintReportLayoutAction.printJob.beginPrintingTask.name"),
                IProgressMonitor.UNKNOWN); // $NON-NLS-1$
            Map<String, Object> params = null;
            boolean paramsSet = false;
            if (nextRunParams != null) {
              params = nextRunParams;
              paramsSet = true;
              nextRunParams = null;
            }
            ;
            String errorMessages = ""; // $NON-NLS-1$

            for (ReportRegistryItemID itemID : reportRegistryItems) {
              if (params == null && !paramsSet) {
                // if no parameters set by now, get them from the user
                WizardResult dialogResult = ReportParameterWizard.openResult(itemID, false);
                if (!dialogResult.isAcquisitionFinished()) return Status.OK_STATUS;
                params = dialogResult.getParameters();
                paramsSet = true;
              }
              try {
                printWithParams(itemID, params, monitor);
              } catch (PrinterException e) {
                errorMessages =
                    addErrMessage(
                        errorMessages,
                        "Printing failed for "
                            + itemID
                            + ": "
                            + e.getMessage()); // $NON-NLS-1$ //$NON-NLS-2$
                continue;
              }
            }
            if (!"".equals(errorMessages)) // $NON-NLS-1$
              // TODO: Maybe throw typed exception wrapped in RuntimeException
              throw new IllegalStateException(errorMessages);
            return Status.OK_STATUS;
          }
        };
    printJob.schedule();
  }
示例#2
0
  /**
   * Prints the given report (registryItemID) with the given parameters. The {@link ReportUseCase}
   * for the given report will be searched and used for printing.
   *
   * @param registryItemID The id of the report to print.
   * @param params The parameters to use to render the report.
   * @param monitor The monitor to report progress to.
   * @throws PrinterException If an error occurs while printing.
   */
  public void printWithParams(
      ReportRegistryItemID registryItemID, Map<String, Object> params, ProgressMonitor monitor)
      throws PrinterException {
    monitor.beginTask(
        Messages.getString(
            "org.nightlabs.jfire.reporting.ui.layout.action.print.AbstractPrintReportLayoutAction.task.printingReportLayout"),
        6); //$NON-NLS-1$
    String useCaseID = getReportUseCaseID(registryItemID, params);
    if (useCaseID == null) {
      // Try to lookup the UseCase by the reportLayoutType
      ReportUseCase useCase =
          ReportUseCaseRegistry.sharedInstance()
              .getReportUseCaseByLayoutType(registryItemID.reportRegistryItemType);
      if (useCase != null) useCaseID = useCase.getId();
    }
    if (useCaseID == null) {
      // if no usecase found till now, try to find the default/fallback one
      ReportUseCase useCase =
          ReportUseCaseRegistry.sharedInstance()
              .getReportUseCase(ReportingPlugin.DEFAULT_REPORT_USE_CASE_ID);
      if (useCase == null) {
        throw new PrinterException(
            "No useCaseID could be found. A usecase for the type "
                + registryItemID.reportRegistryItemType
                + " could not be found and also the default/fallback usecase seems not to be registered."); //$NON-NLS-1$ //$NON-NLS-2$
      }
      useCaseID = useCase.getId();
    }

    RenderReportRequest renderRequest = new RenderReportRequest();
    renderRequest.setReportRegistryItemID(registryItemID);
    renderRequest.setParameters(params);
    Locale requestLocale =
        getRenderRequestLocale(registryItemID, params, new SubProgressMonitor(monitor, 1));
    if (requestLocale != null) {
      renderRequest.setLocale(requestLocale);
    } else {
      renderRequest.setLocale(Locale.getDefault());
    }
    PrintReportLayoutUtil.printReportLayoutWithDefaultFormat(
        renderRequest, useCaseID, new SubProgressMonitor(monitor, 5));
    monitor.done();
  }