/*
 * Copyright
 *   2007 axYus - www.axyus.com
 *   2005 C.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 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.updater.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JDialog;

import fr.gouv.finances.cp.utils.xml.marshal.XmlMarshallable;
import fr.gouv.finances.cp.xemelios.updater.config.ComponentModel;
import fr.gouv.finances.cp.xemelios.updater.config.FileListModel;

/**
 *
 * @author  chm
 */
public class DlgComponentDetail extends javax.swing.JDialog {
    /**
	 * 
	 */
	private static final long serialVersionUID = -2917904079172668916L;
	private ComponentModel cm;

    /** Creates new form NewJDialog */
    public DlgComponentDetail(JDialog parent, ComponentModel cm) {
        super(parent, false);
        this.cm=cm;
        initComponents();
    }
    
    /** 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 ">
    private void initComponents() {
        lblName = new javax.swing.JLabel();
        vlName = new javax.swing.JLabel();
        lblId = new javax.swing.JLabel();
        lblVersion = new javax.swing.JLabel();
        lblDesc = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDesc = new javax.swing.JTextArea();
        lblDepends = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstDepends = new javax.swing.JList();
        vlId = new javax.swing.JLabel();
        vlVersion = new javax.swing.JLabel();
        lblFiles = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lstFiles = new javax.swing.JList();
        pbClose = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        lblName.setText("Nom");

        vlName.setFont(new java.awt.Font("Dialog", 0, 12));
        vlName.setText(cm.getName());

        lblId.setText("ID");

        lblVersion.setText("Version");

        lblDesc.setText("Description");

        jScrollPane1.setBackground(javax.swing.UIManager.getDefaults().getColor("PropSheet.setBackground"));
        jScrollPane1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        txtDesc.setBackground(javax.swing.UIManager.getDefaults().getColor("ComboBox.background"));
        txtDesc.setColumns(20);
        txtDesc.setEditable(false);
        txtDesc.setLineWrap(true);
        txtDesc.setWrapStyleWord(true);
        txtDesc.setRows(5);
        txtDesc.setText(cm.getDescription().getText());
        jScrollPane1.setViewportView(txtDesc);
        lblConfig = new javax.swing.JLabel();
        dfConfiguration = new javax.swing.JTextField();

        lblDepends.setText("Dépendances");

        lstDepends.setFont(new java.awt.Font("Dialog", 0, 12));
        if(cm.getRequires()!=null && cm.getRequires().getComponents()!=null) {
        	lstDepends.setListData(cm.getRequires().getComponents().toArray());
        }
        jScrollPane2.setViewportView(lstDepends);

        vlId.setFont(new java.awt.Font("Dialog", 0, 12));
        vlId.setText(cm.getId());

        vlVersion.setFont(new java.awt.Font("Dialog", 0, 12));
        vlVersion.setText(cm.getRelease().getV());

        lblFiles.setText("Fichiers");

        lstFiles.setFont(new java.awt.Font("Dialog", 0, 12));
        Vector<XmlMarshallable> files = new Vector<XmlMarshallable>();
        for(FileListModel flm:cm.getFileLists()) {
        	for(XmlMarshallable fm:flm.getFiles()) {
        		files.add(fm);
        	}
        }
        lstFiles.setListData(files);
        jScrollPane3.setViewportView(lstFiles);

        pbClose.setText("Fermer");
        pbClose.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent evt) {
        		setVisible(false);
        	}
        });

        lblConfig.setText("Configurateur");

        dfConfiguration.setEditable(false);
        dfConfiguration.setText(cm.getConfiguration()!=null && cm.getConfiguration().getClassName()!=null?cm.getConfiguration().getClassName():"N/A");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(lblName)
                    .add(lblId)
                    .add(lblVersion))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
                    .add(vlVersion)
                    .add(vlId)
                    .add(vlName)
                    .add(dfConfiguration, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(lblConfig)
                .addContainerGap(244, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(lblFiles)
                .addContainerGap(283, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(130, 130, 130)
                .add(pbClose)
                .add(136, 136, 136))
            .add(layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(lblDesc)
                .addContainerGap(259, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(lblDepends)
                .addContainerGap(248, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblName)
                    .add(vlName))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblId)
                    .add(vlId))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblVersion)
                    .add(vlVersion))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblDesc)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblDepends)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblFiles)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 93, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(8, 8, 8)
                .add(lblConfig)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(dfConfiguration, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 31, Short.MAX_VALUE)
                .add(pbClose)
                .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        setVisible(true);
    }// </editor-fold>
    
    
    // Variables declaration - do not modify
    private javax.swing.JLabel vlVersion;
    private javax.swing.JList lstFiles;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblConfig;
    private javax.swing.JLabel lblDepends;
    private javax.swing.JLabel lblDesc;
    private javax.swing.JLabel lblFiles;
    private javax.swing.JLabel lblId;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblVersion;
    private javax.swing.JList lstDepends;
    private javax.swing.JButton pbClose;
    private javax.swing.JTextArea txtDesc;
    private javax.swing.JLabel vlId;
    private javax.swing.JLabel vlName;
    private javax.swing.JTextField dfConfiguration;
    // End of variables declaration
    
}
