<commit_before>package fi.csc.microarray.client.operation.parameter;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

import fi.csc.microarray.client.operation.Operation;
import fi.csc.microarray.client.operation.Operation.DataBinding;
import fi.csc.microarray.client.operation.OperationDefinition.InputDefinition;
import fi.csc.microarray.databeans.DataBean;

/**
 * User can remap input files to appropriate input
 * parameters.
 * 
 * @author naktinis
 *
 */
@SuppressWarnings("serial")
public class InputFileComponent extends JPanel {
    
    private static final Logger logger = Logger
        .getLogger(SingleSelectionInputComponent.class);
    
    private InputDefinition input;
    private SteppedComboBox choiceBox;
    private Operation operation;

    public InputFileComponent(InputDefinition input, Operation operation) {
        super(new BorderLayout());
        
        // Set name and operation object
        this.input = input;
        this.operation = operation;
        
        // Check current bindings and generate choices
        List<DataBinding> bindings = operation.getBindings();
        HashMap<String, String> bindingMap = new HashMap<String, String>();
        DataBean[] dataBeans = new DataBean[0];
        DataBean currentBean = null;
        Boolean enabled = false;
        Integer index = 0;
        if (bindings != null) {
            
            // User has already selected the input files
            enabled = true;
            dataBeans = new DataBean[bindings.size()];
            for (DataBinding binding : bindings) {
                dataBeans[index++] = binding.getData();
                bindingMap.put(binding.getName(), binding.getData().getName());
                
                // Find the selected item
                if (binding.getName().equals(input.getID())) {
                    currentBean = binding.getData();
                }
            }
        }
        
        // Prepare the combo box
        choiceBox = new SteppedComboBox(dataBeans);
        choiceBox.setEnabled(enabled);
        choiceBox.setPreferredSize(ParameterInputComponent.PREFERRED_SIZE);
        choiceBox.setBackground(Color.white);

        // Set selected bean for this combo box
        if (currentBean != null) {
            choiceBox.setSelectedItem(currentBean);
        }
        
        this.add(choiceBox, BorderLayout.CENTER);
    }
    
    /**
     * @return input definition object.
     */
    public InputDefinition getInput() {
        return input;
    }
    
    /**
     * @return checkbox component.
     */
    public JComboBox getChoiceBox() {
        return choiceBox;
    }
    
    /**
     * Sets action listener for this component.
     */
    public void setListener(InputFileComponentListener listener) {
        choiceBox.addItemListener(listener);
    }
    
    /**
     * @return parameter name for this component.
     */
    public JLabel getLabel() {
        return new JLabel(input.getDescription());
    }
    
    /**
     * Listener that is responsible for changes made to input
     * file selection components.
     */
    public class InputFileComponentListener implements ItemListener {
        
        private Object deselected;<commit_msg>Fixed input names in the parameter panel.<commit_after>package fi.csc.microarray.client.operation.parameter;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.apache.log4j.Logger;

import fi.csc.microarray.client.operation.Operation;
import fi.csc.microarray.client.operation.Operation.DataBinding;
import fi.csc.microarray.client.operation.OperationDefinition.InputDefinition;
import fi.csc.microarray.databeans.DataBean;

/**
 * User can remap input files to appropriate input
 * parameters.
 * 
 * @author naktinis
 *
 */
@SuppressWarnings("serial")
public class InputFileComponent extends JPanel {
    
    private static final Logger logger = Logger
        .getLogger(SingleSelectionInputComponent.class);
    
    private InputDefinition input;
    private SteppedComboBox choiceBox;
    private Operation operation;

    public InputFileComponent(InputDefinition input, Operation operation) {
        super(new BorderLayout());
        
        // Set name and operation object
        this.input = input;
        this.operation = operation;
        
        // Check current bindings and generate choices
        List<DataBinding> bindings = operation.getBindings();
        HashMap<String, String> bindingMap = new HashMap<String, String>();
        DataBean[] dataBeans = new DataBean[0];
        DataBean currentBean = null;
        Boolean enabled = false;
        Integer index = 0;
        if (bindings != null) {
            
            // User has already selected the input files
            enabled = true;
            dataBeans = new DataBean[bindings.size()];
            for (DataBinding binding : bindings) {
                dataBeans[index++] = binding.getData();
                bindingMap.put(binding.getName(), binding.getData().getName());
                
                // Find the selected item
                if (binding.getName().equals(input.getID())) {
                    currentBean = binding.getData();
                }
            }
        }
        
        // Prepare the combo box
        choiceBox = new SteppedComboBox(dataBeans);
        choiceBox.setEnabled(enabled);
        choiceBox.setPreferredSize(ParameterInputComponent.PREFERRED_SIZE);
        choiceBox.setBackground(Color.white);

        // Set selected bean for this combo box
        if (currentBean != null) {
            choiceBox.setSelectedItem(currentBean);
        }
        
        this.add(choiceBox, BorderLayout.CENTER);
    }
    
    /**
     * @return input definition object.
     */
    public InputDefinition getInput() {
        return input;
    }
    
    /**
     * @return checkbox component.
     */
    public JComboBox getChoiceBox() {
        return choiceBox;
    }
    
    /**
     * Sets action listener for this component.
     */
    public void setListener(InputFileComponentListener listener) {
        choiceBox.addItemListener(listener);
    }
    
    /**
     * @return parameter name for this component.
     */
    public JLabel getLabel() {
        return new JLabel(input.getDisplayName());
    }
    
    /**
     * Listener that is responsible for changes made to input
     * file selection components.
     */
    public class InputFileComponentListener implements ItemListener {
        
        private Object deselected;
{'fraction_non_alphanumeric': 0.0905601364799545, 'fraction_numerical': 0.0008529997156667614, 'mean_word_length': 2.3404558404558404, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3319894', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1800, 'n_words': 451}