@Override
  protected boolean performLeavingAction(WizardStepDirection direction) {
    if (direction == WizardStepDirection.FINISH) {
      try {
        if (state.getTranslator() != null) {
          state.getTranslator().close();
        }
      } catch (OperatorException e) {
        ImportWizardUtils.showErrorMessage(
            state.getDataResultSetFactory().getResourceName(), e.toString(), e);
      }

      // use settings edited by user even if he never pressed Enter or otherwise confirmed his
      // changes
      for (int i = 0; i < previewTable.getColumnCount(); i++) {
        EditableTableHeaderColumn col =
            (EditableTableHeaderColumn) previewTable.getColumnModel().getColumn(i);
        if (col.getHeaderEditor() instanceof MetaDataTableHeaderCellEditor) {
          MetaDataTableHeaderCellEditor editor =
              (MetaDataTableHeaderCellEditor) col.getHeaderEditor();
          editor.updateColumnMetaData();
        }
      }
    }
    return true;
  }
  public void updateErrors() {
    final List<ParsingError> errorList = new ArrayList<ParsingError>();

    canProceed = true;
    if (headerValidator.getErrors().size() > 0) {
      List<ParsingError> headerErrors = headerValidator.getErrors();
      errorList.addAll(headerErrors);
      canProceed = false;
    }
    errorList.addAll(state.getTranslator().getErrors());
    SwingUtilities.invokeLater(
        new Runnable() {

          @Override
          public void run() {

            final int size = errorList.size();
            errorLabel.setText(size + " errors.");
            if (size == 0) {
              errorLabel.setIcon(SwingTools.createIcon("16/ok.png"));
            } else {
              errorLabel.setIcon(SwingTools.createIcon("16/error.png"));
            }
          }
        });
    errorTableModel.setErrors(errorList);
    fireStateChanged();
  }
  private void updateTableModel(ExampleSet exampleSet) {
    if (previewTable == null) {
      previewTable = new ExtendedJTable(false, false, false);
    }

    // data model
    DataTableViewerTableModel model =
        new DataTableViewerTableModel(new DataTableExampleSetAdapter(exampleSet, null));
    List<Integer> rowsList = new LinkedList<Integer>();
    int lastHit = -1;
    for (ParsingError error : state.getTranslator().getErrors()) {
      if (error.getExampleIndex() != lastHit) {
        rowsList.add(error.getExampleIndex());
        lastHit = error.getExampleIndex();
      }
    }
    int[] rowMap = new int[rowsList.size()];
    int j = 0;
    for (Integer row : rowsList) {
      rowMap[j++] = row;
    }
    filteredModel = new RowFilteringTableModel(model, rowMap, filterErrorsBox.isSelected());
    previewTable.setModel(filteredModel);

    // Header model

    TableColumnModel columnModel = previewTable.getColumnModel();
    previewTable.setTableHeader(new EditableTableHeader(columnModel));
    // header editors and renderers and values
    MetaDataTableHeaderCellEditor headerRenderer = new MetaDataTableHeaderCellEditor();
    MetaDataTableHeaderCellEditor headerEditor = new MetaDataTableHeaderCellEditor(headerValidator);
    headerValidator.addHeaderRenderer(headerRenderer);
    for (int i = 0; i < previewTable.getColumnCount(); i++) {
      EditableTableHeaderColumn col =
          (EditableTableHeaderColumn) previewTable.getColumnModel().getColumn(i);
      col.setHeaderValue(state.getTranslationConfiguration().getColumnMetaData()[i]);
      col.setHeaderRenderer(headerRenderer);
      col.setHeaderEditor(headerEditor);
    }
    previewTable.getTableHeader().setReorderingAllowed(false);

    previewTable.setCellColorProvider(
        new CellColorProviderAlternating() {

          @Override
          public Color getCellColor(int row, int column) {
            row = filteredModel.translateRow(row);
            ParsingError error = state.getTranslator().getErrorByExampleIndexAndColumn(row, column);
            if (error != null) {
              return SwingTools.DARK_YELLOW;
            } else {
              return super.getCellColor(row, column);
            }
          }
        });
    tableScrollPane.setViewportView(previewTable);
  }
 private void cancelGuessing() {
   state.getTranslator().cancelGuessing();
   state.getTranslator().cancelLoading();
   guessButton.setEnabled(false);
 }
 private void cancelReload() {
   state.getTranslator().cancelLoading();
   reloadButton.setEnabled(false);
 }