<commit_before>package nl.mpi.kinnate.plugins.export.ui;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

/**
 * Document : ResultsPanel
 * Created on : Jul 19, 2012, 12:00:44 PM
 * Author : <NAME>
 */
public class ResultsPanel extends JPanel {

    JTable resultsTable;
    String[] resultsHeader = null;
    String[][] tableData = null;
    AbstractTableModel resultsModel = new AbstractTableModel() {

        @Override
        public String getColumnName(int column) {
            if (resultsHeader == null) {
                return "";
            }
            return resultsHeader[column];
        }

        public int getRowCount() {
            if (tableData == null) {
                return 0;
            }
            return tableData.length;
        }

        public int getColumnCount() {
            if (tableData == null || tableData.length == 0) {
                return 0;
            }
            return resultsHeader.length;
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
//            System.out.println(rowIndex + " : " + columnIndex);
            if (columnIndex < tableData[rowIndex].length) {
                return tableData[rowIndex][columnIndex];
            } else {
                return "<error>";
            }
        }
    };

    public ResultsPanel() {
        this.setLayout(new BorderLayout());
        resultsTable = new JTable(resultsModel);
        this.add(new JScrollPane(resultsTable), BorderLayout.CENTER);
    }

    public void updateTable(String resultsString) {
        String[] resultsRows = resultsString.split("\n");
        if (resultsRows.length > 0) {
            final String fieldSeparator = "\",\"";
//            final String fieldSeparator = ",";
            resultsHeader = resultsRows[0].split(fieldSeparator);
            tableData = new String[resultsRows.length - 1][resultsHeader.length];
//            tableData[0] = resultsHeader;
            boolean allRowsCorrectLength = true;
            for (int rowCounter = 1; rowCounter < resultsRows.length - 1; rowCounter++) {
                tableData[rowCounter] = resultsRows[rowCounter].split(fieldSeparator);
                if (resultsHeader.length != tableData[rowCounter].length) {
                    allRowsCorrectLength = false;
                }
            }
            if (allRowsCorrectLength) {
                // todo: show error message
            }
        } else {
            tableData = new String[0][0];
        }
        resultsModel.fireTableStructureChanged();
    }
}
<commit_msg>Added a query to retrieve all valid xpaths in the database (Arbil or KinOath) for which a value can be exported. Added panel for user to enter preferred CSV column names for each field. Added simple CSV import into the database. refs #2097<commit_after>package nl.mpi.kinnate.plugins.export.ui;

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

/**
 * Document : ResultsPanel
 * Created on : Jul 19, 2012, 12:00:44 PM
 * Author : <NAME>
 */
public class ResultsPanel extends JPanel {

    JTable resultsTable;
    String[] resultsHeader = null;
    String[][] tableData = null;
    AbstractTableModel resultsModel = new AbstractTableModel() {

        @Override
        public String getColumnName(int column) {
            if (resultsHeader == null) {
                return "";
            }
            return resultsHeader[column];
        }

        public int getRowCount() {
            if (tableData == null) {
                return 0;
            }
            return tableData.length;
        }

        public int getColumnCount() {
            if (tableData == null || tableData.length == 0) {
                return 0;
            }
            return resultsHeader.length;
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
//            System.out.println(rowIndex + " : " + columnIndex);
            if (columnIndex < tableData[rowIndex].length) {
                return tableData[rowIndex][columnIndex];
            } else {
                return "<error>";
            }
        }
    };

    public ResultsPanel() {
        this.setLayout(new BorderLayout());
        resultsTable = new JTable(resultsModel);
        this.add(new JScrollPane(resultsTable), BorderLayout.CENTER);
    }

    public void updateTable(String resultsString) {
        resultsString = resultsString.replaceAll("^\"", "");
        resultsString = resultsString.replaceAll("\"$", "");
        // include the quotes in the line separator so that line breaks in the data are ignored (not entirely reliable, but this is only a sample output)
        String[] resultsRows = resultsString.split("\"\\n\"");
        if (resultsRows.length > 0) {
            final String fieldSeparator = "\",\"";
//            final String fieldSeparator = ",";
            resultsHeader = resultsRows[0].split(fieldSeparator);
            tableData = new String[resultsRows.length - 1][resultsHeader.length];
//            tableData[0] = resultsHeader;
            boolean allRowsCorrectLength = true;
            for (int rowCounter = 1; rowCounter < resultsRows.length - 1; rowCounter++) {
                // add start and end quites so that the column count is correct 
                tableData[rowCounter] = ("\"" + resultsRows[rowCounter] + "\"").split(fieldSeparator);
                // trim the last and first quote 
                tableData[rowCounter][0] = tableData[rowCounter][0].replaceAll("^\"", "");
                tableData[rowCounter][tableData[rowCounter].length - 1] = tableData[rowCounter][tableData[rowCounter].length - 1].replaceAll("\"$", "");

                if (resultsHeader.length != tableData[rowCounter].length) {
                    allRowsCorrectLength = false;
                }
            }
            if (allRowsCorrectLength) {
                // todo: show error message
            }
        } else {
            tableData = new String[0][0];
        }
        resultsModel.fireTableStructureChanged();
    }
}

{'fraction_non_alphanumeric': 0.10710277376944044, 'fraction_numerical': 0.008658008658008658, 'mean_word_length': 2.0179003386550556, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5110230', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1574, 'n_words': 401}