<commit_before>/*
 * Copyright (c) 2016, Mirante and/or its affiliates. All rights reserved.
 * Mirante PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package br.net.mirante.singular.form.wicket;

import br.net.mirante.singular.form.SInstance;
import br.net.mirante.singular.form.context.UIComponentMapper;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateChoiceBehavior;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateInputBehavior;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateSingularFormComponentPanel;
import br.net.mirante.singular.form.wicket.component.SingularFormComponentPanel;
import br.net.mirante.singular.util.wicket.jquery.JQuery;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
import org.apache.wicket.markup.html.form.CheckGroup;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.model.IModel;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

import static br.net.mirante.singular.util.wicket.util.Shortcuts.$b;

@FunctionalInterface
public interface IWicketComponentMapper extends UIComponentMapper {

    /*  Evento utilizado para capturar mudanças via change ou blur sem chamadas repetidas.
     *  Esse evento é utilizado em alguns js da aplicação, para mudar o nome é preciso fazer uma varredura de texto.
     */
    static final String SINNGULAR_BLUR_CHANGE_EVENT = "singular:blurchange";

    static final Behavior SINGULAR_BLUR_CHANGE_DEBOUNCER = $b.onReadyScript(
            comp -> JQuery.$(comp) + ".on('change blur', function (e) {                                               \n" +
                    "            clearTimeout($(this).data('blurChangeTimeout'));                                     \n" +
                    "            $(this).data('blurChangeTimeout', setTimeout(                                        \n" +
                    "                   function() {                                                                  \n" +
                    "                   " + JQuery.$(comp) + ".trigger('" + SINNGULAR_BLUR_CHANGE_EVENT + "', e)" + " \n" +
                    "                   }                                                                             \n" +
                    "              , 100));//100 ms para debounce                                                     \n" +
                    "});");

    static final Behavior SINGULAR_FORM_GROUP_HEIGHT_FIX = $b.onReadyScript(
            comp -> "$('[snglr] .form-group').css('min-height',            \n" +
                    "   Math.max.apply(null,                               \n" +
                    "       $('[snglr] .form-group').map(                  \n" +
                    "           function () {                              \n" +
                    "               return $(this).height();               \n" +
                    "            }                                         \n" +
                    "       ).get()                                        \n" +
                    "   )                                                  \n" +
                    ")                                                     \n"
    );

    void buildView(WicketBuildContext ctx);

    default void addAjaxUpdate(Component component, IModel<SInstance> model, IAjaxUpdateListener listener) {
        component.setOutputMarkupId(true);
        if ((component instanceof RadioChoice) ||
                (component instanceof CheckBoxMultipleChoice) ||
                (component instanceof RadioGroup) ||
                (component instanceof CheckGroup)) {
            component.add(new AjaxUpdateChoiceBehavior(model, listener));
            component.add(SINGULAR_FORM_GROUP_HEIGHT_FIX);
        } else if (component instanceof SingularFormComponentPanel) {
            component.add(new AjaxUpdateSingularFormComponentPanel(model, listener));
        } else if (!(component instanceof FormComponentPanel<?>)) {
            component.add(SINGULAR_BLUR_CHANGE_DEBOUNCER);
            component.add(new AjaxUpdateInputBehavior(SINNGULAR_BLUR_CHANGE_EVENT, model, listener));
            component.add(SINGULAR_FORM_GROUP_HEIGHT_FIX);
        } else {
            LoggerFactory.getLogger(WicketBuildContext.class).warn("Atualização ajax não suportada para " + component);
        }
    }

    default boolean updateOnChange() {
        return true;
    }<commit_msg>[LAYOUT] removendo fix de altura no layout<commit_after>/*
 * Copyright (c) 2016, Mirante and/or its affiliates. All rights reserved.
 * Mirante PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package br.net.mirante.singular.form.wicket;

import br.net.mirante.singular.form.SInstance;
import br.net.mirante.singular.form.context.UIComponentMapper;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateChoiceBehavior;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateInputBehavior;
import br.net.mirante.singular.form.wicket.behavior.AjaxUpdateSingularFormComponentPanel;
import br.net.mirante.singular.form.wicket.component.SingularFormComponentPanel;
import br.net.mirante.singular.util.wicket.jquery.JQuery;
import org.apache.wicket.Component;
import org.apache.wicket.behavior.Behavior;
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
import org.apache.wicket.markup.html.form.CheckGroup;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.model.IModel;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

import static br.net.mirante.singular.util.wicket.util.Shortcuts.$b;

@FunctionalInterface
public interface IWicketComponentMapper extends UIComponentMapper {

    /*  Evento utilizado para capturar mudanças via change ou blur sem chamadas repetidas.
     *  Esse evento é utilizado em alguns js da aplicação, para mudar o nome é preciso fazer uma varredura de texto.
     */
    static final String SINNGULAR_BLUR_CHANGE_EVENT = "singular:blurchange";

    static final Behavior SINGULAR_BLUR_CHANGE_DEBOUNCER = $b.onReadyScript(
            comp -> JQuery.$(comp) + ".on('change blur', function (e) {                                               \n" +
                    "            clearTimeout($(this).data('blurChangeTimeout'));                                     \n" +
                    "            $(this).data('blurChangeTimeout', setTimeout(                                        \n" +
                    "                   function() {                                                                  \n" +
                    "                   " + JQuery.$(comp) + ".trigger('" + SINNGULAR_BLUR_CHANGE_EVENT + "', e)" + " \n" +
                    "                   }                                                                             \n" +
                    "              , 100));//100 ms para debounce                                                     \n" +
                    "});");

    static final Behavior SINGULAR_FORM_GROUP_HEIGHT_FIX = $b.onReadyScript(
            comp -> "$('[snglr] .form-group').css('min-height',            \n" +
                    "   Math.max.apply(null,                               \n" +
                    "       $('[snglr] .form-group').map(                  \n" +
                    "           function () {                              \n" +
                    "               return $(this).height();               \n" +
                    "            }                                         \n" +
                    "       ).get()                                        \n" +
                    "   )                                                  \n" +
                    ")                                                     \n"
    );

    void buildView(WicketBuildContext ctx);

    default void addAjaxUpdate(Component component, IModel<SInstance> model, IAjaxUpdateListener listener) {
        component.setOutputMarkupId(true);
        if ((component instanceof RadioChoice) ||
                (component instanceof CheckBoxMultipleChoice) ||
                (component instanceof RadioGroup) ||
                (component instanceof CheckGroup)) {
            component.add(new AjaxUpdateChoiceBehavior(model, listener));
//            component.add(SINGULAR_FORM_GROUP_HEIGHT_FIX);
        } else if (component instanceof SingularFormComponentPanel) {
            component.add(new AjaxUpdateSingularFormComponentPanel(model, listener));
        } else if (!(component instanceof FormComponentPanel<?>)) {
            component.add(SINGULAR_BLUR_CHANGE_DEBOUNCER);
            component.add(new AjaxUpdateInputBehavior(SINNGULAR_BLUR_CHANGE_EVENT, model, listener));
//            component.add(SINGULAR_FORM_GROUP_HEIGHT_FIX);
        } else {
            LoggerFactory.getLogger(WicketBuildContext.class).warn("Atualização ajax não suportada para " + component);
        }
    }

    default boolean updateOnChange() {
        return true;
    }
{'fraction_non_alphanumeric': 0.09735177441835531, 'fraction_numerical': 0.002358743433043851, 'mean_word_length': 1.6283460129613976, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 56, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1093919', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2325, 'n_words': 436}