/*
 *
 * Copyright
 *  2009 axYus - www.axyus.com
 *  2009 Christophe Marchand <christophe.marchand@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 General Public License as published by
 * the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU 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.exports;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 *
 * @author Christophe Marchand <christophe.marchand@axyus.com>
 */
public class DlgGetExportDetails extends DialogBox {
    public static final HTML MSG = new HTML(
            "Afin de r&eacute;aliser votre export, vous devez sp&eacute;cifier le nom du fichier sous lequel<br/>" +
            "votre export vous sera transmis, ainsi qu'un nom d'export qui vous permettra de suivre l'avancement<br/>" +
            "de la constitution de votre export.");
    private TextBox fileName=null, exportName=null;
    private Button pbCancel=null, pbOk=null;
    private DlgSelectExport parent=null;

    public DlgGetExportDetails(DlgSelectExport parent) {
        super(true, true);
        this.parent=parent;
        setText("Export");
        initComponents();
    }

    protected void initComponents() {
        Grid grd = new Grid(2,2);
        grd.setText(0,0,"Nom de fichier");
        grd.setText(1,0,"Nom d'export");
        grd.setWidget(0, 1, fileName=new TextBox());
        grd.setWidget(1, 1, exportName=new TextBox());
        fileName.setMaxLength(80);
        fileName.setVisibleLength(80);
        exportName.setMaxLength(80);
        exportName.setVisibleLength(80);
        grd.getColumnFormatter().setWidth(0, "15%");
        grd.getColumnFormatter().setWidth(1, "15%");

        VerticalPanel vPane = new VerticalPanel();
        vPane.add(grd);
        vPane.add(MSG);

        HorizontalPanel buttonPane = new HorizontalPanel();
        buttonPane.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        pbCancel = new Button("Annuler");
        pbOk = new Button("Ok");
        FlowPanel fp = new FlowPanel();
        fp.add(pbCancel);
        fp.add(pbOk);
        buttonPane.add(fp);
        buttonPane.setWidth("100%");
        vPane.add(buttonPane);
        setWidget(vPane);

        center();
        initListeners();
    }

    protected void initListeners() {
        pbCancel.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                hide();
            }
        });
        pbOk.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                hide();
                parent.runExport(fileName.getText(),exportName.getText());
            }
        });
    }

}
