<commit_before>package org.pentaho.reporting.platform.plugin.gwt.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.SimplePanel;

public class DropDownParameterUI extends SimplePanel implements ParameterUI
{
  private class ListBoxChangeHandler implements ChangeHandler
  {
    private ParameterControllerPanel controller;
    private String parameterName;

    public ListBoxChangeHandler(final ParameterControllerPanel controller,
                                final String parameterName)
    {
      this.controller = controller;
      this.parameterName = parameterName;
    }

    public void onChange(final ChangeEvent event)
    {
      updateSelection((ListBox) event.getSource());
      controller.fetchParameters(ParameterControllerPanel.ParameterSubmitMode.USERINPUT);
    }
    
    public void updateSelection(ListBox listBox) {
      final ArrayList<String> selectedItems = new ArrayList<String>();
      for (int i = 0; i < listBox.getItemCount(); i++)
      {
        if (listBox.isItemSelected(i))
        {
          selectedItems.add(values.get(i));
        }
      }
      controller.getParameterMap().setSelectedValues
          (parameterName, selectedItems.toArray(new String[selectedItems.size()]));
    }
  }

  private ListBox listBox;
  private ArrayList<String> values;

  public DropDownParameterUI(final ParameterControllerPanel controller, final Parameter parameterElement)
  {
    listBox = new ListBox(false);
    listBox.setVisibleItemCount(1);
    values = new ArrayList<String>();

    boolean hasSelection = false;
    final List<ParameterSelection> choices = parameterElement.getSelections();
    for (int i = 0; i < choices.size(); i++)
    {
      final ParameterSelection choiceElement = choices.get(i);
      final String choiceLabel = choiceElement.getLabel(); //$NON-NLS-1$
      final String choiceValue = choiceElement.getValue(); //$NON-NLS-1$
      listBox.addItem(choiceLabel, String.valueOf(i));
      values.add(choiceValue);
      final boolean selected = choiceElement.isSelected();
      listBox.setItemSelected(i, selected);
      if (selected)
      {
        hasSelection = true;
      }
    }

    ListBoxChangeHandler lbChangeHandler = new ListBoxChangeHandler(controller, parameterElement.getName());
    listBox.addChangeHandler(lbChangeHandler);

    if (hasSelection == false) {
      listBox.setSelectedIndex(0);
    }
    
    lbChangeHandler.updateSelection(listBox);
    
    setWidget(listBox);
  }

  public void setEnabled(final boolean enabled)
  {
    listBox.setEnabled(enabled); 
  }
}<commit_msg>PRD-3467 UI Refresh - Report filters controls do not have updated style<commit_after>package org.pentaho.reporting.platform.plugin.gwt.client;

import java.util.ArrayList;
import java.util.List;

import org.pentaho.gwt.widgets.client.listbox.CustomListBox;
import org.pentaho.gwt.widgets.client.listbox.DefaultListItem;
import org.pentaho.gwt.widgets.client.listbox.ListItem;

import com.google.gwt.user.client.ui.ChangeListener;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

public class DropDownParameterUI extends SimplePanel implements ParameterUI
{
  private class ListBoxChangeHandler implements ChangeListener
  {
    private ParameterControllerPanel controller;
    private String parameterName;

    public ListBoxChangeHandler(final ParameterControllerPanel controller,
                                final String parameterName)
    {
      this.controller = controller;
      this.parameterName = parameterName;
    }

    public void onChange(Widget sender) {
      updateSelection((CustomListBox)sender);
      controller.fetchParameters(ParameterControllerPanel.ParameterSubmitMode.USERINPUT);
    }
    
    public void updateSelection(CustomListBox listBox) {
      final ArrayList<String> selectedItems = new ArrayList<String>();
      for (ListItem item : listBox.getSelectedItems()) {
        selectedItems.add((String)item.getValue());
      }
      controller.getParameterMap().setSelectedValues
          (parameterName, selectedItems.toArray(new String[selectedItems.size()]));
    }
  }

  private CustomListBox listBox;

  public DropDownParameterUI(final ParameterControllerPanel controller, final Parameter parameterElement)
  {
    listBox = new CustomListBox();
    listBox.setMultiSelect(false);
    listBox.setVisibleRowCount(1);

    boolean hasSelection = false;
    final List<ParameterSelection> choices = parameterElement.getSelections();
    for (int i = 0; i < choices.size(); i++)
    {
      final ParameterSelection choiceElement = choices.get(i);
      final String choiceLabel = choiceElement.getLabel(); //$NON-NLS-1$
      final String choiceValue = choiceElement.getValue(); //$NON-NLS-1$
      
      DefaultListItem item = new DefaultListItem(choiceLabel);
      item.setValue(choiceValue);

      listBox.addItem(item);
      final boolean selected = choiceElement.isSelected();
      if (selected)
      {
        listBox.setSelectedIndex(i);
        hasSelection = true;
      }
    }

    ListBoxChangeHandler lbChangeHandler = new ListBoxChangeHandler(controller, parameterElement.getName());
    listBox.addChangeListener(lbChangeHandler);

    if (hasSelection == false) {
      listBox.setSelectedIndex(0);
    }
    
    lbChangeHandler.updateSelection(listBox);
    
    setWidget(listBox);
  }

  public void setEnabled(final boolean enabled)
  {
    listBox.setEnabled(enabled); 
  }
}
{'fraction_non_alphanumeric': 0.0950952717007763, 'fraction_numerical': 0.002646436132674665, 'mean_word_length': 3.601461038961039, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 11, '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': '1568401', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1516, 'n_words': 310}