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

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.containers.XulTree;
import org.pentaho.ui.xul.containers.XulTreeChildren;
import org.pentaho.ui.xul.containers.XulTreeCols;
import org.pentaho.ui.xul.containers.XulTreeRow;
import org.pentaho.ui.xul.dom.Element;
import org.pentaho.ui.xul.swt.SwtElement;
import org.pentaho.ui.xul.swt.TableSelection;
import org.pentaho.ui.xul.swt.TabularWidget;
import org.pentaho.ui.xul.swt.custom.TableWrapper;
import org.pentaho.ui.xul.swt.custom.TreeWrapper;

public class SwtTree extends SwtElement implements XulTree {

  // Tables and trees 
  // share so much of the same API, I wrapped their common methods 
  // into an interface (TabularWidget) and set the component to two
  // separate member variables here so that I don't have to reference 
  // them separately.  
	
	private static final Log logger = LogFactory.getLog(SwtTree.class);
  
	protected TabularWidget widget;

  protected Composite tree;

  protected XulTreeCols columns = null;

  protected XulTreeChildren rootChildren = null;

  protected XulComponent parentComponent = null;
  
  private Object data = null;

  private boolean disabled = false;

  private boolean enableColumnDrag = false;

  private boolean editable = false;
  
  private String onedit;

  private String onSelect = null;

  private int rowsToDisplay = 0;

  private TableSelection selType = TableSelection.SINGLE;

  private boolean isHierarchical = false;
  
  private int activeRow = -1;
  private int activeColumn = -1;
  

  public SwtTree(Element self, XulComponent parent, XulDomContainer container, String tagName) {
    super(tagName);
    this.parentComponent = parent;
    
    // According to XUL spec, in order for a hierarchical tree to be rendered, a 
    // primary column must be identified AND at least one treeitem must be listed as a container. 

    XulComponent primaryColumn = getElementByXPath("//treecol[@primary='true']");
    XulComponent isaContainer = getElementByXPath("//treeitem[@container='true']");

    isHierarchical = (primaryColumn != null) && (isaContainer != null);

    widget = isHierarchical ? new TreeWrapper(selType, (Composite) parent.getManagedObject(), this) : 
                              new TableWrapper(selType, (Composite) parent.getManagedObject(), this);

    tree = widget.getComposite();

    managedObject = tree;
  }

  public boolean isHierarchical() {
    return isHierarchical;
  }

  public boolean isDisabled() {
    return disabled;
  }

  public void setDisabled(boolean disabled) {
    this.disabled = disabled;
    if (!tree.isDisposed())
      tree.setEnabled(!disabled);
  }

  public int getRows() {
    return rowsToDisplay;
  }

  public void setRows(int rowsToDisplay) {
    this.rowsToDisplay = rowsToDisplay;
    if ((!tree.isDisposed()) && (rowsToDisplay > 0)) {
      int ht = rowsToDisplay * widget.getItemHeight();
      if (tree.getLayoutData() != null) {
       // tree.setSize(tree.getSize().x,height);
        ((GridData) tree.getLayoutData()).heightHint = ht;
        ((GridData) tree.getLayoutData()).minimumHeight = ht;
        
        tree.getParent().layout(true);
      }
    }
  }

  public String getSeltype() {
    return selType.toString();
  }

  public void setSeltype(String selType) {
    if (selType.equalsIgnoreCase(getSeltype())) {
      return; // nothing has changed
    }
    this.selType = TableSelection.valueOf(selType.toUpperCase());
    tree.dispose();
  }

  public TableSelection getTableSelection() {
    return selType;
  }

  public boolean isEditable() {
    return editable;
  }

  public boolean isEnableColumnDrag() {
    return enableColumnDrag;
  }

  public void setEditable(boolean edit) {
    editable = edit;
  }

  public void setEnableColumnDrag(boolean drag) {
    enableColumnDrag = drag;
  }

  public String getOnselect() {
    return onSelect;
  }

  public void setOnselect(final String method) {
    if (method == null) {
      return;
    }
    onSelect = method;

    if (tree.isDisposed()) {
      return;
    }

    widget.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        invoke(method, new Object[] {new Integer(widget.getSelectionIndex())});
      }
    });
  }

  @Override<commit_msg>onselect invocation passes primative int instead of Integer<commit_after>package org.pentaho.ui.xul.swt.tags;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.pentaho.ui.xul.XulComponent;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.containers.XulTree;
import org.pentaho.ui.xul.containers.XulTreeChildren;
import org.pentaho.ui.xul.containers.XulTreeCols;
import org.pentaho.ui.xul.containers.XulTreeRow;
import org.pentaho.ui.xul.dom.Element;
import org.pentaho.ui.xul.swt.SwtElement;
import org.pentaho.ui.xul.swt.TableSelection;
import org.pentaho.ui.xul.swt.TabularWidget;
import org.pentaho.ui.xul.swt.custom.TableWrapper;
import org.pentaho.ui.xul.swt.custom.TreeWrapper;

public class SwtTree extends SwtElement implements XulTree {

  // Tables and trees 
  // share so much of the same API, I wrapped their common methods 
  // into an interface (TabularWidget) and set the component to two
  // separate member variables here so that I don't have to reference 
  // them separately.  
	
	private static final Log logger = LogFactory.getLog(SwtTree.class);
  
	protected TabularWidget widget;

  protected Composite tree;

  protected XulTreeCols columns = null;

  protected XulTreeChildren rootChildren = null;

  protected XulComponent parentComponent = null;
  
  private Object data = null;

  private boolean disabled = false;

  private boolean enableColumnDrag = false;

  private boolean editable = false;
  
  private String onedit;

  private String onSelect = null;

  private int rowsToDisplay = 0;

  private TableSelection selType = TableSelection.SINGLE;

  private boolean isHierarchical = false;
  
  private int activeRow = -1;
  private int activeColumn = -1;
  

  public SwtTree(Element self, XulComponent parent, XulDomContainer container, String tagName) {
    super(tagName);
    this.parentComponent = parent;
    
    // According to XUL spec, in order for a hierarchical tree to be rendered, a 
    // primary column must be identified AND at least one treeitem must be listed as a container. 

    XulComponent primaryColumn = getElementByXPath("//treecol[@primary='true']");
    XulComponent isaContainer = getElementByXPath("//treeitem[@container='true']");

    isHierarchical = (primaryColumn != null) && (isaContainer != null);

    widget = isHierarchical ? new TreeWrapper(selType, (Composite) parent.getManagedObject(), this) : 
                              new TableWrapper(selType, (Composite) parent.getManagedObject(), this);

    tree = widget.getComposite();

    managedObject = tree;
  }

  public boolean isHierarchical() {
    return isHierarchical;
  }

  public boolean isDisabled() {
    return disabled;
  }

  public void setDisabled(boolean disabled) {
    this.disabled = disabled;
    if (!tree.isDisposed())
      tree.setEnabled(!disabled);
  }

  public int getRows() {
    return rowsToDisplay;
  }

  public void setRows(int rowsToDisplay) {
    this.rowsToDisplay = rowsToDisplay;
    if ((!tree.isDisposed()) && (rowsToDisplay > 0)) {
      int ht = rowsToDisplay * widget.getItemHeight();
      if (tree.getLayoutData() != null) {
       // tree.setSize(tree.getSize().x,height);
        ((GridData) tree.getLayoutData()).heightHint = ht;
        ((GridData) tree.getLayoutData()).minimumHeight = ht;
        
        tree.getParent().layout(true);
      }
    }
  }

  public String getSeltype() {
    return selType.toString();
  }

  public void setSeltype(String selType) {
    if (selType.equalsIgnoreCase(getSeltype())) {
      return; // nothing has changed
    }
    this.selType = TableSelection.valueOf(selType.toUpperCase());
    tree.dispose();
  }

  public TableSelection getTableSelection() {
    return selType;
  }

  public boolean isEditable() {
    return editable;
  }

  public boolean isEnableColumnDrag() {
    return enableColumnDrag;
  }

  public void setEditable(boolean edit) {
    editable = edit;
  }

  public void setEnableColumnDrag(boolean drag) {
    enableColumnDrag = drag;
  }

  public String getOnselect() {
    return onSelect;
  }

  public void setOnselect(final String method) {
    if (method == null) {
      return;
    }
    onSelect = method;

    if (tree.isDisposed()) {
      return;
    }

    widget.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        invoke(method, new Object[] {widget.getSelectionIndex()});
      }
    });
  }

  @Override
{'fraction_non_alphanumeric': 0.10313853957518758, 'fraction_numerical': 0.0008453978653703899, 'mean_word_length': 3.51311397234144, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2392280', 'n_tokens_mistral': 2952, 'n_tokens_neox': 2845, 'n_words': 701}