OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 144 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * 
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
 * 
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
 * language governing permissions and limitations under the License.
 * 
 * When distributing the software, include this License Header Notice in each file.
 */
 
 package org.openconcerto.erp.core.humanresources.employe.element;

import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.ElementSQLObject;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JDate;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class EtatCivilSQLElement extends ComptaSQLConfElement {

    public EtatCivilSQLElement() {
        super("ETAT_CIVIL", "un état civil", "états civils");
    }

    // MAYBE un champ nationnalité???

    protected List<String> getListFields() {
        final List<String> l = new ArrayList<String>();
        l.add("DATE_NAISSANCE");
        l.add("NB_ENFANTS");
        return l;
    }

    protected List<String> getComboFields() {
        final List<String> l = new ArrayList<String>();
        l.add("DATE_NAISSANCE");
        l.add("NB_ENFANTS");
        return l;
    }

    @Override
    public boolean isPrivate() {
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.openconcerto.devis.SQLElement#getComponent()
     */
    public SQLComponent createComponent() {
        return new BaseSQLComponent(this) {

            JDate dateNaissance;
            JTextField numeroSS, numeroTel, mail, portable;
            JTextField nbEnfants, lieuNaissance, nombrePersonne;
            ElementComboBox comboSituationFam;
            ElementComboBox comboPays, comboDepartement;

            public void addViews() {
                this.setLayout(new GridBagLayout());
                final GridBagConstraints c = new DefaultGridBagConstraints();

                /***********************************************************************************
                 * PANEL ADRESSE
                 **********************************************************************************/
                JPanel panelInfos = new JPanel();
                panelInfos.setOpaque(false);
                panelInfos.setBorder(BorderFactory.createTitledBorder(getLabelFor("ID_ADRESSE")));
                panelInfos.setLayout(new GridBagLayout());

                this.addView("ID_ADRESSE", REQ + ";" + DEC + ";" + SEP);
                ElementSQLObject eltModeRegl = (ElementSQLObject) this.getView("ID_ADRESSE");
                panelInfos.add(eltModeRegl, c);

                // c.fill = GridBagConstraints.BOTH;
                c.anchor = GridBagConstraints.NORTHWEST;
                this.add(panelInfos, c);
                c.anchor = GridBagConstraints.WEST;
                // c.fill = GridBagConstraints.HORIZONTAL;

                /***********************************************************************************
                 * PANEL CONTACT
                 **********************************************************************************/
                JPanel panelContact = new JPanel();
                panelContact.setOpaque(false);
                panelContact.setBorder(BorderFactory.createTitledBorder("Contact"));
                panelContact.setLayout(new GridBagLayout());

                // Téléphone
                c.fill = GridBagConstraints.NONE;
                this.numeroTel = new JTextField(12);
                JLabel labelNumeroTel = new JLabel(getLabelFor("TELEPHONE"));
                labelNumeroTel.setHorizontalAlignment(SwingConstants.RIGHT);
                panelContact.add(labelNumeroTel, c);
                c.gridx++;
                c.weightx = 1;
                panelContact.add(this.numeroTel, c);

                // portable
                c.gridwidth = 1;
                c.gridx = 0;
                c.weightx = 0;
                c.gridy++;

                this.portable = new JTextField(12);
                JLabel labelNumeroPort = new JLabel(getLabelFor("PORTABLE"));
                labelNumeroPort.setHorizontalAlignment(SwingConstants.RIGHT);
                panelContact.add(labelNumeroPort, c);
                c.gridx++;
                c.weightx = 1;
                panelContact.add(this.portable, c);
                c.fill = GridBagConstraints.HORIZONTAL;

                // mail
                c.gridwidth = 1;
                c.gridx = 0;
                c.gridy++;
                c.weightx = 0;

                this.mail = new JTextField();
                JLabel labelMail = new JLabel(getLabelFor("MAIL"));
                labelMail.setHorizontalAlignment(SwingConstants.RIGHT);
                panelContact.add(labelMail, c);
                c.gridx++;
                c.weightx = 1;
                c.weighty = 1;
                panelContact.add(this.mail, c);

                c.gridx = 1;
                c.gridy = 0;

                c.anchor = GridBagConstraints.NORTHWEST;
                c.weighty = 0;
                this.add(panelContact, c);
                c.anchor = GridBagConstraints.WEST;

                /***********************************************************************************
                 * PANEL NAISSANCE
                 **********************************************************************************/
                JPanel panelNaissance = new JPanel();
                panelNaissance.setOpaque(false);
                panelNaissance.setBorder(BorderFactory.createTitledBorder("Date et lieu de naissance"));
                panelNaissance.setLayout(new GridBagLayout());

                // Date de naissance
                c.gridwidth = 1;
                c.gridx = 0;
                c.gridy = 0;
                JLabel labelDateNaissance = new JLabel(getLabelFor("DATE_NAISSANCE"));
                labelDateNaissance.setHorizontalAlignment(SwingConstants.RIGHT);
                this.dateNaissance = new JDate();
                panelNaissance.add(labelDateNaissance, c);
                c.gridx++;
                panelNaissance.add(this.dateNaissance, c);

                // Commune de naissance
                JLabel labelLieuNaissance = new JLabel(getLabelFor("COMMUNE_NAISSANCE"));
                labelLieuNaissance.setHorizontalAlignment(SwingConstants.RIGHT);
                this.lieuNaissance = new JTextField();
                c.gridx++;
                panelNaissance.add(labelLieuNaissance, c);
                c.gridx++;
                c.weightx = 1;
                panelNaissance.add(this.lieuNaissance, c);

                // Departement de naissance
                c.weightx = 0;
                JLabel labelDptNaissance = new JLabel(getLabelFor("ID_DEPARTEMENT_NAISSANCE"));
                labelDptNaissance.setHorizontalAlignment(SwingConstants.RIGHT);
                this.comboDepartement = new ElementComboBox(false, 20);

                c.gridx = 0;
                c.gridy++;
                panelNaissance.add(labelDptNaissance, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                panelNaissance.add(this.comboDepartement, c);
                c.gridwidth = 1;

                // Pays de naissance
                JLabel labelPaysNaissance = new JLabel(getLabelFor("ID_PAYS_NAISSANCE"));
                labelPaysNaissance.setHorizontalAlignment(SwingConstants.RIGHT);
                this.comboPays = new ElementComboBox(false, 20);
                c.gridx++;
                c.weightx = 0;
                panelNaissance.add(labelPaysNaissance, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                c.weighty = 1;
                panelNaissance.add(this.comboPays, c);
                c.gridwidth = 1;

                // Nationnalite
                c.weightx = 0;
                JLabel labelNationnalite = new JLabel(getLabelFor("NATIONNALITE"));
                labelNationnalite.setHorizontalAlignment(SwingConstants.RIGHT);
                c.gridy++;
                c.gridx = 0;
                panelNaissance.add(labelNationnalite, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldNation = new JTextField();
                panelNaissance.add(fieldNation, c);
                addView(fieldNation, "NATIONNALITE");
                c.gridwidth = 1;

                c.gridx = 0;
                c.weighty = 0;
                c.gridy = 1;
                c.weightx = 0;
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.anchor = GridBagConstraints.NORTHWEST;
                this.add(panelNaissance, c);

                c.anchor = GridBagConstraints.WEST;
                c.gridwidth = 1;

                /***********************************************************************************
                 * SITUATION
                 **********************************************************************************/
                JPanel panelSituation = new JPanel();
                panelSituation.setOpaque(false);
                panelSituation.setBorder(BorderFactory.createTitledBorder("Situation personnelle"));
                panelSituation.setLayout(new GridBagLayout());
                // Numero SS
                c.gridy = 0;
                c.gridx = 0;
                this.numeroSS = new JTextField();
                JLabel labelNumeroSS = new JLabel(getLabelFor("NUMERO_SS"));
                labelNumeroSS.setHorizontalAlignment(SwingConstants.RIGHT);
                panelSituation.add(labelNumeroSS, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                panelSituation.add(this.numeroSS, c);

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;
                panelSituation.add(new JLabel("CNPS", SwingConstants.RIGHT), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldCNPS = new JTextField();
                panelSituation.add(fieldCNPS, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldCNPS, "CNPS");

                // Situation familiale
                JLabel labelSitutationFamiliale = new JLabel(getLabelFor("ID_SITUATION_FAMILIALE"));
                labelSitutationFamiliale.setHorizontalAlignment(SwingConstants.RIGHT);

                this.comboSituationFam = new ElementComboBox(false);

                c.gridx = 0;
                c.gridy++;
                panelSituation.add(labelSitutationFamiliale, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                panelSituation.add(this.comboSituationFam, c);
                c.gridwidth = 1;
                c.weightx = 0;

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;
                panelSituation.add(new JLabel(getLabelFor("NTT"), SwingConstants.RIGHT), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldNTT = new JTextField();
                panelSituation.add(fieldCNPS, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldNTT, "NTT");

                // Nombre d'enfants
                JLabel labelNombreEnfants = new JLabel(getLabelFor("NB_ENFANTS"));
                labelNombreEnfants.setHorizontalAlignment(SwingConstants.RIGHT);
                this.nbEnfants = new JTextField();
                c.gridx = 0;
                c.gridy++;
                panelSituation.add(labelNombreEnfants, c);
                c.gridx++;
                c.weightx = 1;
                panelSituation.add(this.nbEnfants, c);
                c.weightx = 0;

                // Nombre de personnes à charge
                JLabel labelNombrePersonne = new JLabel(getLabelFor("NB_PERS_A_CHARGE"));
                labelNombrePersonne.setHorizontalAlignment(SwingConstants.RIGHT);
                this.nombrePersonne = new JTextField(3);
                c.gridx++;
                panelSituation.add(labelNombrePersonne, c);
                c.gridx++;
                c.weightx = 1;
                c.weighty = 1;
                panelSituation.add(this.nombrePersonne, c);
                c.weightx = 1;
                c.weighty = 0;

                c.gridx = 0;
                c.gridy = 2;
                c.anchor = GridBagConstraints.NORTHWEST;
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.weighty = 0;
                this.add(panelSituation, c);

                /***********************************************************************************
                 * PIECE IDENTITE
                 **********************************************************************************/
                JPanel panelIdentite = new JPanel();
                panelIdentite.setOpaque(false);
                panelIdentite.setBorder(BorderFactory.createTitledBorder("Pièce d'identité"));
                panelIdentite.setLayout(new GridBagLayout());
                // TYPE_PIECE_IDENTITE
                c.gridy = 0;
                c.gridx = 0;
                c.gridwidth = 1;
                JTextField fieldTypePiece = new JTextField();
                JLabel typePieceLabel = new JLabel(getLabelFor("TYPE_PIECE_IDENTITE"));
                typePieceLabel.setHorizontalAlignment(SwingConstants.RIGHT);
                panelIdentite.add(typePieceLabel, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                panelIdentite.add(fieldTypePiece, c);
                addView(fieldTypePiece, "TYPE_PIECE_IDENTITE");

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;

                panelIdentite.add(new JLabel(getLabelFor("NUMERO_PIECE")), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldNumeroPiece = new JTextField();
                panelIdentite.add(fieldNumeroPiece, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldNumeroPiece, "NUMERO_PIECE");

                // Date debut
                JLabel labelDateDebut = new JLabel(getLabelFor("DATE_DEBUT_PIECE"));
                labelDateDebut.setHorizontalAlignment(SwingConstants.RIGHT);
                c.gridx = 0;
                c.gridy++;
                panelIdentite.add(labelDateDebut, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JDate fieldDateDebut = new JDate();
                panelIdentite.add(fieldDateDebut, c);
                addView(fieldDateDebut, "DATE_DEBUT_PIECE");
                c.gridwidth = 1;
                c.weightx = 0;

                // Nombre d'enfants
                JLabel labelDateFin = new JLabel(getLabelFor("DATE_FIN_PIECE"));
                labelDateFin.setHorizontalAlignment(SwingConstants.RIGHT);
                JDate fieldDateFin = new JDate();
                c.gridx++;
                panelIdentite.add(labelDateFin, c);
                c.gridx++;
                c.weightx = 1;
                panelIdentite.add(fieldDateFin, c);
                addView(fieldDateFin, "DATE_FIN_PIECE");
                c.weightx = 0;

                c.gridx = 0;
                c.gridy = 3;
                c.anchor = GridBagConstraints.NORTHWEST;
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.weighty = 0;
                this.add(panelIdentite, c);

                /***********************************************************************************
                 * FAMILLE
                 **********************************************************************************/
                JPanel panelFamille = new JPanel();
                panelFamille.setOpaque(false);
                panelFamille.setBorder(BorderFactory.createTitledBorder("Famille"));
                panelFamille.setLayout(new GridBagLayout());
                // TYPE_PIECE_IDENTITE
                c.gridy = 0;
                c.gridx = 0;
                c.gridwidth = 1;
                JTextField fieldPere = new JTextField();
                JLabel pereLabel = new JLabel(getLabelFor("NOM_PERE"));
                pereLabel.setHorizontalAlignment(SwingConstants.RIGHT);
                panelFamille.add(pereLabel, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                panelFamille.add(fieldPere, c);
                addView(fieldPere, "NOM_PERE");

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;
                panelFamille.add(new JLabel(getLabelFor("NOM_MERE")), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldNomMere = new JTextField();
                panelFamille.add(fieldNomMere, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldNomMere, "NOM_MERE");

                // Nom
                JLabel labelConjointNom = new JLabel(getLabelFor("CONJOINT_NOM"));
                labelConjointNom.setHorizontalAlignment(SwingConstants.RIGHT);
                c.gridx = 0;
                c.gridy++;
                panelFamille.add(labelConjointNom, c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldConjointNom = new JTextField();
                panelFamille.add(fieldConjointNom, c);
                addView(fieldConjointNom, "CONJOINT_NOM");
                c.gridwidth = 1;
                c.weightx = 0;

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;
                panelFamille.add(new JLabel(getLabelFor("CONJOINT_PROFESSION")), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldProfession = new JTextField();
                panelFamille.add(fieldProfession, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldProfession, "CONJOINT_PROFESSION");

                // Nombre d'enfants
                JLabel labelDateNaissanceConjoint = new JLabel(getLabelFor("CONJOINT_DATE_NAISSANCE"));
                labelDateNaissanceConjoint.setHorizontalAlignment(SwingConstants.RIGHT);
                JDate fieldDateNaissanceConjoint = new JDate();
                c.gridx = 0;
                c.gridy++;
                panelFamille.add(labelDateNaissanceConjoint, c);
                c.gridx++;
                c.weightx = 1;
                panelFamille.add(fieldDateNaissanceConjoint, c);
                addView(fieldDateNaissanceConjoint, "CONJOINT_DATE_NAISSANCE");
                c.weightx = 0;

                c.weightx = 0;
                c.gridwidth = 1;
                c.gridx++;
                panelFamille.add(new JLabel(getLabelFor("CONJOINT_LIEU_NAISSANCE")), c);
                c.gridx++;
                c.gridwidth = 1;
                c.weightx = 1;
                JTextField fieldLieuNaissanceConjoint = new JTextField();
                panelFamille.add(fieldLieuNaissanceConjoint, c);
                c.weightx = 0;
                c.gridwidth = 1;
                addView(fieldLieuNaissanceConjoint, "CONJOINT_LIEU_NAISSANCE");

                c.gridx = 0;
                c.gridy = 4;
                c.anchor = GridBagConstraints.NORTHWEST;
                c.gridwidth = GridBagConstraints.REMAINDER;
                c.weighty = 1;
                this.add(panelFamille, c);

                this.addRequiredSQLObject(this.dateNaissance, "DATE_NAISSANCE");
                this.addSQLObject(this.lieuNaissance, "COMMUNE_NAISSANCE");
                this.addSQLObject(this.nbEnfants, "NB_ENFANTS");
                this.addSQLObject(this.nombrePersonne, "NB_PERS_A_CHARGE");
                this.addRequiredSQLObject(this.numeroSS, "NUMERO_SS");
                this.addSQLObject(this.comboPays, "ID_PAYS_NAISSANCE");
                this.addSQLObject(this.comboDepartement, "ID_DEPARTEMENT_NAISSANCE");
                this.addRequiredSQLObject(this.comboSituationFam, "ID_SITUATION_FAMILIALE");
                this.addSQLObject(this.numeroTel, "TELEPHONE");
                this.addSQLObject(this.portable, "PORTABLE");
                this.addSQLObject(this.mail, "MAIL");
                this.comboPays.setButtonsVisible(false);
                this.comboDepartement.setButtonsVisible(false);
                this.comboSituationFam.setButtonsVisible(false);
            }

            protected SQLRowValues createDefaults() {
                final SQLTable table = getTable();
                final SQLRowValues vals = new SQLRowValues(table);
                getElement().loadAllSafe(vals, table.getRow(table.getUndefinedID()));
                return vals;
            }
        };

    }

    @Override
    protected String createCode() {
        return this.createCodeOfPackage() + ".info";
    }
}