Exemplo n.º 1
0
 public void selectOutputFile() {
   FileDialog dlg = new FileDialog(getParentShell(), SWT.SAVE);
   ArrayList<String> extensionList = new ArrayList<String>();
   if (chosenOutputFormat != null && chosenOutputFormat.getFileSuffix() != null) {
     extensionList.add("*." + chosenOutputFormat.getFileSuffix()); // $NON-NLS-1$
   }
   extensionList.add("*.*"); // $NON-NLS-1$
   dlg.setFilterExtensions(extensionList.toArray(new String[extensionList.size()]));
   dlg.setFileName(getDefaultOutputFilename());
   dlg.setOverwrite(true);
   String path;
   if (isFilePath()) {
     path = getOldFolderPath();
   } else {
     path = defaultFolder;
   }
   if (LOG.isDebugEnabled()) {
     LOG.debug("File dialog path set to: " + path); // $NON-NLS-1$
   }
   dlg.setFilterPath(path);
   String fn = dlg.open();
   if (fn != null) {
     textFile.setText(fn);
     getButton(IDialogConstants.OK_ID).setEnabled(true);
   }
 }
  @Override
  protected void okPressed() {
    if (textFile.getText().length() == 0 || scopeCombo.getSelectionIndex() < 0) {
      MessageDialog.openWarning(
          getShell(), Messages.GenerateReportDialog_5, Messages.GenerateReportDialog_6);
      return;
    }
    List<Integer> rootElements = new ArrayList<Integer>(0);
    rootElements.add(getRootElement());
    if (getRootElements() != null) rootElements.addAll(Arrays.asList(getRootElements()));
    IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore();
    boolean dontShow =
        preferenceStore.getBoolean(PreferenceConstants.SHOW_REPORT_VALIDATION_WARNING);
    IValidationService vService = ServiceFactory.lookupValidationService();
    boolean validationsExistant = false;
    for (Integer scopeId : rootElements) {
      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();
    chosenReportType = reportTypes[comboReportType.getSelectionIndex()];
    chosenOutputFormat = chosenReportType.getOutputFormats()[comboOutputFormat.getSelectionIndex()];

    chosenReportType.setReportFile(textReportTemplateFile.getText());

    // 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$
    }

    outputFile = new File(f);
    resetScopeCombo();
    super.okPressed();
  }
 private void setupComboOutputFormatContent() {
   comboOutputFormat.removeAll();
   for (IOutputFormat of : reportTypes[comboReportType.getSelectionIndex()].getOutputFormats()) {
     comboOutputFormat.add(of.getLabel());
   }
   ;
   comboOutputFormat.select(0);
   if (chosenReportType != null) {
     chosenOutputFormat =
         chosenReportType.getOutputFormats()[comboOutputFormat.getSelectionIndex()];
   }
 }
 protected void setupOutputFilepath() {
   String currentPath = textFile.getText();
   String path = currentPath;
   if (currentPath != null && !currentPath.isEmpty() && chosenOutputFormat != null) {
     int lastDot = currentPath.lastIndexOf('.');
     if (lastDot != -1) {
       path = currentPath.substring(0, lastDot + 1) + chosenOutputFormat.getFileSuffix();
     } else {
       path = currentPath + chosenOutputFormat.getFileSuffix();
     }
   }
   if (!currentPath.equals(path)) {
     textFile.setText(path);
   }
 }
 protected String getDefaultOutputFilename() {
   String outputFileName = chosenReportType.getReportFile();
   if (outputFileName == null || outputFileName.equals("")) {
     outputFileName = "unknown";
   }
   StringBuilder sb = new StringBuilder(outputFileName);
   if (chosenOutputFormat != null) {
     sb.append(".").append(chosenOutputFormat.getFileSuffix());
   }
   return sb.toString();
 }
Exemplo n.º 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;
   }
 }
Exemplo n.º 7
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());
 }
Exemplo n.º 8
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();
  }