@Override
 public String getColumnText(Object element, int columnIndex) {
   try {
     if (element instanceof PlaceHolder) {
       if (columnIndex == 1) {
         PlaceHolder ph = (PlaceHolder) element;
         return ph.getTitle();
       }
       return ""; //$NON-NLS-1$
     }
     ReportTemplateMetaData data = (ReportTemplateMetaData) element;
     switch (columnIndex) {
       case 0:
         return data.getOutputname(); // $NON-NLS-1$
       case 1:
         StringBuilder sb = new StringBuilder();
         OutputFormat[] formats = data.getOutputFormats();
         for (int i = 0; i < formats.length; i++) {
           sb.append(formats[i]);
           if (!(i == formats.length - 1)) {
             sb.append(", ");
           }
         }
         return sb.toString(); // $NON-NLS-1$
       case 2:
         return data.getFilename(); // $NON-NLS-1$
       default:
         return null;
     }
   } catch (Exception e) {
     LOG.error("Error while getting column text", e); // $NON-NLS-1$
     throw new RuntimeException(e);
   }
 }
 private void deleteAttachments() {
   Iterator iterator = ((IStructuredSelection) viewer.getSelection()).iterator();
   while (iterator.hasNext()) {
     ReportTemplateMetaData sel = (ReportTemplateMetaData) iterator.next();
     try {
       ServiceFactory.lookupReportDepositService().remove(sel, Locale.getDefault().getLanguage());
     } catch (ReportDepositException e) {
       ExceptionUtil.log(e, "Error deleting Reporttemplate:\t" + sel.getOutputname());
     }
   }
 }
示例#3
0
  /**
   * adds decorators ( "(L)" or "(S)" ) as a prefix to the report names, sorts alphabetically:
   * (locally stored templates before server-sided templates) adds sorted name list to the
   * reportCombo
   *
   * @return sorted Array (for access later on)
   */
  @SuppressWarnings("unchecked")
  private ReportTemplateMetaData[] fillReportCombo() {

    Arrays.sort(
        reportTemplates,
        new Comparator() {
          @Override
          public int compare(Object template1, Object template2) {
            return comparator.compare(
                ((ReportTemplateMetaData) template1).getDecoratedOutputname(),
                ((ReportTemplateMetaData) template2).getDecoratedOutputname());
          }
        });

    for (ReportTemplateMetaData data : reportTemplates) {
      comboReportType.add(data.getDecoratedOutputname());
    }

    return reportTemplates;
  }
    /*
     * (non-Javadoc)
     *
     * @see
     * org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface
     * .viewers.Viewer, java.lang.Object, java.lang.Object)
     */
    @Override
    public int compare(Viewer viewer, Object e1, Object e2) {
      ReportTemplateMetaData data1 = (ReportTemplateMetaData) e1;
      ReportTemplateMetaData data2 = (ReportTemplateMetaData) e2;
      int rc = 0;
      if (e1 == null) {
        if (e2 != null) {
          rc = 1;
        }
      } else if (e2 == null) {
        rc = -1;
      } else {
        // e1 and e2 != null
        switch (propertyIndex) {
          case 0:
            rc = comporeToLowerCase(data1.getDecoratedOutputname(), data2.getDecoratedOutputname());
            break;
          case 1:
            // implement a sorted list here that needs to be compared
            String s1 = getSortedOutputFormatsString(data1.getOutputFormats());
            String s2 = getSortedOutputFormatsString(data2.getOutputFormats());
            if (s1 != null && s2 != null) {
              rc = s1.compareTo(s2);
            }
            break;
          case 2:
            rc = comporeToLowerCase(data1.getFilename(), data2.getFilename());
            break;
          default:
            rc = 0;
        }
      }

      // If descending order, flip the direction
      if (direction == DESCENDING) {
        rc = -rc;
      }
      return rc;
    }
示例#5
0
 protected String getDefaultOutputFilename() {
   String outputFileName = chosenReportMetaData.getOutputname();
   if (outputFileName == null || outputFileName.isEmpty()) {
     outputFileName = "unknown";
   }
   StringBuilder sb = new StringBuilder(outputFileName);
   String scopeName = convertToFileName(scopeCombo.getText());
   if (scopeName != null && !scopeName.isEmpty()) {
     sb.append("_").append(scopeName);
   }
   if (useDate) {
     String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
     sb.append("_").append(date);
   }
   if (chosenOutputFormat != null) {
     sb.append(".").append(chosenOutputFormat.getFileSuffix());
   } else {
     sb.append(".pdf");
   }
   return convertToFileName(sb.toString());
 }
示例#6
0
 private void setupComboOutputFormatContent() {
   comboOutputFormat.removeAll();
   if (reportTemplates.length > 0) {
     for (IOutputFormat of :
         getDepositService()
             .getOutputFormats(
                 reportTemplates[comboReportType.getSelectionIndex()].getOutputFormats())) {
       comboOutputFormat.add(of.getLabel());
     }
     comboOutputFormat.select(0);
     if (chosenReportMetaData != null) {
       chosenOutputFormat =
           getDepositService()
               .getOutputFormat(
                   chosenReportMetaData.getOutputFormats()[comboOutputFormat.getSelectionIndex()]);
     }
   } else {
     showNoReportsExistant();
     return;
   }
 }
示例#7
0
  @Override
  protected void okPressed() {
    try {
      if (textFile.getText().length() == 0 || scopeCombo.getSelectionIndex() < 0) {
        MessageDialog.openWarning(
            getShell(), Messages.GenerateReportDialog_5, Messages.GenerateReportDialog_6);
        return;
      }
      List<Integer> scopeIds = new ArrayList<Integer>(0);
      if (getRootElement() != null) {
        scopeIds.add(getRootElement());
      }
      if (getRootElements() != null) {
        for (Integer scopeId : getRootElements()) {
          if (scopeId != null) {
            scopeIds.add(scopeId);
          }
        }
      }
      IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
      boolean dontShow =
          preferenceStore.getBoolean(PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
      IValidationService vService = ServiceFactory.lookupValidationService();
      boolean validationsExistant = false;
      for (Integer scopeId : scopeIds) {
        if (vService.getValidations(scopeId, (Integer) null).size() > 0) {
          validationsExistant = true;
          break;
        }
      }

      if (!dontShow && validationsExistant) {
        MessageDialogWithToggle dialog =
            MessageDialogWithToggle.openYesNoQuestion(
                getParentShell(),
                Messages.GenerateReportDialog_5,
                Messages.GenerateReportDialog_21,
                Messages.GenerateReportDialog_23,
                dontShow,
                preferenceStore,
                PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
        preferenceStore.setValue(
            PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING, dialog.getToggleState());

        if (!(dialog.getReturnCode() == IDialogConstants.OK_ID
            || dialog.getReturnCode() == IDialogConstants.YES_ID)) {
          return;
        }
      }

      String f = textFile.getText();
      if (reportTemplates.length > 0) {
        chosenReportMetaData = reportTemplates[comboReportType.getSelectionIndex()];
      } else {
        showNoReportsExistant();
        return;
      }
      chosenOutputFormat =
          getDepositService()
              .getOutputFormat(
                  chosenReportMetaData.getOutputFormats()[comboOutputFormat.getSelectionIndex()]);

      // This just appends the chosen report's extension if the existing
      // suffix does not match. Could be enhanced.
      if (!f.endsWith(chosenOutputFormat.getFileSuffix())) {
        f += "." + chosenOutputFormat.getFileSuffix(); // $NON-NLS-1$
      }

      String currentPath = setupDirPath();
      if (useDefaultFolder) {
        Activator.getDefault()
            .getPreferenceStore()
            .setValue(PreferenceConstants.DEFAULT_FOLDER_REPORT, currentPath);
      }
      currentPath = getOldTemplateFolderPath();
      outputFile = new File(f);
    } catch (Exception e) {
      LOG.error("Error while creating report.", e);
      MessageDialog.openError(getShell(), "Error", "An error occurred while creating report.");
      return;
    }
    super.okPressed();
  }