Exemplo n.º 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();
  }
  private void loadProperties() {
    Job fillStateComboJob =
        new Job(
            Messages.getString(
                "org.nightlabs.jfire.trade.ui.overview.StatableFilterComposite.loadProcessDefinitionsJob.name")) { //$NON-NLS-1$
          @Override
          protected IStatus run(ProgressMonitor monitor) {
            try {
              JbpmManagerRemote jbpmManager =
                  JFireEjb3Factory.getRemoteBean(
                      JbpmManagerRemote.class, Login.getLogin().getInitialContextProperties());

              String[] FETCH_GROUPS_ISSUE_TYPE =
                  new String[] {
                    FetchPlan.DEFAULT,
                    IssueType.FETCH_GROUP_NAME,
                    IssueType.FETCH_GROUP_PROCESS_DEFINITION
                  };

              IssueTypeDAO issueTypeDAO = IssueTypeDAO.sharedInstance();
              Collection<IssueType> issueTypes =
                  issueTypeDAO.getAllIssueTypes(
                      FETCH_GROUPS_ISSUE_TYPE, NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT, monitor);

              String[] FETCH_GROUPS_STATE_DEFINITON =
                  new String[] {FetchPlan.DEFAULT, StateDefinition.FETCH_GROUP_NAME};

              for (IssueType issueType : issueTypes) {
                ProcessDefinition processDefinition = issueType.getProcessDefinition();
                Set<StateDefinitionID> statedDefinitionIDs =
                    jbpmManager.getStateDefinitionIDs(issueType.getProcessDefinition());
                Collection<StateDefinition> stateDefinitions =
                    StateDefinitionDAO.sharedInstance()
                        .getStateDefintions(
                            statedDefinitionIDs,
                            FETCH_GROUPS_STATE_DEFINITON,
                            NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT,
                            monitor);
                processDefinition2StateDefinitions.put(
                    processDefinition, new ArrayList<StateDefinition>(stateDefinitions));
              }

              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        public void run() {
                          if (processDefinitionsCombo == null
                              || processDefinitionsCombo.isDisposed()
                              || stateDefinitionsCombo == null
                              || stateDefinitionsCombo.isDisposed()) return;

                          Set<ProcessDefinition> processDefinitions =
                              processDefinition2StateDefinitions.keySet();
                          processDefinitionsCombo.addElement(ALL_PROCESS_DEFINITION);
                          processDefinitionsCombo.addElements(processDefinitions);
                          stateDefinitionsCombo.addElement(ALL_STATE_DEFINITION);

                          if (!processDefinitions.isEmpty()) {
                            ProcessDefinition firstProcessDefinition =
                                processDefinitions.iterator().next();
                            List<StateDefinition> stateDefinitionList =
                                processDefinition2StateDefinitions.get(firstProcessDefinition);
                            stateDefinitionsCombo.addElements(stateDefinitionList);
                            if (!stateDefinitionList.isEmpty()) {
                              stateDefinitionsCombo.selectElementByIndex(0);
                            }
                          }
                          processDefinitionsCombo.selectElementByIndex(0);

                          if (selectedProcessDefinition != null) {
                            processDefinitionsCombo.setSelection(selectedProcessDefinition);
                            selectedProcessDefinition = null;
                          }

                          if (selectedStateDefinition != null) {
                            stateDefinitionsCombo.setSelection(selectedStateDefinition);
                            selectedStateDefinition = null;
                          }
                        }
                      });
            } catch (Exception e) {
              ExceptionHandlerRegistry.asyncHandleException(e);
              throw new RuntimeException(e);
            }
            return Status.OK_STATUS;
          }
        };
    fillStateComboJob.schedule();
  }
Exemplo n.º 3
0
  @Override
  public void refresh() {
    Job loadCustomersJob =
        new Job(
            Messages.getString(
                "org.nightlabs.jfire.trade.dashboard.ui.internal.lastCustomers.DashboardGadgetLastCustomers.loadCustomers.job.name")) { //$NON-NLS-1$
          @Override
          protected IStatus run(ProgressMonitor monitor) {
            monitor.beginTask(
                Messages.getString(
                    "org.nightlabs.jfire.trade.dashboard.ui.internal.lastCustomers.DashboardGadgetLastCustomers.loadCustomers.task.name"),
                100); //$NON-NLS-1$
            try {
              if (!transactionInfoTable.isDisposed()) {
                transactionInfoTable
                    .getDisplay()
                    .syncExec(
                        new Runnable() {
                          public void run() {
                            transactionInfoTable.setLoadingMessage(
                                Messages.getString(
                                    "org.nightlabs.jfire.trade.dashboard.ui.internal.lastCustomers.DashboardGadgetLastCustomers.loadCustomers.message")); //$NON-NLS-1$
                          }
                        });
              }
              DashboardManagerRemote dashboardManager =
                  GlobalJFireEjb3Provider.sharedInstance()
                      .getRemoteBean(DashboardManagerRemote.class);
              List<LastCustomerTransaction> lastCustomers =
                  dashboardManager.searchLastCustomerTransactions(
                      (DashboardGadgetLastCustomersConfig)
                          getGadgetContainer().getLayoutEntry().getConfig());
              monitor.worked(50);

              Map<AnchorID, LegalEntity> anchorIDToLegalEntity =
                  new HashMap<AnchorID, LegalEntity>();
              for (LastCustomerTransaction trans : lastCustomers)
                anchorIDToLegalEntity.put(trans.getCustomerID(), null);

              Collection<LegalEntity> legalEntities =
                  LegalEntityDAO.sharedInstance()
                      .getLegalEntities(
                          anchorIDToLegalEntity.keySet(),
                          new String[] {
                            FetchPlan.DEFAULT,
                            LegalEntity.FETCH_GROUP_PERSON,
                            PropertySet.FETCH_GROUP_FULL_DATA
                          },
                          NLJDOHelper.MAX_FETCH_DEPTH_NO_LIMIT,
                          new SubProgressMonitor(monitor, 50));

              for (LegalEntity legalEntity : legalEntities) {
                anchorIDToLegalEntity.put(
                    (AnchorID) JDOHelper.getObjectId(legalEntity), legalEntity);
              }

              final List<TransactionInfoTableItem> customerTransactions =
                  new LinkedList<TransactionInfoTableItem>();

              for (LastCustomerTransaction lastCustomerTransaction : lastCustomers) {
                TransactionInfoTableItem customerTransaction = new TransactionInfoTableItem();
                customerTransaction.setTransactionInfo(lastCustomerTransaction);
                customerTransaction.setLegalEntityName(
                    getLegalEntityName(
                        anchorIDToLegalEntity.get(lastCustomerTransaction.getCustomerID())));
                customerTransactions.add(customerTransaction);
              }

              if (!transactionInfoTable.isDisposed()) {
                transactionInfoTable
                    .getDisplay()
                    .syncExec(
                        new Runnable() {
                          public void run() {
                            if (!transactionInfoTable.isDisposed()) {
                              transactionInfoTable.setInput(customerTransactions);
                            }
                          }
                        });
              }

            } finally {
              monitor.done();
            }

            return Status.OK_STATUS;
          }

          private String getLegalEntityName(LegalEntity legalEntity) {
            String displayName = legalEntity.getPerson().getDisplayName();
            if (displayName == null || displayName.equals("")) { // $NON-NLS-1$
              IStruct structure = legalEntity.getPerson().getStructure();
              displayName = structure.createDisplayName(legalEntity.getPerson());
            }
            return displayName;
          }
        };

    loadCustomersJob.schedule();
  }