OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Blame | 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.finance.accounting.element;

import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
import org.openconcerto.erp.model.ISQLCompteSelector;
import org.openconcerto.sql.element.BaseSQLComponent;
import org.openconcerto.sql.element.SQLComponent;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.utils.ListMap;

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

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

public class CategorieComptableSQLElement extends ComptaSQLConfElement {

    public CategorieComptableSQLElement() {
        super("CATEGORIE_COMPTABLE", "une catégorie comptable", "catégories comptable");
    }

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

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

    @Override
    public ListMap<String, String> getShowAs() {
        ListMap<String, String> map = new ListMap<String, String>();
        map.add(null, "NOM");
        return map;
    }

    public SQLComponent createComponent() {
        return new BaseSQLComponent(this) {

            @Override
            protected void addViews() {

                this.setLayout(new GridBagLayout());
                GridBagConstraints c = new DefaultGridBagConstraints();
                JLabel labelNom = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);

                this.add(labelNom, c);
                c.gridx++;
                c.weightx = 1;
                c.fill = GridBagConstraints.NONE;
                JTextField fieldNom = new JTextField(40);
                DefaultGridBagConstraints.lockMinimumSize(fieldNom);
                this.add(fieldNom, c);

                JLabel labelTaxe = new JLabel(getLabelFor("ID_TAXE_VENTE"), SwingConstants.RIGHT);
                c.fill = GridBagConstraints.HORIZONTAL;
                c.gridx = 0;
                c.gridy++;
                this.add(labelTaxe, c);
                c.gridx++;
                c.weightx = 1;
                c.gridwidth = GridBagConstraints.REMAINDER;
                ISQLCompteSelector compteTaxe = new ISQLCompteSelector();
                this.add(compteTaxe, c);

                JLabel labelCompteVt = new JLabel(getLabelFor("ID_COMPTE_PCE_VENTE"), SwingConstants.RIGHT);
                c.gridx = 0;
                c.gridy++;
                c.weightx = 0;
                c.gridwidth = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
                this.add(labelCompteVt, c);
                c.gridx++;
                c.weightx = 1;

                c.gridwidth = GridBagConstraints.REMAINDER;
                ISQLCompteSelector compteVt = new ISQLCompteSelector();
                this.add(compteVt, c);

                JLabel labelCompteAchat = new JLabel(getLabelFor("ID_COMPTE_PCE_ACHAT"), SwingConstants.RIGHT);
                c.fill = GridBagConstraints.HORIZONTAL;
                c.gridwidth = 1;
                c.gridx = 0;
                c.gridy++;
                this.add(labelCompteAchat, c);
                c.gridx++;
                c.weightx = 1;
                c.gridwidth = GridBagConstraints.REMAINDER;
                ISQLCompteSelector compteAchat = new ISQLCompteSelector();
                this.add(compteAchat, c);

                JLabel labelTaxeAchat = new JLabel(getLabelFor("ID_TAXE_ACHAT"), SwingConstants.RIGHT);
                c.fill = GridBagConstraints.HORIZONTAL;
                c.gridwidth = 1;
                c.gridx = 0;
                c.gridy++;
                this.add(labelTaxeAchat, c);
                c.gridx++;
                c.weightx = 1;
                c.gridwidth = GridBagConstraints.REMAINDER;
                ISQLCompteSelector compteTaxeAchat = new ISQLCompteSelector();
                this.add(compteTaxeAchat, c);

                // Spacer
                c.gridy++;
                c.weighty = 1;
                c.anchor = GridBagConstraints.NORTHWEST;
                this.add(new JPanel(), c);

                this.addSQLObject(compteAchat, "ID_COMPTE_PCE_ACHAT");
                this.addSQLObject(compteVt, "ID_COMPTE_PCE_VENTE");
                this.addSQLObject(compteTaxe, "ID_TAXE_VENTE");
                this.addSQLObject(compteTaxeAchat, "ID_TAXE_ACHAT");
                this.addRequiredSQLObject(fieldNom, "NOM");

            }
        };
    }

    @Override
    protected String createCode() {
        return "finance.accounting.category";
    }
}