<commit_before>/*
 * EDACCExperimentModeImport.java
 *
 * Created on 28.05.2011, 13:58:10
 */
package edacc;

import edacc.experiment.ExperimentTableModel;
import edacc.experiment.InstanceTableModel;
import edacc.experiment.SolverConfigurationTableModel;
import edacc.experiment.Util;
import edacc.model.Experiment;
import edacc.model.ExperimentDAO;
import edacc.model.Instance;
import edacc.model.InstanceDAO;
import edacc.model.SolverConfiguration;
import edacc.model.SolverConfigurationDAO;
import edacc.model.TaskRunnable;
import edacc.model.Tasks;
import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author simon
 */
public class EDACCExperimentModeImport extends javax.swing.JDialog {

    private ExperimentTableModel expTableModel;
    private SolverConfigurationTableModel solverConfigTableModel;
    private InstanceTableModel instanceTableModel;
    private HashMap<Integer, ArrayList<Instance>> instances;
    private HashMap<Integer, ArrayList<SolverConfiguration>> solverConfigs;
    private Experiment experiment;
    private HashSet<Integer> instanceIds;
    private HashSet<Integer> solverConfigIds;
    private TableCellRenderer defaultBooleanCellRenderer;
    private boolean cancelled;
    private ArrayList<SolverConfiguration> selectedSolverConfigs;
    private ArrayList<Instance> selectedInstances;
    private boolean importFinishedRuns;

    /** Creates new form EDACCExperimentModeImport */
    public EDACCExperimentModeImport(java.awt.Frame parent, boolean modal, Experiment experiment) {
        super(parent, modal);
        initComponents();
        cancelled = true;
        this.experiment = experiment;

        expTableModel = new ExperimentTableModel(true);
        solverConfigTableModel = new SolverConfigurationTableModel();
        instanceTableModel = new InstanceTableModel();

        tblExperiments.setModel(expTableModel);
        tblSolverConfigs.setModel(solverConfigTableModel);
        tblInstances.setModel(instanceTableModel);


        instances = new HashMap<Integer, ArrayList<Instance>>();
        solverConfigs = new HashMap<Integer, ArrayList<SolverConfiguration>>();

        instanceIds = new HashSet<Integer>();
        solverConfigIds = new HashSet<Integer>();

        defaultBooleanCellRenderer = tblExperiments.getDefaultRenderer(Boolean.class);

        tblExperiments.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                ArrayList<SolverConfiguration> scs = new ArrayList<SolverConfiguration>();
                ArrayList<Instance> inst = new ArrayList<Instance>();
                HashSet<Integer> instanceIds = new HashSet<Integer>();
                for (int viewRow : tblExperiments.getSelectedRows()) {
                    int row = tblExperiments.convertRowIndexToModel(viewRow);
                    Experiment exp = expTableModel.getExperimentAt(row);
                    ArrayList<SolverConfiguration> listScs = solverConfigs.get(exp.getId());
                    ArrayList<Instance> listInst = instances.get(exp.getId());
                    if (listScs != null) {
                        scs.addAll(listScs);
                    }
                    if (listInst != null) {
                        for (Instance i : listInst) {
                            if (!instanceIds.contains(i.getId())) {
                                inst.add(i);
                                instanceIds.add(i.getId());
                            }
                        }
                    }
                }
                solverConfigTableModel.setSolverConfigurations(scs);
                instanceTableModel.setInstances(inst, false, false);
                solverConfigTableModel.fireTableDataChanged();
                instanceTableModel.fireTableDataChanged();
            }
        });

        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c;
                if (value instanceof Boolean) {
                    c = defaultBooleanCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                } else {
                    c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
                boolean inExperiment = false;
                if (table == tblSolverConfigs) {
                    SolverConfiguration sc = solverConfigTableModel.getSolverConfigurationAt(tblSolverConfigs.convertRowIndexToModel(row));
                    if (solverConfigIds.contains(sc.getId())) {
                        inExperiment = true;
                    }
                } else if (table == tblInstances) {
                    Instance i = instanceTableModel.getInstanceAt(tblInstances.convertRowIndexToModel(row));
                    if (instanceIds.contains(i.getId())) {
                        inExperiment = true;
                    }
                }
                if (isSelected) {
                    c.setBackground(table.getSelectionBackground());
                } else {
                    if (inExperiment) {
                        c.setBackground(Color.orange);
                    } else {
                        c.setBackground(table.getBackground());
                    }
                }
                return c;
            }
        };

        tblInstances.setDefaultRenderer(String.class, renderer);
        tblInstances.setDefaultRenderer(Boolean.class, renderer);
        tblInstances.setDefaultRenderer(Integer.class, renderer);
        tblInstances.setDefaultRenderer(Float.class, renderer);
        tblInstances.setDefaultRenderer(Double.class, renderer);

        tblSolverConfigs.setDefaultRenderer(String.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Boolean.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Integer.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Float.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Double.class, renderer);
    }

    public void initializeData() {<commit_msg>experiment mode: space selection for tables in import dialog<commit_after>/*
 * EDACCExperimentModeImport.java
 *
 * Created on 28.05.2011, 13:58:10
 */
package edacc;

import edacc.experiment.ExperimentTableModel;
import edacc.experiment.InstanceTableModel;
import edacc.experiment.SolverConfigurationTableModel;
import edacc.experiment.Util;
import edacc.model.Experiment;
import edacc.model.ExperimentDAO;
import edacc.model.Instance;
import edacc.model.InstanceDAO;
import edacc.model.SolverConfiguration;
import edacc.model.SolverConfigurationDAO;
import edacc.model.TaskRunnable;
import edacc.model.Tasks;
import java.awt.Color;
import java.awt.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author simon
 */
public class EDACCExperimentModeImport extends javax.swing.JDialog {

    private ExperimentTableModel expTableModel;
    private SolverConfigurationTableModel solverConfigTableModel;
    private InstanceTableModel instanceTableModel;
    private HashMap<Integer, ArrayList<Instance>> instances;
    private HashMap<Integer, ArrayList<SolverConfiguration>> solverConfigs;
    private Experiment experiment;
    private HashSet<Integer> instanceIds;
    private HashSet<Integer> solverConfigIds;
    private TableCellRenderer defaultBooleanCellRenderer;
    private boolean cancelled;
    private ArrayList<SolverConfiguration> selectedSolverConfigs;
    private ArrayList<Instance> selectedInstances;
    private boolean importFinishedRuns;

    /** Creates new form EDACCExperimentModeImport */
    public EDACCExperimentModeImport(java.awt.Frame parent, boolean modal, Experiment experiment) {
        super(parent, modal);
        initComponents();
        cancelled = true;
        this.experiment = experiment;

        expTableModel = new ExperimentTableModel(true);
        solverConfigTableModel = new SolverConfigurationTableModel();
        instanceTableModel = new InstanceTableModel();

        tblExperiments.setModel(expTableModel);
        tblSolverConfigs.setModel(solverConfigTableModel);
        tblInstances.setModel(instanceTableModel);


        instances = new HashMap<Integer, ArrayList<Instance>>();
        solverConfigs = new HashMap<Integer, ArrayList<SolverConfiguration>>();

        instanceIds = new HashSet<Integer>();
        solverConfigIds = new HashSet<Integer>();

        defaultBooleanCellRenderer = tblExperiments.getDefaultRenderer(Boolean.class);

        tblExperiments.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(ListSelectionEvent e) {
                ArrayList<SolverConfiguration> scs = new ArrayList<SolverConfiguration>();
                ArrayList<Instance> inst = new ArrayList<Instance>();
                HashSet<Integer> instanceIds = new HashSet<Integer>();
                for (int viewRow : tblExperiments.getSelectedRows()) {
                    int row = tblExperiments.convertRowIndexToModel(viewRow);
                    Experiment exp = expTableModel.getExperimentAt(row);
                    ArrayList<SolverConfiguration> listScs = solverConfigs.get(exp.getId());
                    ArrayList<Instance> listInst = instances.get(exp.getId());
                    if (listScs != null) {
                        scs.addAll(listScs);
                    }
                    if (listInst != null) {
                        for (Instance i : listInst) {
                            if (!instanceIds.contains(i.getId())) {
                                inst.add(i);
                                instanceIds.add(i.getId());
                            }
                        }
                    }
                }
                solverConfigTableModel.setSolverConfigurations(scs);
                instanceTableModel.setInstances(inst, false, false);
                solverConfigTableModel.fireTableDataChanged();
                instanceTableModel.fireTableDataChanged();
            }
        });

        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component c;
                if (value instanceof Boolean) {
                    c = defaultBooleanCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                } else {
                    c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                }
                boolean inExperiment = false;
                if (table == tblSolverConfigs) {
                    SolverConfiguration sc = solverConfigTableModel.getSolverConfigurationAt(tblSolverConfigs.convertRowIndexToModel(row));
                    if (solverConfigIds.contains(sc.getId())) {
                        inExperiment = true;
                    }
                } else if (table == tblInstances) {
                    Instance i = instanceTableModel.getInstanceAt(tblInstances.convertRowIndexToModel(row));
                    if (instanceIds.contains(i.getId())) {
                        inExperiment = true;
                    }
                }
                if (isSelected) {
                    c.setBackground(table.getSelectionBackground());
                } else {
                    if (inExperiment) {
                        c.setBackground(Color.orange);
                    } else {
                        c.setBackground(table.getBackground());
                    }
                }
                return c;
            }
        };

        tblInstances.setDefaultRenderer(String.class, renderer);
        tblInstances.setDefaultRenderer(Boolean.class, renderer);
        tblInstances.setDefaultRenderer(Integer.class, renderer);
        tblInstances.setDefaultRenderer(Float.class, renderer);
        tblInstances.setDefaultRenderer(Double.class, renderer);

        tblSolverConfigs.setDefaultRenderer(String.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Boolean.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Integer.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Float.class, renderer);
        tblSolverConfigs.setDefaultRenderer(Double.class, renderer);
        
        Util.addSpaceSelection(tblInstances, InstanceTableModel.COL_SELECTED);
        Util.addSpaceSelection(tblSolverConfigs, SolverConfigurationTableModel.COL_SEL);
    }

    public void initializeData() {
{'fraction_non_alphanumeric': 0.08234170706625532, 'fraction_numerical': 0.00205670633171735, 'mean_word_length': 2.4785385794583545, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '1201342', 'n_tokens_mistral': 3436, 'n_tokens_neox': 3254, 'n_words': 624}