<commit_before>/*
 * Copyright (c) 2008-2014 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.gui.components.filter;

import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.filter.condition.AbstractCondition;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;

/**
 * @author krivopustov
 * @version $Id$
 */
public class ParamEditor implements AbstractCondition.Listener {

    protected AbstractCondition condition;
    protected Component field;
    protected String fieldWidth = null;
    protected BoxLayout mainLayout;
    protected Label captionLbl;
    protected Component operationEditor;
    protected Component paramEditComponent;
    protected final LinkButton removeButton;

    public ParamEditor(final AbstractCondition condition, boolean removeButtonVisible) {
        this.condition = condition;

        ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
        mainLayout = componentsFactory.createComponent(BoxLayout.HBOX);
        mainLayout.setWidth("100%");
        mainLayout.setSpacing(true);

        captionLbl = componentsFactory.createComponent(Label.NAME);
        captionLbl.setAlignment(Component.Alignment.MIDDLE_LEFT);
        captionLbl.setValue(condition.getLocCaption());
        mainLayout.add(captionLbl);

        operationEditor = condition.createOperationEditor().getComponent();
        operationEditor.setAlignment(Component.Alignment.MIDDLE_LEFT);
        mainLayout.add(operationEditor);

        paramEditComponent = condition.getParam().createEditComponent(Param.ValueProperty.VALUE);
        paramEditComponent.setAlignment(Component.Alignment.MIDDLE_LEFT);
        if (paramEditComponent instanceof Field)
            ((Field) paramEditComponent).setRequired(condition.getRequired());
        mainLayout.add(paramEditComponent);
        mainLayout.expand(paramEditComponent);

        removeButton = componentsFactory.createComponent(LinkButton.NAME);
        removeButton.setIcon("icons/item-remove.png");
        removeButton.setAlignment(Component.Alignment.MIDDLE_LEFT);
        removeButton.setVisible(removeButtonVisible);
        mainLayout.add(removeButton);

        condition.addListener(this);
    }

    @Override
    public void paramChanged() {
        Component oldParamEditComponent = paramEditComponent;
        mainLayout.remove(paramEditComponent);
        paramEditComponent = condition.getParam().createEditComponent(Param.ValueProperty.VALUE);
        if (paramEditComponent instanceof Field) {
            ((Field) paramEditComponent).setRequired(condition.getRequired());
            if (paramEditComponent.getClass().equals(oldParamEditComponent.getClass())) {<commit_msg>Components for Date and Boolean filter parameters are not expanded #PL-4488<commit_after>/*
 * Copyright (c) 2008-2014 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.gui.components.filter;

import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.gui.components.filter.condition.AbstractCondition;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;

import java.util.Date;

/**
 * @author krivopustov
 * @version $Id$
 */
public class ParamEditor implements AbstractCondition.Listener {

    protected AbstractCondition condition;
    protected Component field;
    protected String fieldWidth = null;
    protected BoxLayout mainLayout;
    protected Label captionLbl;
    protected Component operationEditor;
    protected Component paramEditComponent;
    protected final LinkButton removeButton;

    public ParamEditor(final AbstractCondition condition, boolean removeButtonVisible) {
        this.condition = condition;

        ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.class);
        mainLayout = componentsFactory.createComponent(BoxLayout.HBOX);
        mainLayout.setWidth("100%");
        mainLayout.setSpacing(true);

        captionLbl = componentsFactory.createComponent(Label.NAME);
        captionLbl.setAlignment(Component.Alignment.MIDDLE_LEFT);
        captionLbl.setValue(condition.getLocCaption());
        mainLayout.add(captionLbl);

        operationEditor = condition.createOperationEditor().getComponent();
        operationEditor.setAlignment(Component.Alignment.MIDDLE_LEFT);
        mainLayout.add(operationEditor);

        paramEditComponent = condition.getParam().createEditComponent(Param.ValueProperty.VALUE);
        paramEditComponent.setAlignment(Component.Alignment.MIDDLE_LEFT);
        if (paramEditComponent instanceof Field)
            ((Field) paramEditComponent).setRequired(condition.getRequired());
        if (Date.class.isAssignableFrom(condition.getParam().getJavaClass()) || Boolean.class.isAssignableFrom(condition.getParam().getJavaClass())) {
            HBoxLayout componentEditLayout = componentsFactory.createComponent(HBoxLayout.class);
            componentEditLayout.add(paramEditComponent);
            paramEditComponent.setAlignment(Component.Alignment.MIDDLE_LEFT);
            mainLayout.add(componentEditLayout);
            mainLayout.expand(componentEditLayout);
        } else {
            mainLayout.add(paramEditComponent);
            mainLayout.expand(paramEditComponent);
        }

        removeButton = componentsFactory.createComponent(LinkButton.NAME);
        removeButton.setIcon("icons/item-remove.png");
        removeButton.setAlignment(Component.Alignment.MIDDLE_LEFT);
        removeButton.setVisible(removeButtonVisible);
        mainLayout.add(removeButton);

        condition.addListener(this);
    }

    @Override
    public void paramChanged() {
        Component oldParamEditComponent = paramEditComponent;
        mainLayout.remove(paramEditComponent);
        paramEditComponent = condition.getParam().createEditComponent(Param.ValueProperty.VALUE);
        if (paramEditComponent instanceof Field) {
            ((Field) paramEditComponent).setRequired(condition.getRequired());
            if (paramEditComponent.getClass().equals(oldParamEditComponent.getClass())) {
{'fraction_non_alphanumeric': 0.09345351043643264, 'fraction_numerical': 0.004111321948134092, 'mean_word_length': 4.01984126984127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6989144', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1566, 'n_words': 269}