/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *
 * This file is part of XEMELIOS.
 *
 * XEMELIOS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * XEMELIOS 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with XEMELIOS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package fr.gouv.finances.dgfip.xemelios.web.gwt.client.widget.search.criteria;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import fr.gouv.finances.dgfip.xemelios.web.gwt.client.widget.search.CriteriaTable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author CBO
 */
public class CritereLineContainer extends Composite {

    private CriteriaTable criteriaTable;
    private String critereId;
    private HorizontalPanel horizontalPanel;

    public CritereLineContainer(CriteriaTable criteriaTable, String critereId) {
        this.criteriaTable = criteriaTable;
        this.critereId = critereId;
        this.horizontalPanel = new HorizontalPanel();
        initWidget(this.horizontalPanel);
    }

    public CriteriaTable getCriteriaTable() {
        return criteriaTable;
    }

    public String getCritereId() {
        return critereId;
    }

    public void add(CritereWidget critereWidget) {
        horizontalPanel.add(critereWidget);
    }

    public List<InputCritereWidget> getInputCriteriaWidgets() {
        List<InputCritereWidget> toReturn = new ArrayList<InputCritereWidget>();
        for (int i = 0; i < horizontalPanel.getWidgetCount(); i++) {
            Widget widget = horizontalPanel.getWidget(i);
            if (widget instanceof InputCritereWidget) {
                toReturn.add((InputCritereWidget) widget);
            }
        }
        return toReturn;
    }

    InputCritereWidget getInputCritereWidget(String inputId) {
        for (InputCritereWidget inputCritereWidget : getInputCriteriaWidgets()) {
            if (inputCritereWidget.getInputId().equals(inputId)) {
                return inputCritereWidget;
            }
        }
        return null;
    }
}
