<commit_before>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
 *                    Desenvolvemento Tecnolóxico de Galicia
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.web.common.components.bandboxsearch;

import static org.navalplanner.web.I18nHelper._;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.navalplanner.web.common.components.finders.FilterPair;
import org.navalplanner.web.common.components.finders.IMultipleFiltersFinder;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.InputEvent;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listheader;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.api.Listbox;

/**
 * @author <NAME> <<EMAIL>>
 */

@SuppressWarnings("serial")
public class BandboxMultipleSearch extends HtmlMacroComponent {

    private Listbox listbox;

    private Listhead listhead;

    private Bandbox bandbox;

    private String widthBandbox;

    private String widthListbox;

    private IMultipleFiltersFinder multipleFiltersFinder;

    private List selectedFilters = new ArrayList();

    private String selectedFiltersText = new String("");

    public void afterCompose() {
        super.afterCompose();
        listbox = (Listbox) getFellowIfAny("listbox");
        listhead = (Listhead) listbox.getFellowIfAny("listhead");
        bandbox = (Bandbox) getFellowIfAny("bandbox");

        if (multipleFiltersFinder != null) {
            listbox.setModel(getSubModel());
            listbox.setItemRenderer(multipleFiltersFinder.getItemRenderer());
            addHeaders();

            /**
             * Search for matching elements while typing on bandbox
             */
            bandbox.addEventListener("onChanging", new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    final String inputText = ((InputEvent) event).getValue();
                    if ((inputText == null) || (inputText.isEmpty())) {
                        clear();
                        searchMultipleFilters();
                    } else {
                        searchMultipleFilters(inputText);
                    }
                }
            });

            /**
             * Pick element from list when selecting
             */
            listbox.addEventListener("onSelect", new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    final Object object = getSelectedItem().getValue();
                    if (multipleFiltersFinder.isValidNewFilter(object)) {
                        addSelectedElement(object);
                        clearListbox();
                    }
                    bandbox.close();
                }
            });
        }

        updateWidth();
    }
<commit_msg> ItEr50S04ValidacionEProbasFuncionaisItEr49S04: [Bug #343]. Added control keys to BandboxMultipleSearch.<commit_after>/*
 * This file is part of NavalPlan
 *
 * Copyright (C) 2009 Fundación para o Fomento da Calidade Industrial e
 *                    Desenvolvemento Tecnolóxico de Galicia
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.navalplanner.web.common.components.bandboxsearch;

import static org.navalplanner.web.I18nHelper._;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.navalplanner.web.common.components.finders.FilterPair;
import org.navalplanner.web.common.components.finders.IMultipleFiltersFinder;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.InputEvent;
import org.zkoss.zul.Bandbox;
import org.zkoss.zul.ListModel;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listheader;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.SimpleListModel;
import org.zkoss.zul.api.Listbox;

/**
 * @author <NAME> <<EMAIL>>
 */

@SuppressWarnings("serial")
public class BandboxMultipleSearch extends HtmlMacroComponent {

    private Listbox listbox;

    private Listhead listhead;

    private Bandbox bandbox;

    private String widthBandbox;

    private String widthListbox;

    private IMultipleFiltersFinder multipleFiltersFinder;

    private List selectedFilters = new ArrayList();

    private String selectedFiltersText = new String("");

    public void afterCompose() {
        super.afterCompose();
        listbox = (Listbox) getFellowIfAny("listbox");
        listhead = (Listhead) listbox.getFellowIfAny("listhead");
        bandbox = (Bandbox) getFellowIfAny("bandbox");

        if (multipleFiltersFinder != null) {
            listbox.setModel(getSubModel());
            listbox.setItemRenderer(multipleFiltersFinder.getItemRenderer());
            addHeaders();

            /**
             * Search for matching elements while typing on bandbox
             */
            bandbox.addEventListener("onChanging", new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    final String inputText = ((InputEvent) event).getValue();
                    if ((inputText == null) || (inputText.isEmpty())) {
                        clear();
                        searchMultipleFilters();
                    } else {
                        searchMultipleFilters(inputText);
                    }
                }
            });

            bandbox.setCtrlKeys("#down");
            bandbox.addEventListener(Events.ON_CTRL_KEY, new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    int selectedItemIndex = listbox.getSelectedIndex();
                    List<Listitem> items = listbox.getItems();
                    if (!items.isEmpty()) {
                        listbox.setSelectedIndex(0);
                        items.get(0).setFocus(true);
                    }
                }
            });

            // Close bandbox for events onClick and onOK
            listbox.addEventListener(Events.ON_CLICK, new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    pickElementFromListAndCloseBandbox();
                }
            });
            listbox.addEventListener(Events.ON_OK, new EventListener() {

                @Override
                public void onEvent(Event event) throws Exception {
                    pickElementFromListAndCloseBandbox();
                }
            });
        }

        updateWidth();
    }

    private void pickElementFromListAndCloseBandbox() {
        final Object object = getSelectedItem().getValue();
        if (multipleFiltersFinder.isValidNewFilter(object)) {
            addSelectedElement(object);
            clearListbox();
        }
        bandbox.close();
    }

{'fraction_non_alphanumeric': 0.08831254103742613, 'fraction_numerical': 0.002954694681549573, 'mean_word_length': 2.4630541871921183, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4946271', 'n_tokens_mistral': 2407, 'n_tokens_neox': 2346, 'n_words': 619}