<commit_before>package nl.fontys.sofa.limo.view.custom;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import nl.fontys.sofa.limo.api.dao.ProcedureCategoryDAO;
import nl.fontys.sofa.limo.domain.component.procedure.Procedure;
import nl.fontys.sofa.limo.domain.component.procedure.ProcedureCategory;
import nl.fontys.sofa.limo.domain.component.procedure.ProcedureResponsibilityDirection;
import nl.fontys.sofa.limo.domain.component.procedure.TimeType;
import nl.fontys.sofa.limo.domain.component.procedure.value.RangeValue;
import nl.fontys.sofa.limo.domain.component.procedure.value.SingleValue;
import nl.fontys.sofa.limo.domain.component.procedure.value.Value;
import nl.fontys.sofa.limo.view.custom.table.DragNDropTable;
import nl.fontys.sofa.limo.view.custom.table.DragNDropTableModel;
import org.openide.util.Lookup;

/**
 * @author <NAME>
 */
public class ProcedureComponent extends JPanel implements ActionListener, MouseListener {

    private DragNDropTable table;
    private DragNDropTableModel model;
    private final JButton btn_add, btn_delete;
    private final JScrollPane sc_pane;
    private ProcedureCategoryDAO procedureCategoryDao = Lookup.getDefault().lookup(ProcedureCategoryDAO.class);
    private Value changedValue;
    CellConstraints cc;

    public ProcedureComponent(List<Procedure> procedures) {
        //LAYOUT
        cc = new CellConstraints();
        FormLayout layout = new FormLayout("5px, pref:grow, 5px, pref, 5px", "5px, pref, 10px, pref, pref:grow, 5px");
        this.setLayout(layout);
        //TABLEMODEL
        List<List<Object>> valueList = new ArrayList<>();
        for (Procedure p : procedures) {
            ArrayList<Object> values = new ArrayList<>();
            values.add(p.getName());
            values.add(p.getCategory());
            values.add(p.getTimeType());
            values.add(p.getTime());
            values.add(p.getCost());
            values.add(p.getDirection());
            valueList.add(values);
        }
        model = new DragNDropTableModel(new String[]{"Name", "Category", "Time Type", "Time Cost", "Money Cost", "Direction"},
                valueList, new Class[]{String.class, String.class, TimeType.class, Value.class, Value.class, ProcedureResponsibilityDirection.class});
        //TABLE
        table = new DragNDropTable(model);
        try {
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JComboBox(procedureCategoryDao.findAll().toArray())));
        } catch (Exception e) {
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JComboBox(new ProcedureCategory[]{})));
        }
        table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(new JComboBox(TimeType.values())));
        table.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(new JComboBox(ProcedureResponsibilityDirection.values())));
        //OTHER COMPONENTS
        sc_pane = new JScrollPane(table);
        btn_add = new JButton("+");
        btn_delete = new JButton("-");
        //ADD COMPONENTS TO PANEL
        this.add(sc_pane, cc.xywh(2, 2, 1, 4));
        this.add(btn_add, cc.xy(4, 2));
        this.add(btn_delete, cc.xy(4, 4));
        //ADD COMPONENTS TO LISTENER
        btn_add.addActionListener(this);
        btn_delete.addActionListener(this);
        table.addMouseListener(this);
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(btn_delete)) {
            int rowToDelete = table.getSelectedRow();
            if (rowToDelete > -1) {
                deleteProcedure(rowToDelete);
            }
        } else if (e.getSource().equals(btn_add)) {
            addProcedure();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getSource().equals(table)) {
            System.out.println(getActiveTableState());
            if (e.getClickCount() > 1) {
                editProcedure();
            }
        }
    }

    public List<Procedure> getActiveTableState() {
        List<List<Object>> values = ((DragNDropTableModel) table.getModel()).getValues();
        ArrayList<Procedure> procedures = new ArrayList<>();
        for (List<Object> value : values) {
            Procedure p = new Procedure();
            p.setName((String) value.get(0));
            p.setCategory((String) value.get(1));
            p.setTimeType((TimeType) value.get(2));
            p.setTime((Value) value.get(3));
            p.setCost((Value) value.get(4));
            p.setDirection((ProcedureResponsibilityDirection) value.get(5));
            procedures.add(p);
        }
        return procedures;
    }

    private void addProcedure() {
        new AddProcedureDialog();
    }<commit_msg>- ProcedureComponent -- Empty Constructor added -- setProcedureTable<commit_after>package nl.fontys.sofa.limo.view.custom;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultCellEditor;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import nl.fontys.sofa.limo.api.dao.ProcedureCategoryDAO;
import nl.fontys.sofa.limo.domain.component.procedure.Procedure;
import nl.fontys.sofa.limo.domain.component.procedure.ProcedureCategory;
import nl.fontys.sofa.limo.domain.component.procedure.ProcedureResponsibilityDirection;
import nl.fontys.sofa.limo.domain.component.procedure.TimeType;
import nl.fontys.sofa.limo.domain.component.procedure.value.RangeValue;
import nl.fontys.sofa.limo.domain.component.procedure.value.SingleValue;
import nl.fontys.sofa.limo.domain.component.procedure.value.Value;
import nl.fontys.sofa.limo.view.custom.table.DragNDropTable;
import nl.fontys.sofa.limo.view.custom.table.DragNDropTableModel;
import org.openide.util.Lookup;

/**
 * @author <NAME>
 */
public class ProcedureComponent extends JPanel implements ActionListener, MouseListener {

    private DragNDropTable table;
    private DragNDropTableModel model;
    private JButton btn_add, btn_delete;
    private JScrollPane sc_pane;
    private ProcedureCategoryDAO procedureCategoryDao = Lookup.getDefault().lookup(ProcedureCategoryDAO.class);
    private Value changedValue;
    CellConstraints cc;

    public ProcedureComponent() {
        new ProcedureComponent(null);
    }

    public ProcedureComponent(List<Procedure> procedures) {
        //LAYOUT
        cc = new CellConstraints();
        FormLayout layout = new FormLayout("5px, pref:grow, 5px, pref, 5px", "5px, pref, 10px, pref, pref:grow, 5px");
        this.setLayout(layout);
        //TABLEMODEL
        List<List<Object>> valueList = new ArrayList<>();
        if (procedures != null) {
            for (Procedure p : procedures) {
                ArrayList<Object> values = new ArrayList<>();
                values.add(p.getName());
                values.add(p.getCategory());
                values.add(p.getTimeType());
                values.add(p.getTime());
                values.add(p.getCost());
                values.add(p.getDirection());
                valueList.add(values);
            }
        }
        model = new DragNDropTableModel(new String[]{"Name", "Category", "Time Type", "Time Cost", "Money Cost", "Direction"},
                valueList, new Class[]{String.class, String.class, TimeType.class, Value.class, Value.class, ProcedureResponsibilityDirection.class});
        //TABLE
        table = new DragNDropTable(model);
        try {
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JComboBox(procedureCategoryDao.findAll().toArray())));
        } catch (Exception e) {
            table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new JComboBox(new ProcedureCategory[]{})));
        }
        table.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(new JComboBox(TimeType.values())));
        table.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(new JComboBox(ProcedureResponsibilityDirection.values())));
        //OTHER COMPONENTS
        sc_pane = new JScrollPane(table);
        btn_add = new JButton("+");
        btn_delete = new JButton("-");
        //ADD COMPONENTS TO PANEL
        this.add(sc_pane, cc.xywh(2, 2, 1, 4));
        this.add(btn_add, cc.xy(4, 2));
        this.add(btn_delete, cc.xy(4, 4));
        //ADD COMPONENTS TO LISTENER
        btn_add.addActionListener(this);
        btn_delete.addActionListener(this);
        table.addMouseListener(this);
        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource().equals(btn_delete)) {
            int rowToDelete = table.getSelectedRow();
            if (rowToDelete > -1) {
                deleteProcedure(rowToDelete);
            }
        } else if (e.getSource().equals(btn_add)) {
            addProcedure();
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getSource().equals(table)) {
            System.out.println(getActiveTableState());
            if (e.getClickCount() > 1) {
                editProcedure();
            }
        }
    }

    public List<Procedure> getActiveTableState() {
        List<List<Object>> values = ((DragNDropTableModel) table.getModel()).getValues();
        ArrayList<Procedure> procedures = new ArrayList<>();
        for (List<Object> value : values) {
            Procedure p = new Procedure();
            p.setName((String) value.get(0));
            p.setCategory((String) value.get(1));
            p.setTimeType((TimeType) value.get(2));
            p.setTime((Value) value.get(3));
            p.setCost((Value) value.get(4));
            p.setDirection((ProcedureResponsibilityDirection) value.get(5));
            procedures.add(p);
        }
        return procedures;
    }

    public void setProcedureTable(List<Procedure> procedures) {
        List<List<Object>> valueList = new ArrayList<>();
        if (procedures != null) {
            for (Procedure p : procedures) {
                ArrayList<Object> values = new ArrayList<>();
                values.add(p.getName());
                values.add(p.getCategory());
                values.add(p.getTimeType());
                values.add(p.getTime());
                values.add(p.getCost());
                values.add(p.getDirection());
                valueList.add(values);
            }
        }
        model = new DragNDropTableModel(new String[]{"Name", "Category", "Time Type", "Time Cost", "Money Cost", "Direction"},
                valueList, new Class[]{String.class, String.class, TimeType.class, Value.class, Value.class, ProcedureResponsibilityDirection.class});
        table.setModel(model);
        model.fireTableDataChanged();
        this.revalidate();
        this.repaint();
    }

    private void addProcedure() {
        new AddProcedureDialog();
    }
{'fraction_non_alphanumeric': 0.12588892651540806, 'fraction_numerical': 0.004571622079241449, 'mean_word_length': 2.928500166278683, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '2019585', 'n_tokens_mistral': 3510, 'n_tokens_neox': 3468, 'n_words': 616}