Exemplo n.º 1
0
 @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);
   }
 }
Exemplo n.º 2
0
    /*
     * (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;
    }
Exemplo n.º 3
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.º 4
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();
  }