<commit_before>package com.vaadin.components.grid.table;

import static com.google.gwt.query.client.GQuery.$;

import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.query.client.plugins.observe.Observe;
import com.google.gwt.query.client.plugins.observe.Observe.Changes.MutationRecord;
import com.google.gwt.query.client.plugins.observe.Observe.MutationListener;
import com.google.gwt.user.client.Timer;
import com.vaadin.client.widgets.Grid;
import com.vaadin.client.widgets.Grid.Column;
import com.vaadin.client.widgets.Grid.StaticSection.StaticCell;
import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
import com.vaadin.components.common.js.JS;
import com.vaadin.components.common.js.JSArray;
import com.vaadin.components.common.js.JSValidate;
import com.vaadin.components.grid.GridComponent;
import com.vaadin.components.grid.config.JSColumn;
import com.vaadin.components.grid.config.JSStaticCell;
import com.vaadin.components.grid.data.GridDomTableDataSource;

/**
 * This class represents a grid header configuration based on a DOM structure.
 */
public class GridLightDomTable implements MutationListener {

    private String lastConfigString = null;
    private final GQuery $light;
    private GQuery $thead;
    private GQuery $tfoot;
    private GQuery $head_tr;
    private GQuery $foot_tr;
    private final Grid<Object> grid;
    private final GridComponent gridComponent;
    protected final JSArray<JSColumn> jsColumns = JSArray.createArray().cast();
    int defaultHeaderRow, numberHeaderRows, numberColumns, numberFooterRows;
    private final GridDomTableDataSource ds;

    public GridLightDomTable(Element tableElement, GridComponent grid) {
        this.gridComponent = grid;
        this.grid = grid.getGrid();

        ds = GridDomTableDataSource.createInstance(tableElement, gridComponent);
        $light = $(tableElement);

        parseDom();

        $light.as(Observe.Observe).mutation(
                Observe.createMutationInit().attributes(true).childList(true)
                        .subtree(true), this);
    }

    public void parseDom() {
        $thead = $light.find("thead");
        if ($thead.isEmpty()) {
            $thead = $("<thead>").appendTo($light);
        }
        $tfoot = $light.find("tfoot");
        if ($tfoot.isEmpty()) {
            $tfoot = $("<tfoot>").appendTo($light);
        }
        String txt = $thead.toString() + $tfoot.toString();
        if (!txt.equals(lastConfigString)) {
            lastConfigString = txt;

            $head_tr = $thead.find("tr");
            $foot_tr = $tfoot.find("tr");
            numberHeaderRows = $head_tr.size();
            numberFooterRows = $foot_tr.size();

            // Create the jsColumns array
            configureColumns();

            // We need to set columns to the grid before configuring
            // headers or footers
            gridComponent.setColumns(jsColumns);

            if (numberColumns > 0) {
                if (numberHeaderRows > 0) {
                    // Configure Headers
                    configureHeadersFooters(true);
                }
                if (numberFooterRows > 0) {
                    // Configure Footers
                    configureHeadersFooters(false);
                }
            }
        }
    }

    private void configureColumns() {
        // Clear columns array
        jsColumns.setLength(0);
        for (int i = 0; i < numberHeaderRows; i++) {
            GQuery $ths = $head_tr.eq(i).children("th, td");

            JSArray<Object> contents = JSArray.createArray().cast();
            for (int j = 0; j < $ths.size(); j++) {
                if (jsColumns.size() <= j) {
                    JSColumn column = JS.createJsType(JSColumn.class);
                    jsColumns.add(column);
                }
                contents.add($ths.eq(j).html());
            }
            // The default row should be the last row in the header which has
            // the largest number of th elements, or the last header row which
            // contains a th element with the sortable attribute
            if (!$ths.filter("[sortable]").isEmpty()
                    || $ths.size() == jsColumns.size()) {
                defaultHeaderRow = i;<commit_msg><th> name attribute should be mapped to correct property in columns<commit_after>package com.vaadin.components.grid.table;

import static com.google.gwt.query.client.GQuery.$;

import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.query.client.Function;
import com.google.gwt.query.client.GQuery;
import com.google.gwt.query.client.js.JsUtils;
import com.google.gwt.query.client.plugins.observe.Observe;
import com.google.gwt.query.client.plugins.observe.Observe.Changes.MutationRecord;
import com.google.gwt.query.client.plugins.observe.Observe.MutationListener;
import com.google.gwt.user.client.Timer;
import com.vaadin.client.widgets.Grid;
import com.vaadin.client.widgets.Grid.Column;
import com.vaadin.client.widgets.Grid.StaticSection.StaticCell;
import com.vaadin.client.widgets.Grid.StaticSection.StaticRow;
import com.vaadin.components.common.js.JS;
import com.vaadin.components.common.js.JSArray;
import com.vaadin.components.common.js.JSValidate;
import com.vaadin.components.grid.GridComponent;
import com.vaadin.components.grid.config.JSColumn;
import com.vaadin.components.grid.config.JSStaticCell;
import com.vaadin.components.grid.data.GridDomTableDataSource;

/**
 * This class represents a grid header configuration based on a DOM structure.
 */
public class GridLightDomTable implements MutationListener {

    private String lastConfigString = null;
    private final GQuery $light;
    private GQuery $thead;
    private GQuery $tfoot;
    private GQuery $head_tr;
    private GQuery $foot_tr;
    private final Grid<Object> grid;
    private final GridComponent gridComponent;
    protected final JSArray<JSColumn> jsColumns = JSArray.createArray().cast();
    int defaultHeaderRow, numberHeaderRows, numberColumns, numberFooterRows;
    private final GridDomTableDataSource ds;

    public GridLightDomTable(Element tableElement, GridComponent grid) {
        this.gridComponent = grid;
        this.grid = grid.getGrid();

        ds = GridDomTableDataSource.createInstance(tableElement, gridComponent);
        $light = $(tableElement);

        parseDom();

        $light.as(Observe.Observe).mutation(
                Observe.createMutationInit().attributes(true).childList(true)
                        .subtree(true), this);
    }

    public void parseDom() {
        $thead = $light.find("thead");
        if ($thead.isEmpty()) {
            $thead = $("<thead>").appendTo($light);
        }
        $tfoot = $light.find("tfoot");
        if ($tfoot.isEmpty()) {
            $tfoot = $("<tfoot>").appendTo($light);
        }
        String txt = $thead.toString() + $tfoot.toString();
        if (!txt.equals(lastConfigString)) {
            lastConfigString = txt;

            $head_tr = $thead.find("tr");
            $foot_tr = $tfoot.find("tr");
            numberHeaderRows = $head_tr.size();
            numberFooterRows = $foot_tr.size();

            // Create the jsColumns array
            configureColumns();

            // We need to set columns to the grid before configuring
            // headers or footers
            gridComponent.setColumns(jsColumns);

            if (numberColumns > 0) {
                if (numberHeaderRows > 0) {
                    // Configure Headers
                    configureHeadersFooters(true);
                }
                if (numberFooterRows > 0) {
                    // Configure Footers
                    configureHeadersFooters(false);
                }
            }
        }
    }

    private void configureColumns() {
        // Clear columns array
        jsColumns.setLength(0);
        for (int i = 0; i < numberHeaderRows; i++) {
            GQuery $ths = $head_tr.eq(i).children("th, td");

            JSArray<Object> contents = JSArray.createArray().cast();
            for (int j = 0; j < $ths.size(); j++) {
                if (jsColumns.size() <= j) {
                    JSColumn column = JS.createJsType(JSColumn.class);
                    String name = $ths.eq(j).attr("name");
                    if (!name.isEmpty()) {
                        column.setName(name);
                    }
                    jsColumns.add(column);
                }
                contents.add($ths.eq(j).html());
            }
            // The default row should be the last row in the header which has
            // the largest number of th elements, or the last header row which
            // contains a th element with the sortable attribute
            if (!$ths.filter("[sortable]").isEmpty()
                    || $ths.size() == jsColumns.size()) {
                defaultHeaderRow = i;
{'fraction_non_alphanumeric': 0.11505681818181818, 'fraction_numerical': 0.0013111888111888112, 'mean_word_length': 2.3405109489051097, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, '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': '1378476', 'n_tokens_mistral': 2620, 'n_tokens_neox': 2491, 'n_words': 545}