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

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.FooterClickEvent;
import com.vaadin.ui.Table.FooterClickListener;
import com.vaadin.ui.Table.HeaderClickEvent;
import com.vaadin.ui.Table.HeaderClickListener;

public class HeaderFooterClickLeftRightMiddle extends TestBase {

    private Log log = new Log(10);

    @Override
    protected void setup() {
        final Table table = new Table();
        table.setColumnReorderingAllowed(true);
        table.setContainerDataSource(createContainer());
        table.setWidth("400px");
        table.setHeight("400px");
        table.setImmediate(true);
        table.setFooterVisible(true);

        CheckBox immediateCheckbox = new CheckBox("Immediate");
        immediateCheckbox.setImmediate(true);
        immediateCheckbox.setValue(table.isImmediate());
        immediateCheckbox.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                table.setImmediate(event.getButton().booleanValue());
            }
        });

        CheckBox headerClickListenerCheckbox = new CheckBox(
                "Header click listener");
        headerClickListenerCheckbox.setImmediate(true);
        headerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private HeaderClickListener headerClickListener = new HeaderClickListener() {

                public void headerClick(HeaderClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on header "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }

            };

            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(HeaderClickEvent.class).isEmpty()) {
                    table.addListener(headerClickListener);
                } else {
                    table.removeListener(headerClickListener);
                }
            }
        });
        headerClickListenerCheckbox.setValue(true);

        CheckBox footerClickListenerCheckbox = new CheckBox(
                "Footer click listener");
        footerClickListenerCheckbox.setImmediate(true);
        footerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private FooterClickListener footerClickListener = new FooterClickListener() {

                public void footerClick(FooterClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on footer "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }
            };

            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(FooterClickEvent.class).isEmpty()) {
                    table.addListener(footerClickListener);
                } else {
                    table.removeListener(footerClickListener);
                }
            }
        });
        footerClickListenerCheckbox.setValue(true);

        CheckBox sortEnabledCheckbox = new CheckBox("Sortable");
        sortEnabledCheckbox.setImmediate(true);
        sortEnabledCheckbox.setValue(!table.isSortDisabled());
        sortEnabledCheckbox.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                table.setSortDisabled(!event.getButton().booleanValue());
            }
        });

        CheckBox columnReorderingCheckbox = new CheckBox(
                "Column reordering allowed");
        columnReorderingCheckbox.setImmediate(true);
        columnReorderingCheckbox.setValue(table.isColumnReorderingAllowed());
        columnReorderingCheckbox.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                table.setColumnReorderingAllowed(event.getButton()
                        .booleanValue());
            }
        });

        addComponent(immediateCheckbox);
        addComponent(headerClickListenerCheckbox);
        addComponent(footerClickListenerCheckbox);
        addComponent(sortEnabledCheckbox);<commit_msg>Use value change listeners instead of click listeners for checkboxes<commit_after>package com.vaadin.tests.components.table;

import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.tests.util.Log;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.FooterClickEvent;
import com.vaadin.ui.Table.FooterClickListener;
import com.vaadin.ui.Table.HeaderClickEvent;
import com.vaadin.ui.Table.HeaderClickListener;

public class HeaderFooterClickLeftRightMiddle extends TestBase {

    private Log log = new Log(10);

    @Override
    protected void setup() {
        final Table table = new Table();
        table.setColumnReorderingAllowed(true);
        table.setContainerDataSource(createContainer());
        table.setWidth("400px");
        table.setHeight("400px");
        table.setImmediate(true);
        table.setFooterVisible(true);

        CheckBox immediateCheckbox = new CheckBox("Immediate");
        immediateCheckbox.setImmediate(true);
        immediateCheckbox.setValue(table.isImmediate());
        immediateCheckbox.addListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                table.setImmediate((Boolean) event.getProperty().getValue());
            }
        });

        CheckBox headerClickListenerCheckbox = new CheckBox(
                "Header click listener");
        headerClickListenerCheckbox.setImmediate(true);
        headerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private HeaderClickListener headerClickListener = new HeaderClickListener() {

                public void headerClick(HeaderClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on header "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }

            };

            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(HeaderClickEvent.class).isEmpty()) {
                    table.addListener(headerClickListener);
                } else {
                    table.removeListener(headerClickListener);
                }
            }
        });
        headerClickListenerCheckbox.setValue(true);

        CheckBox footerClickListenerCheckbox = new CheckBox(
                "Footer click listener");
        footerClickListenerCheckbox.setImmediate(true);
        footerClickListenerCheckbox.addListener(new ValueChangeListener() {

            private FooterClickListener footerClickListener = new FooterClickListener() {

                public void footerClick(FooterClickEvent event) {
                    String type = event.isDoubleClick() ? "Double click"
                            : "Click";
                    log.log(type + " on footer "
                            + event.getPropertyId().toString() + " using "
                            + event.getButtonName());
                }
            };

            public void valueChange(ValueChangeEvent event) {
                if (table.getListeners(FooterClickEvent.class).isEmpty()) {
                    table.addListener(footerClickListener);
                } else {
                    table.removeListener(footerClickListener);
                }
            }
        });
        footerClickListenerCheckbox.setValue(true);

        CheckBox sortEnabledCheckbox = new CheckBox("Sortable");
        sortEnabledCheckbox.setImmediate(true);
        sortEnabledCheckbox.setValue(!table.isSortDisabled());
        sortEnabledCheckbox.addListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                table.setSortDisabled(!event.getButton().booleanValue());
            }
        });

        CheckBox columnReorderingCheckbox = new CheckBox(
                "Column reordering allowed");
        columnReorderingCheckbox.setImmediate(true);
        columnReorderingCheckbox.setValue(table.isColumnReorderingAllowed());
        columnReorderingCheckbox.addListener(new ValueChangeListener() {

            public void valueChange(ValueChangeEvent event) {
                table.setColumnReorderingAllowed((Boolean) event.getProperty()
                        .getValue());
            }
        });

        addComponent(immediateCheckbox);
        addComponent(headerClickListenerCheckbox);
        addComponent(footerClickListenerCheckbox);
        addComponent(sortEnabledCheckbox);
{'fraction_non_alphanumeric': 0.08969445882962196, 'fraction_numerical': 0.0016571724495080269, 'mean_word_length': 2.286589516678012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4049101', 'n_tokens_mistral': 2385, 'n_tokens_neox': 2256, 'n_words': 382}