<commit_before>package org.vaadin.maddon.fields;

import java.util.Collection;

import com.vaadin.data.Container;
import com.vaadin.data.Property;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Field;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TwinColSelect;
import java.util.Arrays;
import org.vaadin.maddon.ListContainer;

/**
 * A select implementation with better typed API than in core Vaadin.
 *
 * By default the options toString is used to generate the caption for option.
 * To override this behavior, use setCaptionGenerator or override getCaption(T)
 * to provide your own strategy.
 * <p>
 * Behind the scenes uses Vaadin cores NativeSelect (default) or other cores
 * AbstractSelect implementation, type provided in constructor. Tree and Table
 * are not supported, see MTable.
 * <p>
 * Note, that this select is always in single select mode. See CollectionSelect
 * for "multiselect".
 *
 * @author mstahv
 * @param <T> the type of selects value
 */
public class TypedSelect<T> extends CustomComponent implements Field<T> {
    
    private CaptionGenerator<T> captionGenerator;
    
    private AbstractSelect select;
    
    private ListContainer<T> bic;
    
    private Class<T> fieldType;
    
    public TypedSelect(Class<T> type) {
        this.fieldType = type;
        bic = new ListContainer<T>(type);
    }

    /**
     * Note, that with this constructor, you cannot override the select type.
     * @param options options to select from
     */
    public TypedSelect(T... options) {
        setOptions(options);
    }
    
    public TypedSelect(String caption) {
        setCaption(caption);
    }

    /**
     * Note, that with this constructor, you cannot override the select type.
     */
    public TypedSelect(String caption, Collection<T> listAllStyles) {
        this(caption);
        setOptions(listAllStyles);
    }
    
    public TypedSelect<T> withCaption(String caption) {<commit_msg>TypedSelect style and width propagated properly<commit_after>package org.vaadin.maddon.fields;

import java.util.Collection;

import com.vaadin.data.Container;
import com.vaadin.data.Property;
import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.ui.AbstractSelect;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Field;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.OptionGroup;
import com.vaadin.ui.TwinColSelect;
import java.util.Arrays;
import org.vaadin.maddon.ListContainer;

/**
 * A select implementation with better typed API than in core Vaadin.
 *
 * By default the options toString is used to generate the caption for option.
 * To override this behavior, use setCaptionGenerator or override getCaption(T)
 * to provide your own strategy.
 * <p>
 * Behind the scenes uses Vaadin cores NativeSelect (default) or other cores
 * AbstractSelect implementation, type provided in constructor. Tree and Table
 * are not supported, see MTable.
 * <p>
 * Note, that this select is always in single select mode. See CollectionSelect
 * for "multiselect".
 *
 * @author mstahv
 * @param <T> the type of selects value
 */
public class TypedSelect<T> extends CustomComponent implements Field<T> {
    
    private CaptionGenerator<T> captionGenerator;
    
    private AbstractSelect select;
    
    private ListContainer<T> bic;
    
    private Class<T> fieldType;
    
    public TypedSelect(Class<T> type) {
        this.fieldType = type;
        bic = new ListContainer<T>(type);
    }

    /**
     * Note, that with this constructor, you cannot override the select type.
     * @param options options to select from
     */
    public TypedSelect(T... options) {
        setOptions(options);
    }
    
    public TypedSelect(String caption) {
        setCaption(caption);
    }
    
    /**
     * {@inheritDoc}
     * 
     * Sets the width of the wrapped select component.
     * 
     * @param width
     * @param unit
     */
    @Override
    public void setWidth(float width, Unit unit) {
    	getSelect().setWidth(width, unit);
    }
    
    /**
     * {@inheritDoc}
     * 
     * Adds a style to the wrapped select.
     */
    @Override
    public void addStyleName(String style) {
    	getSelect().addStyleName(style);
    }
    
    /**
     * {@inheritDoc}
     * 
     * Sets the style of the wrapped select.
     */
    @Override
    public void setStyleName(String style) {
    	getSelect().setStyleName(style);
    }
    

    /**
     * Note, that with this constructor, you cannot override the select type.
     */
    public TypedSelect(String caption, Collection<T> listAllStyles) {
        this(caption);
        setOptions(listAllStyles);
    }
    
    public TypedSelect<T> withCaption(String caption) {
{'fraction_non_alphanumeric': 0.0925632911392405, 'fraction_numerical': 0.0, 'mean_word_length': 3.1382978723404253, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '5040885', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1463, 'n_words': 447}