<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ro.nextreports.designer.querybuilder;

import ro.nextreports.engine.querybuilder.IdNameRenderer;
import ro.nextreports.engine.util.comparator.IdNameComparator;
import ro.nextreports.engine.util.ParameterUtil;

import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ro.nextreports.designer.Globals;
import ro.nextreports.designer.datasource.DataSource;
import ro.nextreports.designer.datasource.exception.ConnectionException;
import ro.nextreports.designer.dbviewer.common.InvalidSqlException;
import ro.nextreports.designer.dbviewer.common.NextSqlException;
import ro.nextreports.designer.util.I18NSupport;
import ro.nextreports.designer.util.JDateTimePicker;
import ro.nextreports.designer.util.ListAddPanel;
import ro.nextreports.designer.util.ListSelectionPanel;
import ro.nextreports.designer.util.Show;
import ro.nextreports.designer.util.UIActivator;

import ro.nextreports.engine.queryexec.IdName;
import ro.nextreports.engine.queryexec.QueryException;
import ro.nextreports.engine.queryexec.QueryParameter;
import ro.nextreports.engine.queryexec.Query;
import ro.nextreports.engine.queryexec.QueryExecutor;
import ro.nextreports.engine.queryexec.QueryResult;
import ro.nextreports.engine.EngineProperties;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.*;
import java.util.List;
import java.io.Serializable;
import java.sql.Connection;

/**
 * @author <NAME>
 */
public class RuntimeParametersPanel extends JPanel {

    private List<QueryParameter> paramList;
    private List<JComponent> components;
    private List<JCheckBox> checks;

    private Dimension scrDim = new Dimension(450, 400);
    private Dimension listDim = new Dimension(200, 60);
    private Dimension scrListDim = new Dimension(130, 120);

    private static Map<String, Object> parametersValues;
    private static Map<String, Boolean> parametersIgnore;        

    private static final Log LOG = LogFactory.getLog(RuntimeParametersPanel.class);
    private Connection con;

    private boolean error = false;

    public RuntimeParametersPanel(Map<String, QueryParameter> params) {
        this(params, null);
    }

    public RuntimeParametersPanel(Map<String, QueryParameter> params, DataSource runDS) {
        super();
        con = Globals.getConnection();
        if (runDS != null) {
            try {
                con = Globals.createTempConnection(runDS);
            } catch (ConnectionException e) {
                e.printStackTrace();
                Show.error(e);
                return;
            }
        }
               
        paramList = new ArrayList<QueryParameter>(params.values());        
        initUI();
    }

    private void initUI() {
        setLayout(new GridBagLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        components = new ArrayList<JComponent>();
        checks = new ArrayList<JCheckBox>();

        int size = paramList.size();        
        boolean shouldExpand = false;
        boolean needScroll = false;
        for (int i = 0; i < size; i++) {
        	final int pos = i;
            final QueryParameter param = paramList.get(i);            
            if (param.isHidden()) {
            	components.add(null);
            	checks.add(null);              	
            	initHiddenParameterValues(param);   
            	continue;
            }
            String source = param.getSource();
            String defaultSource = param.getDefaultSource();

            if ((defaultSource != null) && !defaultSource.trim().equals("")) {
                try {
                    param.setDefaultSourceValues(Globals.getDBViewer().getDefaultSourceValues(con, param));
                } catch (NextSqlException e) {
                    Show.error(e);
                }
            }

            final JComponent component;
            int anchor = GridBagConstraints.WEST;
            double y = 0.0;
            int expand = GridBagConstraints.HORIZONTAL;
            if ((source != null) && !source.equals("")) {
                List<IdName> values = new ArrayList<IdName>();
                try {
                    if (param.isManualSource()) {
                        if (!param.isDependent()) {
                            values = Globals.getDBViewer().getValues(con, source, true, param.getOrderBy());
                        }
                    } else {
                        int index = source.indexOf(".");
                        int index2 = source.lastIndexOf(".");
                        String tableName = source.substring(0, index);
                        String columnName;
                        String shownColumnName = null;
                        if (index == index2) {
                            columnName = source.substring(index + 1);
                        } else {
                            columnName = source.substring(index + 1, index2);
                            shownColumnName = source.substring(index2 + 1);
                        }                        
                        values = Globals.getDBViewer().getColumnValues(con, param.getSchema(), tableName, columnName, shownColumnName, param.getOrderBy());
                    }
                } catch (NextSqlException e) {
                    error = true;
                    Show.error(e);
                } catch (InvalidSqlException e) {
                    String m = I18NSupport.getString("source.dialog.valid");
                    Show.info(m + " : \"select <exp1> , <exp2> from ...\"");
                }                               
                if (param.getSelection().equals(ParameterEditPanel.SINGLE_SELECTION)) {
                    component = new JComboBox();
                    final JComboBox combo = (JComboBox) component;
                    combo.setRenderer(new IdNameRenderer());
                    combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --");
                    for (int j = 0, len = values.size(); j < len; j++) {
                        combo.addItem(values.get(j));
                    }                    

                    combo.addItemListener(new ItemListener() {
                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == ItemEvent.SELECTED) {
                                IdName in = null;
                                if (combo.getSelectedIndex() > 0) {
                                    in = (IdName) combo.getSelectedItem();
                                }
                                parameterSelection(pos, in);
                            }
                        }
                    });
                    AutoCompleteDecorator.decorate(combo);
                    needScroll = false;
                } else {                	
                    anchor = GridBagConstraints.NORTHWEST;
                    y = 1.0;
                    expand = GridBagConstraints.BOTH;

                    DefaultListModel model = new DefaultListModel();
                    for (int j = 0, len = values.size(); j < len; j++) {
                        model.addElement(values.get(j));
                    }
                    List srcList = Arrays.asList(model.toArray());                    
                    component = new ListSelectionPanel(srcList, new ArrayList(), "", "", true, false) {
                        protected void onAdd() {
                            selection();
                        }

                        protected void onRemove() {
                            selection();
                        }

                        // needed for saved parameters on rerun
                        protected void onSetRight() {
                            selection();
                        }

                        private void selection() {
                            if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                                Object[] values = getDestinationElements().toArray();
                                if (values.length == 0) {
                                	values = new Object[]{ParameterUtil.NULL};                                	
                                }
                                parameterSelection(pos, values);
                            }
                        }
                    };
                    ((ListSelectionPanel) component).setListSize(scrListDim);
                    ((ListSelectionPanel) component).setRenderer(new IdNameRenderer(), new IdNameComparator(param.getOrderBy()));

                    shouldExpand = true;
                }

            } else {            	
                if (param.getSelection().equals(QueryParameter.MULTIPLE_SELECTION)) {
                    anchor = GridBagConstraints.NORTHWEST;
                    y = 1.0;
                    expand = GridBagConstraints.BOTH;                    ;
                    component = new ListAddPanel(param) {
                    	protected void onAdd() {
                            selection();
                        }

                        protected void onRemove() {
                            selection();
                        }
                        
                        private void selection() {
                            if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                                Object[] values = getElements().toArray();
                                parameterSelection(pos, values);
                            }
                        }
                    };                    
                } else {
                    needScroll = false;
                    if (param.getValueClassName().equals("java.util.Date")) {
                    	 component = new JXDatePicker();                    	                     	                    	 
                    	 ((JXDatePicker)component).addPropertyChangeListener(new PropertyChangeListener() {
                    	     public void propertyChange(PropertyChangeEvent e) {
                    	         if ("date".equals(e.getPropertyName())) {
                    	        	 parameterSelection(pos, ((JXDatePicker)component).getDate());
                    	         }
                    	     }
                    	 });
                         // hack to fix bug with big popup button
                         JButton popupButton = (JButton) component.getComponent(1);
                         //popupButton.setMargin(new Insets(2, 2, 2, 2));
                         popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                         popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                         popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));                    	
                    } else if(param.getValueClassName().equals("java.sql.Timestamp") ||
                            param.getValueClassName().equals("java.sql.Time")) {
                        component = new JDateTimePicker() {
                        	protected void onChange() {
                        		parameterSelection(pos,getDate());
                        	}
                        };
                        // hack to fix bug with big popup button
                        JButton popupButton = (JButton) (((JDateTimePicker) component).getDatePicker()).getComponent(1);
                        //popupButton.setMargin(new Insets(2, 2, 2, 2));
                        popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                        popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                        popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));
                    } else if (param.getValueClassName().equals("java.lang.Boolean")) {
                        component = new JCheckBox();
                        ((JCheckBox)component).addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent actionEvent) {
                                AbstractButton abstractButton = (AbstractButton)actionEvent.getSource();
                                boolean selected = abstractButton.getModel().isSelected();
                                parameterSelection(pos,selected);
                              }
                        });
                    } else {
                        component = new JTextField(25);
                        ((JTextField)component).addPropertyChangeListener(new PropertyChangeListener() {
							@Override
							public void propertyChange(PropertyChangeEvent evt) {	
								Object value = null;								
								try {
									if ("".equals(((JTextField)component).getText().trim())) {
										value = null;
									} else {	
										value = ParameterUtil.getParameterValueFromString(param.getValueClassName(),((JTextField)component).getText());			                    											
									}
									parameterSelection(pos, value);
								} catch (Exception e) {
									e.printStackTrace();
									LOG.error(e.getMessage(), e);
								}																	
							}                        	
                        });
                    }
                }
            }
            components.add(component);
            final JCheckBox cb = new JCheckBox(I18NSupport.getString("run.parameter.ignore"));
            checks.add(cb);


            final JLabel label = new JLabel(getRuntimeParameterName(param));
            panel.add(label, new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, anchor,
                    GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
            final JComponent addComponent;
            if (needScroll) {
                JScrollPane scr = new JScrollPane(component, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scr.setPreferredSize(listDim);
                addComponent = scr;
            } else {
                addComponent = component;
            }
            panel.add(addComponent, new GridBagConstraints(1, i, 1, 1, 1.0, y, GridBagConstraints.WEST,<commit_msg>change PropertyChangeListener with DocumentListener for JTextField<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ro.nextreports.designer.querybuilder;

import ro.nextreports.engine.querybuilder.IdNameRenderer;
import ro.nextreports.engine.util.comparator.IdNameComparator;
import ro.nextreports.engine.util.ParameterUtil;

import org.jdesktop.swingx.JXDatePicker;
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ro.nextreports.designer.Globals;
import ro.nextreports.designer.datasource.DataSource;
import ro.nextreports.designer.datasource.exception.ConnectionException;
import ro.nextreports.designer.dbviewer.common.InvalidSqlException;
import ro.nextreports.designer.dbviewer.common.NextSqlException;
import ro.nextreports.designer.util.I18NSupport;
import ro.nextreports.designer.util.JDateTimePicker;
import ro.nextreports.designer.util.ListAddPanel;
import ro.nextreports.designer.util.ListSelectionPanel;
import ro.nextreports.designer.util.Show;
import ro.nextreports.designer.util.UIActivator;

import ro.nextreports.engine.queryexec.IdName;
import ro.nextreports.engine.queryexec.QueryException;
import ro.nextreports.engine.queryexec.QueryParameter;
import ro.nextreports.engine.queryexec.Query;
import ro.nextreports.engine.queryexec.QueryExecutor;
import ro.nextreports.engine.queryexec.QueryResult;
import ro.nextreports.engine.EngineProperties;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.*;
import java.util.List;
import java.io.Serializable;
import java.sql.Connection;

/**
 * @author <NAME>
 */
public class RuntimeParametersPanel extends JPanel {

    private List<QueryParameter> paramList;
    private List<JComponent> components;
    private List<JCheckBox> checks;

    private Dimension scrDim = new Dimension(450, 400);
    private Dimension listDim = new Dimension(200, 60);
    private Dimension scrListDim = new Dimension(130, 120);

    private static Map<String, Object> parametersValues;
    private static Map<String, Boolean> parametersIgnore;        

    private static final Log LOG = LogFactory.getLog(RuntimeParametersPanel.class);
    private Connection con;

    private boolean error = false;

    public RuntimeParametersPanel(Map<String, QueryParameter> params) {
        this(params, null);
    }

    public RuntimeParametersPanel(Map<String, QueryParameter> params, DataSource runDS) {
        super();
        con = Globals.getConnection();
        if (runDS != null) {
            try {
                con = Globals.createTempConnection(runDS);
            } catch (ConnectionException e) {
                e.printStackTrace();
                Show.error(e);
                return;
            }
        }
               
        paramList = new ArrayList<QueryParameter>(params.values());        
        initUI();
    }

    private void initUI() {
        setLayout(new GridBagLayout());

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        components = new ArrayList<JComponent>();
        checks = new ArrayList<JCheckBox>();

        int size = paramList.size();        
        boolean shouldExpand = false;
        boolean needScroll = false;
        for (int i = 0; i < size; i++) {
        	final int pos = i;
            final QueryParameter param = paramList.get(i);            
            if (param.isHidden()) {
            	components.add(null);
            	checks.add(null);              	
            	initHiddenParameterValues(param);   
            	continue;
            }
            String source = param.getSource();
            String defaultSource = param.getDefaultSource();

            if ((defaultSource != null) && !defaultSource.trim().equals("")) {
                try {
                    param.setDefaultSourceValues(Globals.getDBViewer().getDefaultSourceValues(con, param));
                } catch (NextSqlException e) {
                    Show.error(e);
                }
            }

            final JComponent component;
            int anchor = GridBagConstraints.WEST;
            double y = 0.0;
            int expand = GridBagConstraints.HORIZONTAL;
            if ((source != null) && !source.equals("")) {
                List<IdName> values = new ArrayList<IdName>();
                try {
                    if (param.isManualSource()) {
                        if (!param.isDependent()) {
                            values = Globals.getDBViewer().getValues(con, source, true, param.getOrderBy());
                        }
                    } else {
                        int index = source.indexOf(".");
                        int index2 = source.lastIndexOf(".");
                        String tableName = source.substring(0, index);
                        String columnName;
                        String shownColumnName = null;
                        if (index == index2) {
                            columnName = source.substring(index + 1);
                        } else {
                            columnName = source.substring(index + 1, index2);
                            shownColumnName = source.substring(index2 + 1);
                        }                        
                        values = Globals.getDBViewer().getColumnValues(con, param.getSchema(), tableName, columnName, shownColumnName, param.getOrderBy());
                    }
                } catch (NextSqlException e) {
                    error = true;
                    Show.error(e);
                } catch (InvalidSqlException e) {
                    String m = I18NSupport.getString("source.dialog.valid");
                    Show.info(m + " : \"select <exp1> , <exp2> from ...\"");
                }                               
                if (param.getSelection().equals(ParameterEditPanel.SINGLE_SELECTION)) {
                    component = new JComboBox();
                    final JComboBox combo = (JComboBox) component;
                    combo.setRenderer(new IdNameRenderer());
                    combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --");
                    for (int j = 0, len = values.size(); j < len; j++) {
                        combo.addItem(values.get(j));
                    }                    

                    combo.addItemListener(new ItemListener() {
                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == ItemEvent.SELECTED) {
                                IdName in = null;
                                if (combo.getSelectedIndex() > 0) {
                                    in = (IdName) combo.getSelectedItem();
                                }
                                parameterSelection(pos, in);
                            }
                        }
                    });
                    AutoCompleteDecorator.decorate(combo);
                    needScroll = false;
                } else {                	
                    anchor = GridBagConstraints.NORTHWEST;
                    y = 1.0;
                    expand = GridBagConstraints.BOTH;

                    DefaultListModel model = new DefaultListModel();
                    for (int j = 0, len = values.size(); j < len; j++) {
                        model.addElement(values.get(j));
                    }
                    List srcList = Arrays.asList(model.toArray());                    
                    component = new ListSelectionPanel(srcList, new ArrayList(), "", "", true, false) {
                        protected void onAdd() {
                            selection();
                        }

                        protected void onRemove() {
                            selection();
                        }

                        // needed for saved parameters on rerun
                        protected void onSetRight() {
                            selection();
                        }

                        private void selection() {
                            if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                                Object[] values = getDestinationElements().toArray();
                                if (values.length == 0) {
                                	values = new Object[]{ParameterUtil.NULL};                                	
                                }
                                parameterSelection(pos, values);
                            }
                        }
                    };
                    ((ListSelectionPanel) component).setListSize(scrListDim);
                    ((ListSelectionPanel) component).setRenderer(new IdNameRenderer(), new IdNameComparator(param.getOrderBy()));

                    shouldExpand = true;
                }

            } else {            	
                if (param.getSelection().equals(QueryParameter.MULTIPLE_SELECTION)) {
                    anchor = GridBagConstraints.NORTHWEST;
                    y = 1.0;
                    expand = GridBagConstraints.BOTH;                    ;
                    component = new ListAddPanel(param) {
                    	protected void onAdd() {
                            selection();
                        }

                        protected void onRemove() {
                            selection();
                        }
                        
                        private void selection() {
                            if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) {
                                Object[] values = getElements().toArray();
                                parameterSelection(pos, values);
                            }
                        }
                    };                    
                } else {
                    needScroll = false;
                    if (param.getValueClassName().equals("java.util.Date")) {
                    	 component = new JXDatePicker();                    	                     	                    	 
                    	 ((JXDatePicker)component).addPropertyChangeListener(new PropertyChangeListener() {
                    	     public void propertyChange(PropertyChangeEvent e) {
                    	         if ("date".equals(e.getPropertyName())) {
                    	        	 parameterSelection(pos, ((JXDatePicker)component).getDate());
                    	         }
                    	     }
                    	 });
                         // hack to fix bug with big popup button
                         JButton popupButton = (JButton) component.getComponent(1);
                         //popupButton.setMargin(new Insets(2, 2, 2, 2));
                         popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                         popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                         popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));                    	
                    } else if(param.getValueClassName().equals("java.sql.Timestamp") ||
                            param.getValueClassName().equals("java.sql.Time")) {
                        component = new JDateTimePicker() {
                        	protected void onChange() {
                        		parameterSelection(pos,getDate());
                        	}
                        };
                        // hack to fix bug with big popup button
                        JButton popupButton = (JButton) (((JDateTimePicker) component).getDatePicker()).getComponent(1);
                        //popupButton.setMargin(new Insets(2, 2, 2, 2));
                        popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                        popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight()));
                        popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY));
                    } else if (param.getValueClassName().equals("java.lang.Boolean")) {
                        component = new JCheckBox();
                        ((JCheckBox)component).addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent actionEvent) {
                                AbstractButton abstractButton = (AbstractButton)actionEvent.getSource();
                                boolean selected = abstractButton.getModel().isSelected();
                                parameterSelection(pos,selected);
                              }
                        });
                    } else {
                        component = new JTextField(25);
                        ((JTextField)component).getDocument().addDocumentListener(new DocumentListener() {
                        	
                        	@Override
                            public void changedUpdate(DocumentEvent e) {
                                updateFromTextField(e);
                            }

                            @Override
                            public void insertUpdate(DocumentEvent e) {
                                updateFromTextField(e);
                            }

                            @Override
                            public void removeUpdate(DocumentEvent e) {
                                updateFromTextField(e);
                            }

                            private void updateFromTextField(DocumentEvent e) {
                                java.awt.EventQueue.invokeLater(new Runnable() {

                                    @Override
                                    public void run() {
                                    	Object value = null;								
        								try {
        									if ("".equals(((JTextField)component).getText().trim())) {
        										value = null;
        									} else {	
        										value = ParameterUtil.getParameterValueFromString(param.getValueClassName(),((JTextField)component).getText());			                    											
        									}
        									parameterSelection(pos, value);
        								} catch (Exception e) {
        									e.printStackTrace();
        									LOG.error(e.getMessage(), e);
        								}			
                                    }
                                });
                            }
                        });
                    }
                }
            }
            components.add(component);
            final JCheckBox cb = new JCheckBox(I18NSupport.getString("run.parameter.ignore"));
            checks.add(cb);


            final JLabel label = new JLabel(getRuntimeParameterName(param));
            panel.add(label, new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, anchor,
                    GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
            final JComponent addComponent;
            if (needScroll) {
                JScrollPane scr = new JScrollPane(component, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scr.setPreferredSize(listDim);
                addComponent = scr;
            } else {
                addComponent = component;
            }
            panel.add(addComponent, new GridBagConstraints(1, i, 1, 1, 1.0, y, GridBagConstraints.WEST,
{'fraction_non_alphanumeric': 0.09131244182438722, 'fraction_numerical': 0.005584858827179647, 'mean_word_length': 1.4349172773286998, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373762', 'n_tokens_mistral': 7996, 'n_tokens_neox': 7197, 'n_words': 1565}