예제 #1
0
  /**
   * Evaluates the page
   *
   * <p>This checks whether the current settings on the page make any sense. If everything is fine,
   * the settings are being put into the appropriate data container {@link ImportWizardModel} and
   * the current page is marked as complete by invoking {@link #setPageComplete(boolean)}. Otherwise
   * an error message is set, which will make sure the user is informed about the reason for the
   * error.
   */
  private void evaluatePage() {

    setPageComplete(false);
    setErrorMessage(null);
    tablePreview.setVisible(false);

    if (comboLocation.getText().equals("")) { // $NON-NLS-1$
      return;
    }

    try {
      if (!customLinebreak) {
        detectLinebreak();
        comboLinebreak.select(selectedLinebreak);
      }
      if (!customDelimiter) {
        detectDelimiter();
        comboDelimiter.select(selectedDelimiter);
      }
      readPreview();

    } catch (IOException | IllegalArgumentException e) {
      setErrorMessage(e.getMessage());
      return;
    } catch (TextParsingException e) {
      setErrorMessage(Resources.getMessage("ImportWizardPageCSV.16")); // $NON-NLS-1$
      return;
    } catch (RuntimeException e) {
      if (e.getCause() != null) {
        setErrorMessage(e.getCause().getMessage());
      } else {
        setErrorMessage(e.getMessage());
      }
      return;
    }

    /* Put data into container */
    ImportWizardModel data = wizardImport.getData();

    data.setWizardColumns(wizardColumns);
    data.setPreviewData(previewData);
    data.setFirstRowContainsHeader(btnContainsHeader.getSelection());
    data.setFileLocation(comboLocation.getText());
    data.setCsvDelimiter(delimiters[selectedDelimiter]);
    data.setCsvQuote(quotes[selectedQuote]);
    data.setCsvEscape(escapes[selectedEscape]);
    data.setCharset(
        Charsets.getCharsetForName(Charsets.getNamesOfAvailableCharsets()[selectedCharset]));
    data.setCsvLinebreak(
        CSVSyntax.getLinebreakForLabel(CSVSyntax.getAvailableLinebreaks()[selectedLinebreak]));

    /* Mark page as completed */
    setPageComplete(true);
  }
예제 #2
0
 /**
  * Cancel pressed.
  *
  * @return
  */
 @Override
 public boolean performCancel() {
   try {
     if (data.getJdbcConnection() != null && !data.getJdbcConnection().isClosed()) {
       data.getJdbcConnection().close();
     }
   } catch (Exception e) {
     /* Die silently */
   }
   return true;
 }
예제 #3
0
  /**
   * Handles the correct ordering of wizard pages
   *
   * <p>This method makes sure that the correct page is shown once the user hits the "next" button.
   * The page flow depends <code>currentPage</code> and the selected {@link
   * ImportWizardModel#getSourceType() sourceType}.
   *
   * @param currentPage The page that is currently being shown
   * @return The page that will be shown next
   */
  @Override
  public IWizardPage getNextPage(IWizardPage currentPage) {

    this.currentPage = currentPage;
    if (currentPage == sourcePage) {
      SourceType src = data.getSourceType();
      if (src == SourceType.CSV) {
        return csvPage;
      } else if (src == SourceType.JDBC) {
        return jdbcPage;
      } else if (src == SourceType.EXCEL) {
        return xlsPage;
      }
    } else if (currentPage == csvPage) {
      return columnPage;
    } else if (currentPage == columnPage) {
      return previewPage;
    } else if (currentPage == jdbcPage) {
      return tablePage;
    } else if (currentPage == tablePage) {
      return columnPage;
    } else if (currentPage == xlsPage) {
      return columnPage;
    }

    return null;
  }
예제 #4
0
  /**
   * Gets executed once the wizard is about to finish
   *
   * <p>This will build an appropriate {@link ImportConfiguration} object, depending upon the {@link
   * ImportWizardModel#getSourceType() source type} and the choices the user made during the process
   * of the wizard.
   *
   * <p>{@link #configuration} will hold a reference of the object. This can be retrieved later on
   * by {@link #getResultingConfiguration()}.
   *
   * @return
   * @see {@link #getResultingConfiguration()}
   */
  @Override
  public boolean performFinish() {

    if (data.getSourceType() == SourceType.CSV) {

      configuration =
          new ImportConfigurationCSV(
              data.getFileLocation(),
              data.getCharset(),
              data.getCsvDelimiter(),
              data.getCsvQuote(),
              data.getCsvEscape(),
              data.getCsvLinebreak(),
              data.getFirstRowContainsHeader());

    } else if (data.getSourceType() == SourceType.EXCEL) {

      configuration =
          new ImportConfigurationExcel(
              data.getFileLocation(), data.getExcelSheetIndex(), data.getFirstRowContainsHeader());

    } else if (data.getSourceType() == SourceType.JDBC) {

      configuration =
          new ImportConfigurationJDBC(data.getJdbcConnection(), data.getSelectedJdbcTable());

    } else {
      throw new RuntimeException("Configuration type not supported"); // $NON-NLS-1$
    }

    for (ImportColumn c : data.getEnabledColumns()) {
      c.setCleansing(data.isPerformCleansing());
      configuration.addColumn(c);
    }

    if (data.getSourceType() != SourceType.JDBC) {
      try {
        if (data.getJdbcConnection() != null && !data.getJdbcConnection().isClosed()) {
          data.getJdbcConnection().close();
        }
      } catch (Exception e) {
        /* Die silently */
      }
    }

    return true;
  }