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

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import nl.mpi.arbil.ui.ArbilWindowManager;
import nl.mpi.kinnate.entityindexer.CollectionExport;
import nl.mpi.kinnate.entityindexer.QueryException;
import nl.mpi.kinnate.plugins.export.GedcomExport;

/**
 * Document : ExportPanel
 * Created on : Jul 18, 2012, 5:37:51 PM
 * Author : <NAME>
 */
public class ExportPanel extends JPanel implements ActionListener {

    ArbilWindowManager arbilWindowManager;
    GedcomExport gedcomExport;
    FieldsPanel fieldsPanel;
    JTabbedPane outerTabbedPane;

    public ExportPanel(ArbilWindowManager arbilWindowManager, GedcomExport gedcomExport, JTabbedPane jTabbedPane) {
        this.arbilWindowManager = arbilWindowManager;
        this.gedcomExport = gedcomExport;
        this.outerTabbedPane = jTabbedPane;
        fieldsPanel = new FieldsPanel(gedcomExport);
        fieldsPanel.populateFields();
        this.setLayout(new BorderLayout());
        this.add(fieldsPanel, BorderLayout.CENTER);
        JButton exportButton = new JButton("Export");
        exportButton.addActionListener(this);
        this.add(exportButton, BorderLayout.PAGE_END);
    }

    public void actionPerformed(ActionEvent e) {
        try {
            if (fieldsPanel.namesAreUnique()) {
                final String queryString = gedcomExport.generateExport(fieldsPanel.getSelectedFieldNames(), fieldsPanel.getSelectedFieldPaths());
                SwingUtilities.invokeLater(new Thread() {

                    @Override
                    public void run() {


//                        jProgressBar.setIndeterminate(true);
//                resultsText.setVisible(true);
//                resultsText.setText("");
                        try {
                            long startTime = System.currentTimeMillis();
                            String resultsString = gedcomExport.generateExport(queryString);
                            long queryMils = System.currentTimeMillis() - startTime;
                            String queryTimeString = "Query time: " + queryMils + "ms";
//                    queryTimeLabel.setText(queryTimeString);
//                            ExportPanel.this.removeAll();
                            final ResultsPanel resultsPanel = new ResultsPanel();
//                        ExportPanel.this.add(new JScrollPane(new JTextArea(csvText)), BorderLayout.CENTER);
//                            ExportPanel.this.add(resultsPanel, BorderLayout.CENTER);
                            outerTabbedPane.add("Results Text", new JScrollPane(new JTextArea(resultsString)));
                            outerTabbedPane.add("Results Table", resultsPanel);
                            resultsPanel.updateTable(resultsString); // "\"a\",\"b\",\"c\"\n\",\"1\",\"2\",\"3\"");
                            ExportPanel.this.revalidate();
                            ExportPanel.this.repaint();

                        } catch (QueryException exception) {
//                    resultsText.append("Error: " + exception.getMessage() + "\n");
                            arbilWindowManager.addMessageDialogToQueue(exception.getMessage(), "Generate Table");
                        }
//                jProgressBar.setIndeterminate(false);
//                runQueryButton.setEnabled(gedcomExport.databaseReady());
                    }
                });
            } else {
                arbilWindowManager.addMessageDialogToQueue("The chosen field names are not unique", "Export Error");
            }
        } catch (QueryException exception) {
            arbilWindowManager.addMessageDialogToQueue(exception.getMessage(), "Export Error");
        }
    }

    static public void main(String[] args) {
        JFrame jFrame = new JFrame("Fields Panel Test");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final ArbilWindowManager arbilWindowManager = new ArbilWindowManager();
//        final KinSessionStorage kinSessionStorage = new KinSessionStorage(new ApplicationVersionManager(new KinOathVersion()));
//        arbilWindowManager.setSessionStorage(kinSessionStorage);
        final CollectionExport entityCollection = new CollectionExport();
        final GedcomExport gedcomExport = new GedcomExport(entityCollection);
        JTabbedPane jTabbedPane = new JTabbedPane();
        ExportPanel exportPanel = new ExportPanel(arbilWindowManager, gedcomExport, jTabbedPane);
        jTabbedPane.add("Import", exportPanel);
        jFrame.setContentPane(jTabbedPane);
        jFrame.pack();
        jFrame.setVisible(true);
    }
}
<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 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import nl.mpi.arbil.ui.ArbilWindowManager;
import nl.mpi.kinnate.entityindexer.CollectionExport;
import nl.mpi.kinnate.entityindexer.QueryException;
import nl.mpi.kinnate.plugins.export.GedcomExport;

/**
 * Document : ExportPanel
 * Created on : Jul 18, 2012, 5:37:51 PM
 * Author : <NAME>
 */
public class ExportPanel extends JPanel implements ActionListener {

    ArbilWindowManager arbilWindowManager;
    GedcomExport gedcomExport;
    FieldsPanel fieldsPanel;
    JTabbedPane outerTabbedPane;

    public ExportPanel(ArbilWindowManager arbilWindowManager, GedcomExport gedcomExport, JTabbedPane jTabbedPane) {
        this.arbilWindowManager = arbilWindowManager;
        this.gedcomExport = gedcomExport;
        this.outerTabbedPane = jTabbedPane;
        fieldsPanel = new FieldsPanel(gedcomExport);
        fieldsPanel.populateFields();
        this.setLayout(new BorderLayout());
        this.add(fieldsPanel, BorderLayout.CENTER);
        JButton exportButton = new JButton("Export");
        exportButton.addActionListener(this);
        this.add(exportButton, BorderLayout.PAGE_END);
    }

    public void actionPerformed(ActionEvent e) {
        try {
            if (fieldsPanel.namesAreUnique()) {
                final String queryString = gedcomExport.generateExport(fieldsPanel.getSelectedFieldNames(), fieldsPanel.getSelectedFieldPaths());
                outerTabbedPane.add("Query Text", new JScrollPane(new JTextArea(queryString)));
                SwingUtilities.invokeLater(new Thread() {

                    @Override
                    public void run() {


//                        jProgressBar.setIndeterminate(true);
//                resultsText.setVisible(true);
//                resultsText.setText("");
                        try {
                            long startTime = System.currentTimeMillis();
                            String resultsString = gedcomExport.generateExport(queryString);
                            long queryMils = System.currentTimeMillis() - startTime;
                            String queryTimeString = "Query time: " + queryMils + "ms";
//                    queryTimeLabel.setText(queryTimeString);
//                            ExportPanel.this.removeAll();
                            final ResultsPanel resultsPanel = new ResultsPanel();
//                        ExportPanel.this.add(new JScrollPane(new JTextArea(csvText)), BorderLayout.CENTER);
//                            ExportPanel.this.add(resultsPanel, BorderLayout.CENTER);
                            outerTabbedPane.add("Results Text", new JScrollPane(new JTextArea(resultsString)));
                            outerTabbedPane.add("Results Table", resultsPanel);
                            resultsPanel.updateTable(resultsString); // "\"a\",\"b\",\"c\"\n\",\"1\",\"2\",\"3\"");
                            ExportPanel.this.revalidate();
                            ExportPanel.this.repaint();

                        } catch (QueryException exception) {
//                    resultsText.append("Error: " + exception.getMessage() + "\n");
                            arbilWindowManager.addMessageDialogToQueue(exception.getMessage(), "Generate Table");
                        }
//                jProgressBar.setIndeterminate(false);
//                runQueryButton.setEnabled(gedcomExport.databaseReady());
                    }
                });
            } else {
                arbilWindowManager.addMessageDialogToQueue("The chosen field names are not unique", "Export Error");
            }
        } catch (QueryException exception) {
            arbilWindowManager.addMessageDialogToQueue(exception.getMessage(), "Export Error");
        }
    }

    static public void main(String[] args) {
        JFrame jFrame = new JFrame("Fields Panel Test");
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final ArbilWindowManager arbilWindowManager = new ArbilWindowManager();
//        final KinSessionStorage kinSessionStorage = new KinSessionStorage(new ApplicationVersionManager(new KinOathVersion()));
//        arbilWindowManager.setSessionStorage(kinSessionStorage);
        final CollectionExport entityCollection = new CollectionExport();
        final GedcomExport gedcomExport = new GedcomExport(entityCollection);
        JTabbedPane jTabbedPane = new JTabbedPane();
        ExportPanel exportPanel = new ExportPanel(arbilWindowManager, gedcomExport, jTabbedPane);
        jTabbedPane.add("Import", exportPanel);
        jFrame.setContentPane(jTabbedPane);
        jFrame.pack();
        jFrame.setVisible(true);
    }
}

{'fraction_non_alphanumeric': 0.09559114274416766, 'fraction_numerical': 0.0031633056544088573, 'mean_word_length': 2.4179054054054054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5015089', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2547, 'n_words': 495}