OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
83 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.product.element;
15
 
16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
17
import org.openconcerto.sql.element.BaseSQLComponent;
18
import org.openconcerto.sql.element.SQLComponent;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.SQLRowValues;
21
import org.openconcerto.sql.sqlobject.ElementComboBox;
22
import org.openconcerto.ui.DefaultGridBagConstraints;
23
import org.openconcerto.ui.FormLayouter;
132 ilm 24
import org.openconcerto.utils.ListMap;
83 ilm 25
 
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.sql.SQLException;
29
import java.util.ArrayList;
30
import java.util.List;
31
 
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.JTextField;
35
import javax.swing.SwingConstants;
36
 
37
public class FamilleArticleFounisseurSQLElement extends ComptaSQLConfElement {
38
 
39
    public FamilleArticleFounisseurSQLElement() {
40
        super("FAMILLE_ARTICLE_FOURNISSEUR", "une famille d'article fournisseur", "familles d'articles fournisseur");
41
    }
42
 
43
    protected List<String> getListFields() {
44
        final List<String> l = new ArrayList<String>();
45
        l.add("NOM");
46
        return l;
47
    }
48
 
49
    protected List<String> getComboFields() {
50
        final List<String> l = new ArrayList<String>();
51
        l.add("NOM");
52
        return l;
53
    }
54
 
55
    @Override
132 ilm 56
    public ListMap<String, String> getShowAs() {
57
        return ListMap.singleton(null, "NOM");
83 ilm 58
    }
59
 
60
    /*
61
     * (non-Javadoc)
62
     *
63
     * @see org.openconcerto.devis.SQLElement#getComponent()
64
     */
65
    public SQLComponent createComponent() {
66
        return new BaseSQLComponent(this) {
67
            public void addViews() {
68
                this.setLayout(new GridBagLayout());
69
                final GridBagConstraints c = new DefaultGridBagConstraints();
70
 
71
                // Nom
72
                final JLabel labelNom = new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT);
73
                c.gridx = 0;
74
                c.weightx = 0;
75
                this.add(labelNom, c);
76
 
77
                final JTextField textNom = new JTextField(15);
78
                c.gridx++;
79
                c.weightx = 1;
80
                DefaultGridBagConstraints.lockMinimumSize(textNom);
81
                this.add(textNom, c);
82
                this.addRequiredSQLObject(textNom, "NOM");
83
 
84
                // Famille père
85
                final JLabel labelFamille = new JLabel(getLabelFor("ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE"), SwingConstants.RIGHT);
86
                c.gridx = 0;
87
                c.gridy++;
88
                c.weightx = 0;
89
                this.add(labelFamille, c);
90
 
91
                final ElementComboBox familleBox = new ElementComboBox(true, 25);
92
                DefaultGridBagConstraints.lockMinimumSize(familleBox);
93
                c.gridx++;
94
                c.weightx = 1;
95
                this.add(familleBox, c);
96
 
97
                this.addSQLObject(familleBox, "ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE");
98
 
99
                // Champ Module
100
                c.gridx = 0;
101
                c.gridy++;
102
                c.gridwidth = GridBagConstraints.REMAINDER;
103
                final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
104
 
105
                this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
106
                c.fill = GridBagConstraints.HORIZONTAL;
107
                c.weightx = 1;
108
                this.add(addP, c);
109
 
110
            }
111
 
112
            @Override
113
            public void update() {
114
                // TODO Auto-generated method stub
115
                super.update();
116
 
117
                SQLRow row = this.getTable().getRow(getSelectedID());
118
                int idPere = row.getInt("ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE");
119
 
120
                // Création du code de famille --> permet de faciliter le filtre de recherche
121
                StringBuffer code = new StringBuffer();
122
                if (idPere > 1) {
123
                    SQLRow rowPere = this.getTable().getRow(idPere);
124
                    code.append(rowPere.getString("CODE"));
125
                } else {
126
                    code.append('1');
127
                }
128
                code.append("." + getSelectedID());
129
 
130
                SQLRowValues rowVals = new SQLRowValues(this.getTable());
131
                rowVals.put("CODE", code.toString());
132
 
133
                try {
134
                    rowVals.update(getSelectedID());
135
                } catch (SQLException e) {
136
                    e.printStackTrace();
137
                }
138
 
139
            }
140
 
141
            @Override
142
            public int insert(SQLRow order) {
143
 
144
                int id = super.insert(order);
145
                SQLRow row = this.getTable().getRow(id);
146
                int idPere = row.getInt("ID_FAMILLE_ARTICLE_FOURNISSEUR_PERE");
147
 
148
                // Création du code de famille --> permet de faciliter le filtre de recherche
149
                StringBuffer code = new StringBuffer();
150
                if (idPere > 1) {
151
                    SQLRow rowPere = this.getTable().getRow(idPere);
152
                    code.append(rowPere.getString("CODE"));
153
                } else {
154
                    code.append('1');
155
                }
156
                code.append("." + id);
157
 
158
                SQLRowValues rowVals = new SQLRowValues(this.getTable());
159
                rowVals.put("CODE", code.toString());
160
 
161
                try {
162
                    rowVals.update(id);
163
                } catch (SQLException e) {
164
                    e.printStackTrace();
165
                }
166
 
167
                return id;
168
            }
169
        };
170
    }
171
 
172
    @Override
173
    protected String createCode() {
156 ilm 174
        return createCodeOfPackage() + ".family";
83 ilm 175
    }
176
}