/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2007 N.Le Corre - nicolas.lecorre@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.cp.xemelios.ui;

import fr.gouv.finances.cp.utils.ui.InfiniteGlassPane;
import fr.gouv.finances.cp.xemelios.common.config.DocumentsModel;

/**
 *
 * @author  nicolas.lecorre
 */
public abstract class DlgChooseDocuments extends javax.swing.JDialog {
	
	private DocumentsModel dm;
	private boolean selectionMultiple = true;

	public void setBActionLibelle(String actionLibelle) {
		bAction.setText(actionLibelle);
	}

	/**
	 * La méthode appelée lors du click sur le bouton "action" en bas à droite.
	 * Cela peut être la suppression, l'export, ...
	 * @param evt
	 */
	protected abstract void doAction (java.awt.event.ActionEvent evt);
    
    /** Creates new form DlgChooseDocuments */
    public DlgChooseDocuments(java.awt.Frame parent, boolean modal, DocumentsModel _dm, boolean selectionMultiple) {
        super(parent, modal);
        this.selectionMultiple = selectionMultiple;
        this.setDm(_dm);
        initComponents();
        setLocationRelativeTo(getParent());
        setGlassPane(new InfiniteGlassPane());
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jTabbedPane1.addTab("Par données", new PanelChooseDatabaseDonnees(this, dm));
        jTabbedPane1.addTab("Par fichier", new PanelChooseDatabaseFichier(this, dm, this.selectionMultiple));
        bFermer = new javax.swing.JButton();
        bAction = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        bFermer.setText("Fermer");
        bFermer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bFermerActionPerformed(evt);
            }
        });

        bAction.setText("Action");
        bAction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bActionActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(bAction)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bFermer)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bAction)
                    .add(bFermer))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bActionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bActionActionPerformed
    	doAction (evt);
    }//GEN-LAST:event_bActionActionPerformed

    private void bFermerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bFermerActionPerformed
    	this.dispose();
    }//GEN-LAST:event_bFermerActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bAction;
    private javax.swing.JButton bFermer;
     javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables

	public DocumentsModel getDm() {
		return dm;
	}

	public void setDm(DocumentsModel dm) {
		this.dm = dm;
	}

	public javax.swing.JTabbedPane getJTabbedPane1() {
		return jTabbedPane1;
	}
	
	public void enableButtons (boolean enable) {
		this.bAction.setEnabled(enable);
		this.bFermer.setEnabled(enable);
	}
    
}
