OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 57 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.core.supplychain.stock.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.erp.core.sales.product.model.Article;
18
import org.openconcerto.sql.element.BaseSQLComponent;
19
import org.openconcerto.sql.element.SQLComponent;
20
import org.openconcerto.sql.sqlobject.ElementComboBox;
21
import org.openconcerto.ui.DefaultGridBagConstraints;
22
 
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.beans.PropertyChangeEvent;
26
import java.beans.PropertyChangeListener;
27
import java.util.ArrayList;
28
import java.util.List;
29
 
30
import javax.swing.JLabel;
31
import javax.swing.JTextField;
32
 
33
public class ElementStockSQLElement extends ComptaSQLConfElement {
34
 
35
    public ElementStockSQLElement() {
36
        super("ELEMEENt_STOCK", "un article en stock", "articles en stock");
37
    }
38
 
39
    protected List<String> getListFields() {
40
        final List<String> l = new ArrayList<String>();
41
        l.add("ID_ARTICLE");
42
        l.add("QTE_METRIQUE");
43
        l.add("QTE");
44
 
45
        return l;
46
    }
47
 
48
    protected List<String> getComboFields() {
49
        final List<String> l = new ArrayList<String>();
50
        l.add("ID_ARTICLE");
51
        l.add("QTE_METRIQUE");
52
        l.add("QTE");
53
        return l;
54
    }
55
 
56
    /*
57
     * (non-Javadoc)
58
     *
59
     * @see org.openconcerto.devis.SQLElement#getComponent()
60
     */
61
    public SQLComponent createComponent() {
62
 
63
        return new BaseSQLComponent(this) {
64
 
65
            private JTextField textQteMetriques;
66
            private JTextField textQte;
67
 
68
            public void addViews() {
69
                final ElementComboBox articleSelector = new ElementComboBox();
70
 
71
                this.textQteMetriques = new JTextField();
72
                this.textQte = new JTextField();
73
 
74
                this.setLayout(new GridBagLayout());
75
                final GridBagConstraints c = new DefaultGridBagConstraints();
76
 
77
                // Article
78
                this.add(articleSelector, c);
79
 
80
                // Quantité de la métrique, ex: 3 (pour 3 mètres)
81
                c.gridx = 0;
82
                c.gridy++;
83
                final JLabel labelMetrique = new JLabel();
84
                this.add(labelMetrique, c);
85
                c.gridx++;
86
                this.add(this.textQteMetriques, c);
87
                c.gridx++;
88
                final JLabel labelUnite = new JLabel();
89
                this.add(labelUnite, c);
90
                // Quantité, ex 6 pour 6 toles de 3 m
91
                c.gridx = 0;
92
                c.gridy++;
93
                this.add(new JLabel("Quantité"), c);
94
                c.gridx++;
95
                this.add(this.textQte, c);
96
 
97
                this.addRequiredSQLObject(articleSelector, "NOM");
98
                this.addRequiredSQLObject(this.textQteMetriques, "QTE_METRIQUE");
99
                this.addRequiredSQLObject(this.textQte, "QTE");
100
 
101
                articleSelector.addValueListener(new PropertyChangeListener() {
102
 
103
                    public void propertyChange(PropertyChangeEvent evt) {
104
                        if (evt != null) {
105
                            Integer id = Integer.valueOf(evt.getNewValue().toString());
106
                            Article article = new Article(id.intValue());
107
                            labelMetrique.setText(article.getNomPourQuantiteMetrique());
108
                            labelUnite.setText(article.getUnitePourQuantiteMetrique());
109
                        }
110
                    }
111
                });
112
 
113
            }
114
 
115
        };
116
    }
57 ilm 117
 
118
    @Override
119
    protected String createCode() {
156 ilm 120
        return createCodeOfPackage() + ".item";
57 ilm 121
    }
18 ilm 122
}