/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2005 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 java.awt.Component;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultListSelectionModel;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.tree.DefaultTreeSelectionModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;

import org.apache.log4j.Logger;
import org.jdesktop.swingx.JXTreeTable;

import fr.gouv.finances.cp.utils.Pair;
import fr.gouv.finances.cp.xemelios.common.config.DocumentModel;
import fr.gouv.finances.cp.xemelios.common.config.DocumentsModel;
import fr.gouv.finances.cp.xemelios.data.DataAccessException;
import fr.gouv.finances.cp.xemelios.data.DataConfigurationException;
import fr.gouv.finances.cp.xemelios.data.DataLayerManager;
import fr.gouv.finances.cp.xemelios.export.ExportChampModel;
import fr.gouv.finances.cp.xemelios.export.ExportElementModel;
import org.jdesktop.swingx.treetable.TreeTableModel;

/**
 *
 * @author  nicolas.lecorre
 */
@SuppressWarnings("serial")
public class PanelChooseDatabaseFichier extends javax.swing.JPanel {
	private static final Logger logger = Logger.getLogger(PanelChooseDatabaseFichier.class);
	private DocumentsModel dms = null;
	private DatabaseTreeDataFichier data = null;
	private boolean selectionMultiple = true;
	private int mode = MODE_SUPPRESSION;
	
	public static final int MODE_SUPPRESSION = 0;
	public static final int MODE_EXPORT = 1;
    
    public DatabaseTreeDataFichier getData() {
		return data;
	}

	/** Creates new form PanelCleanDatabaseFichier */
    public PanelChooseDatabaseFichier(JDialog p, DocumentsModel d, boolean selectionMultiple) {
    	dms = d;
    	this.selectionMultiple = selectionMultiple;
        initComponents();
        fillDocType();
        data = new DatabaseTreeDataFichier (listeFichiers);
        data.setMode(getMode());
        data.setSelectionMultiple(this.selectionMultiple);
        listeFichiers.setTreeTableModel(data);
        listeFichiers.setRootVisible(false);
    }
    
    private void fillDocType () {
    	Vector<Pair> v = new Vector<Pair>();
    	v.add(new Pair("RIEN", "Tous"));
    	cbTypeDoc.addItem(new Pair("RIEN", "Tous"));
    	for (DocumentModel d:dms.getDocuments()) {
            if(d.getDisplayInMenuIf()==null || "true".equals(System.getProperty(d.getDisplayInMenuIf())))
    		v.add (new Pair(d.getId(), d.getTitre()));
    	}
    	cbTypeDoc.setModel(new javax.swing.DefaultComboBoxModel(v));
    	fillColl ();
    	fillBudg ();
    }
    
    private void fillColl () {
    	String selectedDocId = ((Pair)cbTypeDoc.getSelectedItem()).key;
    	Vector<Pair> v = new Vector<Pair>();
    	v.add(new Pair("RIEN", "Toutes"));
    	if (!"RIEN".equals(selectedDocId)) {
	    	DocumentModel selectedDocumentModel = dms.getDocumentById(selectedDocId);
	    	Vector<Pair> collectivites = getCollectivitesFromDocumentModel(selectedDocumentModel);
	    	v.addAll(collectivites);
    	}
    	this.cbCollectivite.setModel(new javax.swing.DefaultComboBoxModel(v));
    	fillBudg ();
    }
    
    private void fillBudg () {
    	String selectedDocId = ((Pair)cbTypeDoc.getSelectedItem()).key;
    	Pair selectedColl = (Pair)cbCollectivite.getSelectedItem();
    	Vector<Pair> v = new Vector<Pair>();
    	v.add(new Pair("RIEN", "Tous"));
    	if (!"RIEN".equals(selectedColl)) {
    		DocumentModel selectedDocumentModel = dms.getDocumentById(selectedDocId);
    		try {
    			Vector<Pair> budgets = DataLayerManager.getImplementation().getBudgets(selectedDocumentModel, selectedColl);
    	    	v.addAll(budgets);
    		} catch (Exception e) {
    			logger.debug("Ce n'est pas grave, on n'a juste pas reussi a trouver le budget", e);
    		}
    	}
    	this.cbBudget.setModel(new javax.swing.DefaultComboBoxModel(v));    	
    }
    
    protected Vector<Pair> getCollectivitesFromDocumentModel(DocumentModel dm) {
        Vector<Pair> ret = null;
        try {
            ret = DataLayerManager.getImplementation().getCollectivites(dm);
        } catch(DataAccessException daEx) {
            logger.warn("",daEx);
            ret = new Vector<Pair>();
        } catch(DataConfigurationException dcEx) {
            logger.error("",dcEx);
            ret = new Vector<Pair>();
        }
        return ret;
    }

    
    /** 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.
     */
    private void initComponents() {
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listeFichiers = new JXTreeTablePropertyEditor (this.selectionMultiple);
        bSelectAll = new javax.swing.JButton();
        bUnSelectAll = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cbCollectivite = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        cbBudget = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        cbTypeDoc = new javax.swing.JComboBox();
        bRechercher = new javax.swing.JButton();

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Documents"));
        jPanel2.setMinimumSize(new java.awt.Dimension(1031, 83));
//        listeFichiers.setMaximumSize(new java.awt.Dimension(32000, 32000));
//        listeFichiers.setPreferredSize(new java.awt.Dimension(0, 0));
        if (!this.selectionMultiple)
        	listeFichiers.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        listeFichiers.setRootVisible(true);
        listeFichiers.setShowHorizontalLines(true);
        listeFichiers.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_LAST_COLUMN);
        jScrollPane2.setViewportView(listeFichiers);

        bSelectAll.setText("Tout s\u00e9lectionner");
        bUnSelectAll.setText("Tout d\u00e9s\u00e9lectionner");
        
        if(!selectionMultiple) {
            bSelectAll.setEnabled(false);
            bUnSelectAll.setEnabled(false);
        }

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE))
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(204, 204, 204)
                        .add(bSelectAll)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(bUnSelectAll)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(bSelectAll)
                    .add(bUnSelectAll))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Recherche"));
        jPanel1.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanel1.setPreferredSize(new java.awt.Dimension(0, 0));
        jLabel1.setText("S\u00e9lectionnez dans la liste ci-dessous le type de document, la collectivit\u00e9 et le budget");
        jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);

        cbCollectivite.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        cbCollectivite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCollectiviteActionPerformed(evt);
            }
        });

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Collectivit\u00e9");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Budget");

        cbBudget.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        cbBudget.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbBudgetActionPerformed(evt);
            }
        });

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Type de document");

        cbTypeDoc.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        cbTypeDoc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTypeDocActionPerformed(evt);
            }
        });

        bRechercher.setText("Rechercher");
        bRechercher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bRechercherActionPerformed(evt);
            }
        });
        
        bSelectAll.addActionListener(new java.awt.event.ActionListener() {
        	public void actionPerformed(java.awt.event.ActionEvent evt) {
        		bSelectAllPerformed(evt);
        	}
        });
        
        bUnSelectAll.addActionListener(new java.awt.event.ActionListener() {
        	public void actionPerformed(java.awt.event.ActionEvent evt) {
        		bUnSelectAllPerformed(evt);
        	}
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 136, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(12, 12, 12)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(cbBudget, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cbTypeDoc, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(cbCollectivite, 0, 313, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 94, Short.MAX_VALUE)
                        .add(bRechercher)))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(new java.awt.Component[] {jLabel2, jLabel3, jLabel4}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jLabel1)
                .add(19, 19, 19)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(cbTypeDoc, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(cbCollectivite, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(7, 7, 7)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(cbBudget, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(bRechercher, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1Layout.linkSize(new java.awt.Component[] {cbBudget, cbCollectivite, cbTypeDoc}, org.jdesktop.layout.GroupLayout.VERTICAL);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.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(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, 0, 680, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 154, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }

    private void cbTypeDocActionPerformed(java.awt.event.ActionEvent evt) {
   		fillColl();
    }

    private void bSelectAllPerformed(java.awt.event.ActionEvent evt) {
    	selectAllChilds(data.getData(), true);
    	listeFichiers.repaint();
    }
    private void bUnSelectAllPerformed(java.awt.event.ActionEvent evt) {
   		selectAllChilds(data.getData(), false);
    	listeFichiers.repaint();
    }
    private void selectAllChilds (DatabaseTreeDataFichier.Data d, boolean selected) {
    	for (DatabaseTreeDataFichier.Data dd:d.getChilds()) {
    		dd.setSelected(selected);
    		selectAllChilds (dd, selected);
    	}
    }
    
    private void bRechercherActionPerformed(java.awt.event.ActionEvent evt) {
    	try {
			String coll = ((Pair)cbCollectivite.getSelectedItem()).key;
			if ("RIEN".equals(coll)) coll=null;
			String budg = ((Pair)cbBudget.getSelectedItem()).key;
			if ("RIEN".equals(budg)) budg=null;
	    	if (cbTypeDoc.getSelectedIndex()==0) {
	    		Vector<DatabaseTreeDataFichier.Data> datas = DataLayerManager.getImplementation().searchFichiers(dms, coll, budg);
	    		data = new DatabaseTreeDataFichier(datas, listeFichiers);
	    		data.setMode(getMode());
	    		data.setSelectionMultiple(this.selectionMultiple);
	        	listeFichiers.setTreeTableModel(data);
	            listeFichiers.getColumnModel().getColumn(1).setMaxWidth(25);
	            listeFichiers.setRootVisible(true);
	    	} else {
	    		String selectedDocId = ((Pair)cbTypeDoc.getSelectedItem()).key;
	    		Vector<DatabaseTreeDataFichier.Data> datas = new Vector<DatabaseTreeDataFichier.Data>();
	    		DatabaseTreeDataFichier.Data d = DataLayerManager.getImplementation().searchFichiers(dms.getDocumentById(selectedDocId), coll, budg);
	    		if (d != null)
	    			datas.add(d);
	    		data = new DatabaseTreeDataFichier(datas, listeFichiers);
	    		data.setMode(getMode());
	    		data.setSelectionMultiple(this.selectionMultiple);
	        	listeFichiers.setTreeTableModel(data);
	            listeFichiers.getColumnModel().getColumn(1).setMaxWidth(25);
	            listeFichiers.setRootVisible(true);
	    	}
    	} catch (Exception e) {
    		logger.error("", e);
    	}
    }
    
    public void refresh () {
    	bRechercherActionPerformed (null);
    }

    private void cbBudgetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
    }

    private void cbCollectiviteActionPerformed(java.awt.event.ActionEvent evt) {
   		fillBudg();
    }
    
    
    // Variables declaration - do not modify
    private javax.swing.JButton bRechercher;
    private javax.swing.JComboBox cbBudget;
    private javax.swing.JComboBox cbCollectivite;
    private javax.swing.JComboBox cbTypeDoc;
    private javax.swing.JButton bSelectAll;
    private javax.swing.JButton bUnSelectAll;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private org.jdesktop.swingx.JXTreeTable listeFichiers;
    // End of variables declaration

	public org.jdesktop.swingx.JXTreeTable getListeFichiers() {
		return listeFichiers;
	}

    private class JXTreeTablePropertyEditor extends JXTreeTable {
    	private TableCellEditor booleanEditor;
        private TableCellRenderer booleanRenderer, booleanRendererExclusif, blankRenderer;
        private boolean selectionMultiple = true;
//        private TreeTableModel model = null;
        public JXTreeTablePropertyEditor(boolean selectionMultiple) {
            super();
            getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
            this.selectionMultiple = selectionMultiple;
            booleanEditor = new DefaultCellEditor(new JCheckBox()) {
                public Component getTableCellEditorComponent(JTable table,Object value,boolean isSelected,int row,int column) {
                    Component c = super.getTableCellEditorComponent(table,value,isSelected,row,column);
                    JCheckBox chk = (JCheckBox)editorComponent;
                    chk.setSelected(((Boolean)value).booleanValue());
                    chk.setBackground(c.getBackground());
                    return chk;
                }
            };
            booleanRendererExclusif = new DefaultTableCellRenderer() {
                private JRadioButton rb = new JRadioButton();
                public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
                    JLabel lbl = (JLabel)super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
                    rb.setSelected(((Boolean)value).booleanValue());
                    rb.setBackground(lbl.getBackground());
                    rb.setBorder(lbl.getBorder());
                    return rb;
                }
            };
            booleanRenderer = new DefaultTableCellRenderer() {
                private JCheckBox chk = new JCheckBox();
                public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
                    JLabel lbl = (JLabel)super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
                    chk.setSelected(((Boolean)value).booleanValue());
                    chk.setBackground(lbl.getBackground());
                    chk.setBorder(lbl.getBorder());
                    return chk;
                }
            };
            blankRenderer = new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
                    JLabel lbl = (JLabel)super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
                    lbl.setText("");
                    return lbl;
                }
            };
        }
        public TableCellEditor getCellEditor (int row, int column) {
        	if (row>0 && column==1) {
        		if (selectionMultiple)
        			return booleanEditor;
        		else
        			return booleanEditor;//booleanEditorExclusif;
        	} else {
        		return super.getCellEditor(row, column);
        	}
        }
        public TableCellRenderer getCellRenderer(int row, int column) {
        	if (row==0 && column==1) {
        		return blankRenderer;
        	} else if(column==1)  {
        		if (selectionMultiple)
        			return booleanRenderer;
        		else {
                            Object o = PanelChooseDatabaseFichier.this.listeFichiers.getPathForRow(row).getLastPathComponent();
                            if(PanelChooseDatabaseFichier.this.data.isCellEditable(o,column))
        			return booleanRendererExclusif;
                            else
                                return blankRenderer;
                        }
            } else {
                return super.getCellRenderer(row,column);
            }
        }
    }
    
    public DocumentModel getDMSelected () {
    	return dms.getDocumentById(((Pair)cbTypeDoc.getSelectedItem()).key);
    }

	public int getMode() {
		return mode;
	}

	public void setMode(int mode) {
		this.mode = mode;
	}
	
}
