<commit_before>package org.pentaho.ui.xul.swing.tags;

import java.awt.Color;
import java.awt.Dimension;
import java.beans.Expression;
import java.util.Arrays;
import java.util.Collection;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.containers.XulListbox;
import org.pentaho.ui.xul.dom.Element;
import org.pentaho.ui.xul.swing.AbstractSwingContainer;
import org.pentaho.ui.xul.swing.SwingElement;
import org.pentaho.ui.xul.util.Orient;

public class SwingListbox extends AbstractSwingContainer implements XulListbox, ListSelectionListener{
  private static final long serialVersionUID = 3064125049914932493L;

  private JList listBox;
  private DefaultListModel model;
  private boolean disabled = false;
  private String selType;
  private int rowsToDisplay = 0;
  private String onselect;
  private JScrollPane scrollPane;
  private static final Log logger = LogFactory.getLog(SwingListbox.class);
  private boolean initialized = false;
  private XulDomContainer xulDomContainer;

  private String binding;

  private int[] curSelectedIndices = new int[0];
  
  public SwingListbox(Element self, XulComponent parent, XulDomContainer container, String tagName) {
    super(tagName);
    model = new DefaultListModel();
    listBox = new JList(model);
    scrollPane = new JScrollPane(listBox);
    listBox.setBorder(BorderFactory.createLineBorder(Color.gray));
    listBox.addListSelectionListener(this);
    managedObject = scrollPane;
    this.xulDomContainer = container;
  }
  
  public Object getManagedObject(){
    return this.managedObject;
  }

  public boolean isDisabled() {
    return !this.listBox.isEnabled();
  }

  public void setDisabled(boolean disabled) {
    this.listBox.setEnabled(!disabled);
  }
  public void setDisabled(String disabled) {
    this.listBox.setEnabled(!Boolean.parseBoolean(disabled));
  }

  public int getRows() {
    return rowsToDisplay;
  }

  public void setRows(int rowsToDisplay) {
    this.rowsToDisplay = rowsToDisplay;
    this.listBox.setVisibleRowCount(rowsToDisplay);
  }

  public String getSeltype() {
    return selType;
  }

  public void setSeltype(String selType) {
    this.selType = selType;
    SEL_TYPE sel = SEL_TYPE.valueOf(selType.toUpperCase());
    if(sel == SEL_TYPE.SINGLE){
      this.listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    } else {
      this.listBox.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }
    
  }

  public Orient getOrientation() {
    return null;
  }
  
  public void layout(){
   
    for(Element comp : getChildNodes()){
      if(comp instanceof SwingListitem){
        this.model.addElement(comp);
        logger.info("added swingListitem to model");
      }
    }
    this.scrollPane.setMinimumSize(new Dimension(this.width, this.height));
    if(this.selectedIndex > -1){
      this.listBox.setSelectedIndex(selectedIndex);
    }
    initialized = true;
  }

  public String getOnselect() {
    return onselect;
  }

  public void setOnselect(String onchange) {
    this.onselect = onchange;<commit_msg>clear out listbox model before re-adding elements<commit_after>package org.pentaho.ui.xul.swing.tags;

import java.awt.Color;
import java.awt.Dimension;
import java.beans.Expression;
import java.util.Arrays;
import java.util.Collection;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.containers.XulListbox;
import org.pentaho.ui.xul.dom.Element;
import org.pentaho.ui.xul.swing.AbstractSwingContainer;
import org.pentaho.ui.xul.swing.SwingElement;
import org.pentaho.ui.xul.util.Orient;

public class SwingListbox extends AbstractSwingContainer implements XulListbox, ListSelectionListener{
  private static final long serialVersionUID = 3064125049914932493L;

  private JList listBox;
  private DefaultListModel model;
  private boolean disabled = false;
  private String selType;
  private int rowsToDisplay = 0;
  private String onselect;
  private JScrollPane scrollPane;
  private static final Log logger = LogFactory.getLog(SwingListbox.class);
  private boolean initialized = false;
  private XulDomContainer xulDomContainer;

  private String binding;

  private int[] curSelectedIndices = new int[0];
  
  public SwingListbox(Element self, XulComponent parent, XulDomContainer container, String tagName) {
    super(tagName);
    model = new DefaultListModel();
    listBox = new JList(model);
    scrollPane = new JScrollPane(listBox);
    listBox.setBorder(BorderFactory.createLineBorder(Color.gray));
    listBox.addListSelectionListener(this);
    managedObject = scrollPane;
    this.xulDomContainer = container;
  }
  
  public Object getManagedObject(){
    return this.managedObject;
  }

  public boolean isDisabled() {
    return !this.listBox.isEnabled();
  }

  public void setDisabled(boolean disabled) {
    this.listBox.setEnabled(!disabled);
  }
  public void setDisabled(String disabled) {
    this.listBox.setEnabled(!Boolean.parseBoolean(disabled));
  }

  public int getRows() {
    return rowsToDisplay;
  }

  public void setRows(int rowsToDisplay) {
    this.rowsToDisplay = rowsToDisplay;
    this.listBox.setVisibleRowCount(rowsToDisplay);
  }

  public String getSeltype() {
    return selType;
  }

  public void setSeltype(String selType) {
    this.selType = selType;
    SEL_TYPE sel = SEL_TYPE.valueOf(selType.toUpperCase());
    if(sel == SEL_TYPE.SINGLE){
      this.listBox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    } else {
      this.listBox.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    }
    
  }

  public Orient getOrientation() {
    return null;
  }
  
  public void layout(){
    this.model.clear();
    for(Element comp : getChildNodes()){
      if(comp instanceof SwingListitem){
        this.model.addElement(comp);
        logger.info("added swingListitem to model");
      }
    }
    this.scrollPane.setMinimumSize(new Dimension(this.width, this.height));
    if(this.selectedIndex > -1){
      this.listBox.setSelectedIndex(selectedIndex);
    }
    initialized = true;
  }

  public String getOnselect() {
    return onselect;
  }

  public void setOnselect(String onchange) {
    this.onselect = onchange;
{'fraction_non_alphanumeric': 0.09503901895206243, 'fraction_numerical': 0.006131549609810479, 'mean_word_length': 4.367988032909499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1891393', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2176, 'n_words': 446}