OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 28 | Rev 61 | Go to most recent revision | 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.humanresources.employe.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.sqlobject.ElementComboBox;
20
import org.openconcerto.ui.DefaultGridBagConstraints;
28 ilm 21
import org.openconcerto.ui.FormLayouter;
22
import org.openconcerto.utils.CollectionMap;
18 ilm 23
import org.openconcerto.utils.text.SimpleDocumentListener;
24
 
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.util.ArrayList;
28
import java.util.List;
29
 
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JTextField;
33
import javax.swing.SwingConstants;
34
import javax.swing.event.DocumentEvent;
35
import javax.swing.event.DocumentListener;
36
 
37
public class CommercialSQLElement extends ComptaSQLConfElement {
38
 
39
    public CommercialSQLElement() {
40
        super("COMMERCIAL", "un commercial", "commerciaux");
41
    }
42
 
43
    public CommercialSQLElement(String tableName, String singular, String plural) {
44
        super(tableName, singular, plural);
45
    }
46
 
47
    protected List<String> getListFields() {
48
        final List<String> l = new ArrayList<String>();
49
        l.add("NOM");
50
        l.add("PRENOM");
51
        l.add("FONCTION");
52
        l.add("TEL_STANDARD");
53
        l.add("TEL_DIRECT");
54
        return l;
55
    }
56
 
57
    protected List<String> getComboFields() {
58
        final List<String> l = new ArrayList<String>();
59
        l.add("NOM");
60
        l.add("PRENOM");
61
        l.add("FONCTION");
62
 
63
        return l;
64
    }
65
 
28 ilm 66
    @Override
67
    public CollectionMap<String, String> getShowAs() {
68
        final CollectionMap<String, String> res = new CollectionMap<String, String>();
69
        res.put(null, "NOM");
70
        return res;
71
    }
72
 
18 ilm 73
    /*
74
     * (non-Javadoc)
75
     *
76
     * @see org.openconcerto.devis.SQLElement#getComponent()
77
     */
78
    public SQLComponent createComponent() {
79
        return new BaseSQLComponent(this) {
80
 
81
            JTextField textInitiale;
82
            JTextField textPrenom, textNom;
83
 
84
            DocumentListener listener = new SimpleDocumentListener() {
85
 
86
                @Override
87
                public void update(DocumentEvent e) {
88
                    updateInititale();
89
                }
90
            };
91
 
92
            private void updateInititale() {
93
                String s = "";
94
                if (this.textPrenom.getText().trim().length() > 0) {
95
                    s += this.textPrenom.getText().trim().charAt(0);
96
                }
97
                if (this.textNom.getText().trim().length() > 0) {
98
                    s += this.textNom.getText().trim().charAt(0);
99
                }
100
                this.textInitiale.setText(s);
101
            }
102
 
103
            public void addViews() {
104
                this.setLayout(new GridBagLayout());
105
 
106
                GridBagConstraints c = new DefaultGridBagConstraints();
107
 
108
                // Titre personnel
109
                final JLabel label = new JLabel(getLabelFor("ID_TITRE_PERSONNEL"));
110
                label.setHorizontalAlignment(SwingConstants.RIGHT);
111
                this.add(label, c);
112
                ElementComboBox selTitre = new ElementComboBox(false, 6);
113
 
114
                c.gridx++;
115
                c.fill = GridBagConstraints.NONE;
116
                c.gridwidth = GridBagConstraints.REMAINDER;
117
                this.add(selTitre, c);
118
 
119
                // Nom
120
                c.gridx = 0;
121
                c.gridy++;
122
                c.gridwidth = 1;
123
                c.fill = GridBagConstraints.HORIZONTAL;
124
                final JLabel label2 = new JLabel(getLabelFor("NOM"));
125
                label2.setHorizontalAlignment(SwingConstants.RIGHT);
126
                this.add(label2, c);
127
                this.textNom = new JTextField(21);
128
                c.gridx++;
129
                c.weightx = 1;
130
                this.add(this.textNom, c);
131
                this.textNom.getDocument().addDocumentListener(this.listener);
132
 
133
                // Prenom
134
                c.gridx++;
135
                c.weightx = 0;
136
                final JLabel label3 = new JLabel(getLabelFor("PRENOM"));
137
                label3.setHorizontalAlignment(SwingConstants.RIGHT);
138
                this.add(label3, c);
139
                this.textPrenom = new JTextField(21);
140
                c.gridx++;
141
                c.weightx = 1;
142
                this.add(this.textPrenom, c);
143
                this.textPrenom.getDocument().addDocumentListener(this.listener);
144
 
145
                // // Initiales
146
                c.gridx = 0;
147
                c.gridy++;
148
                c.weightx = 0;
149
                final JLabel label4 = new JLabel("Initiales");
150
                label4.setHorizontalAlignment(SwingConstants.RIGHT);
151
                this.add(label4, c);
152
                c.gridx++;
153
                c.weightx = 1;
154
                c.fill = GridBagConstraints.NONE;
155
                this.textInitiale = new JTextField(2);
156
                this.textInitiale.setEditable(false);
157
                this.add(this.textInitiale, c);
158
                c.fill = GridBagConstraints.HORIZONTAL;
159
 
160
                // Fonction
161
                c.gridx++;
162
                c.weightx = 0;
163
                final JLabel label5 = new JLabel(getLabelFor("FONCTION"));
164
                label5.setHorizontalAlignment(SwingConstants.RIGHT);
165
                this.add(label5, c);
166
                JTextField textFonction = new JTextField();
167
                c.gridx++;
168
                c.weightx = 1;
169
                this.add(textFonction, c);
170
 
171
                // Tel Standard
172
                c.gridx = 0;
173
                c.gridy++;
174
                c.weightx = 0;
175
                final JLabel label6 = new JLabel(getLabelFor("TEL_STANDARD"));
176
                label6.setHorizontalAlignment(SwingConstants.RIGHT);
177
                this.add(label6, c);
178
                c.gridx++;
179
                c.weightx = 1;
180
                JTextField textTel = new JTextField();
181
                this.add(textTel, c);
182
 
183
                // Tel direct
184
                c.gridx++;
185
                c.weightx = 0;
186
                final JLabel label7 = new JLabel(getLabelFor("TEL_DIRECT"));
187
                label7.setHorizontalAlignment(SwingConstants.RIGHT);
188
                this.add(label7, c);
189
                JTextField textTelD = new JTextField();
190
                c.gridx++;
191
                c.weightx = 1;
192
                this.add(textTelD, c);
193
 
194
                // Tel Mobile
195
                c.gridx = 0;
196
                c.gridy++;
197
                c.weightx = 0;
198
                final JLabel label8 = new JLabel(getLabelFor("TEL_MOBILE"));
199
                label8.setHorizontalAlignment(SwingConstants.RIGHT);
200
                this.add(label8, c);
201
                c.gridx++;
202
                c.weightx = 1;
203
                JTextField textTelM = new JTextField();
204
                this.add(textTelM, c);
205
 
206
                // Tel Perso
207
                c.gridx++;
208
                c.weightx = 0;
209
                final JLabel label9 = new JLabel(getLabelFor("TEL_PERSONEL"));
210
                label9.setHorizontalAlignment(SwingConstants.RIGHT);
211
                this.add(label9, c);
212
                JTextField textTelP = new JTextField();
213
                c.gridx++;
214
                c.weightx = 1;
215
                this.add(textTelP, c);
216
 
217
                // Tel Fax
218
                c.gridx = 0;
219
                c.gridy++;
220
                c.weightx = 0;
221
                final JLabel label10 = new JLabel(getLabelFor("FAX"));
222
                label10.setHorizontalAlignment(SwingConstants.RIGHT);
223
                this.add(label10, c);
224
                c.gridx++;
225
                c.weightx = 1;
226
                JTextField textFax = new JTextField();
227
                this.add(textFax, c);
228
 
229
                // Tel Email
230
                c.gridx++;
231
                c.weightx = 0;
232
                final JLabel label11 = new JLabel(getLabelFor("EMAIL"));
233
                label11.setHorizontalAlignment(SwingConstants.RIGHT);
234
                this.add(label11, c);
235
                JTextField textMail = new JTextField();
236
                c.gridx++;
237
                c.weightx = 1;
238
                this.add(textMail, c);
239
 
28 ilm 240
                // Modules
241
                c.gridx = 0;
242
                c.gridy++;
243
                c.gridwidth = GridBagConstraints.REMAINDER;
244
                final JPanel addP = new JPanel();
245
                this.setAdditionalFieldsPanel(new FormLayouter(addP, 1));
246
                this.add(addP, c);
247
 
18 ilm 248
                // User
249
 
250
                c.gridx = 0;
251
                c.gridy++;
28 ilm 252
                c.gridwidth = 1;
18 ilm 253
                c.weightx = 0;
254
                final JLabel labelUser = new JLabel(getLabelFor("ID_USER_COMMON"));
255
                labelUser.setHorizontalAlignment(SwingConstants.RIGHT);
256
                this.add(labelUser, c);
257
                c.gridx++;
258
                c.weightx = 1;
259
 
260
                c.gridwidth = GridBagConstraints.REMAINDER;
261
                ElementComboBox comboUser = new ElementComboBox(true, 25);
262
                this.add(comboUser, c);
263
 
264
                c.weighty = 1;
265
                c.gridy++;
266
                this.add(new JPanel(), c);
267
 
268
                this.addRequiredSQLObject(selTitre, "ID_TITRE_PERSONNEL");
269
                selTitre.setButtonsVisible(false);
270
                this.addRequiredSQLObject(this.textNom, "NOM");
271
                this.addRequiredSQLObject(this.textPrenom, "PRENOM");
272
 
273
                this.addSQLObject(textFonction, "FONCTION");
274
 
275
                this.addSQLObject(comboUser, "ID_USER_COMMON");
276
 
277
                this.addSQLObject(textTel, "TEL_STANDARD");
278
                this.addSQLObject(textTelD, "TEL_DIRECT");
279
 
280
                this.addSQLObject(textTelM, "TEL_MOBILE");
281
                this.addSQLObject(textTelP, "TEL_PERSONEL");
282
 
283
                this.addSQLObject(textFax, "FAX");
284
                this.addSQLObject(textMail, "EMAIL");
285
 
286
                // Locks
287
                DefaultGridBagConstraints.lockMinimumSize(this.textInitiale);
288
                DefaultGridBagConstraints.lockMinimumSize(selTitre);
289
 
290
            }
291
        };
292
    }
57 ilm 293
 
294
    @Override
295
    protected String createCode() {
296
        return super.createCodeFromPackage() + ".salesman";
297
    }
18 ilm 298
}