OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | 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.payroll.element;
15
 
156 ilm 16
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
18 ilm 17
import org.openconcerto.erp.core.common.ui.SQLJavaEditor;
18
import org.openconcerto.erp.core.humanresources.payroll.component.FormuleTreeNode;
57 ilm 19
import org.openconcerto.erp.core.humanresources.payroll.component.RubriqueSQLComponent;
18 ilm 20
import org.openconcerto.erp.core.humanresources.payroll.component.VariableTree;
21
import org.openconcerto.sql.element.ElementSQLObject;
22
import org.openconcerto.sql.element.SQLComponent;
23
import org.openconcerto.sql.element.SQLElement;
156 ilm 24
import org.openconcerto.sql.model.DBRoot;
18 ilm 25
import org.openconcerto.sql.sqlobject.ElementComboBox;
156 ilm 26
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
18 ilm 27
import org.openconcerto.ui.DefaultGridBagConstraints;
28
 
29
import java.awt.GridBagConstraints;
30
import java.awt.GridBagLayout;
31
import java.awt.Insets;
32
import java.awt.event.MouseAdapter;
33
import java.awt.event.MouseEvent;
34
import java.beans.PropertyChangeEvent;
35
import java.beans.PropertyChangeListener;
36
import java.util.ArrayList;
37
import java.util.List;
38
import java.util.Map;
39
 
40
import javax.swing.BorderFactory;
41
import javax.swing.ButtonGroup;
42
import javax.swing.JCheckBox;
43
import javax.swing.JLabel;
44
import javax.swing.JPanel;
45
import javax.swing.JRadioButton;
46
import javax.swing.JScrollPane;
47
import javax.swing.JSplitPane;
48
import javax.swing.JTabbedPane;
49
import javax.swing.SwingConstants;
50
import javax.swing.tree.TreePath;
51
 
156 ilm 52
public class RubriqueCommSQLElement extends ComptaSQLConfElement {
18 ilm 53
 
156 ilm 54
    public RubriqueCommSQLElement(final DBRoot root) {
55
        super(root.getTable("RUBRIQUE_COMM"), "une rubrique de commentaire", "rubriques de commentaire");
18 ilm 56
    }
57
 
58
    protected List<String> getListFields() {
59
        final List<String> l = new ArrayList<String>();
60
        l.add("CODE");
61
        l.add("NOM");
62
        return l;
63
    }
64
 
65
    protected List<String> getComboFields() {
66
        final List<String> l = new ArrayList<String>();
67
        l.add("CODE");
68
        l.add("NOM");
69
        return l;
70
    }
71
 
72
    /*
73
     * (non-Javadoc)
74
     *
75
     * @see org.openconcerto.devis.SQLElement#getComponent()
76
     */
77
    public SQLComponent createComponent() {
21 ilm 78
        return new RubriqueSQLComponent(this) {
18 ilm 79
 
80
            private SQLJavaEditor formuleBase, formuleTxSal, formuleTxPat, formuleMontantSalAd, formuleMontantSalDed, formuleMontantPat;
81
 
21 ilm 82
            @Override
83
            protected boolean newline() {
84
                return false;
85
            }
18 ilm 86
 
21 ilm 87
            @Override
88
            protected void addViews(GridBagConstraints c) {
18 ilm 89
                JCheckBox checkAffichNom = new JCheckBox(getLabelFor("NOM_VISIBLE"));
90
                c.gridx++;
91
                c.gridwidth = 1;
92
                c.weightx = 0;
93
                this.add(checkAffichNom, c);
94
                checkAffichNom.setSelected(true);
95
 
96
                /***********************************************************************************
97
                 * PANEL CALCUL
98
                 **********************************************************************************/
99
                JPanel panelCalcul = new JPanel();
100
                panelCalcul.setLayout(new GridBagLayout());
101
                final GridBagConstraints cPanel = new DefaultGridBagConstraints();
102
 
103
                final VariableTree tree = new VariableTree();
104
                JScrollPane paneTree = new JScrollPane(tree);
105
 
106
                cPanel.gridheight = GridBagConstraints.REMAINDER;
107
                cPanel.weighty = 1;
108
                cPanel.weightx = 1;
109
                cPanel.fill = GridBagConstraints.BOTH;
110
                // panelCalcul.add(paneTree, cPanel);
111
                cPanel.fill = GridBagConstraints.HORIZONTAL;
112
                cPanel.weighty = 0;
113
                cPanel.weightx = 0;
114
                cPanel.gridheight = 1;
115
 
116
                // Formule base
117
                cPanel.gridx++;
118
                final Map<String, List<?>> mapTree = VariablePayeSQLElement.getMapTree();
119
                this.formuleBase = new SQLJavaEditor(mapTree);
120
                this.formuleBase.setVarAssign("BASE");
121
 
122
                final JRadioButton radioBase = new JRadioButton(getLabelFor("NB_BASE"));
123
                panelCalcul.add(radioBase, cPanel);
124
                cPanel.gridx++;
125
                panelCalcul.add(this.formuleBase, cPanel);
126
 
127
                // Formule Tx Sal
128
                cPanel.gridy++;
129
                cPanel.gridx = 1;
130
 
131
                this.formuleTxSal = new SQLJavaEditor(mapTree);
132
                this.formuleTxSal.setVarAssign("SAL");
133
                final JRadioButton radioTxSal = new JRadioButton(getLabelFor("TAUX_SAL"));
134
                panelCalcul.add(radioTxSal, cPanel);
135
                cPanel.gridx++;
136
                panelCalcul.add(this.formuleTxSal, cPanel);
137
 
138
                // Montant Sal Ad
139
                cPanel.gridy++;
140
                cPanel.gridx = 1;
141
                this.formuleMontantSalAd = new SQLJavaEditor(mapTree);
142
                this.formuleMontantSalAd.setVarAssign("MONTANT");
143
                final JRadioButton radioMontantsalAd = new JRadioButton(getLabelFor("MONTANT_SAL_AJ"));
144
                panelCalcul.add(radioMontantsalAd, cPanel);
145
                cPanel.gridx++;
146
                panelCalcul.add(this.formuleMontantSalAd, cPanel);
147
 
148
                // Montant Sal Ded
149
                cPanel.gridy++;
150
                cPanel.gridx = 1;
151
                this.formuleMontantSalDed = new SQLJavaEditor(mapTree);
152
                this.formuleMontantSalDed.setVarAssign("MONTANT");
153
                final JRadioButton radioMontantSalDed = new JRadioButton(getLabelFor("MONTANT_SAL_DED"));
154
                panelCalcul.add(radioMontantSalDed, cPanel);
155
                cPanel.gridx++;
156
                panelCalcul.add(this.formuleMontantSalDed, cPanel);
157
 
158
                // Formule Tx Pat
159
                cPanel.gridy++;
160
                cPanel.gridx = 1;
161
                this.formuleTxPat = new SQLJavaEditor(mapTree);
162
                this.formuleTxPat.setVarAssign("PAT");
163
                final JRadioButton radioTxPat = new JRadioButton(getLabelFor("TAUX_PAT"));
164
                panelCalcul.add(radioTxPat, cPanel);
165
                cPanel.gridx++;
166
                panelCalcul.add(this.formuleTxPat, cPanel);
167
 
168
                // Montant Pat
169
                cPanel.gridy++;
170
                cPanel.gridx = 1;
171
                this.formuleMontantPat = new SQLJavaEditor(mapTree);
172
                this.formuleMontantPat.setVarAssign("MONTANT");
173
                final JRadioButton radioMontantPat = new JRadioButton(getLabelFor("MONTANT_PAT"));
174
                panelCalcul.add(radioMontantPat, cPanel);
175
                cPanel.gridx++;
176
                panelCalcul.add(this.formuleMontantPat, cPanel);
177
 
178
                ButtonGroup group1 = new ButtonGroup();
179
                group1.add(radioBase);
180
                group1.add(radioTxPat);
181
                group1.add(radioTxSal);
182
                group1.add(radioMontantPat);
183
                group1.add(radioMontantsalAd);
184
                group1.add(radioMontantSalDed);
185
                radioBase.setSelected(true);
186
 
187
                // Salarie
188
                cPanel.gridy++;
189
                cPanel.gridx = 1;
190
                JLabel labelSelSal = new JLabel("Salarié");
191
                labelSelSal.setHorizontalAlignment(SwingConstants.RIGHT);
192
                panelCalcul.add(labelSelSal, cPanel);
193
 
80 ilm 194
                final SQLElement eltSal = getDirectory().getElement(SalarieSQLElement.class);
18 ilm 195
                final ElementComboBox selSalarie = new ElementComboBox(false);
196
 
197
                cPanel.gridx++;
198
                selSalarie.init(eltSal);
199
                panelCalcul.add(selSalarie, cPanel);
200
 
201
                /***********************************************************************************
202
                 * PANEL PROPRIETE
203
                 **********************************************************************************/
204
                JPanel panelProp = new JPanel();
205
                panelProp.setLayout(new GridBagLayout());
206
                cPanel.gridx = 0;
207
                cPanel.gridy = 0;
208
                cPanel.weightx = 0;
209
                cPanel.weighty = 0;
210
                cPanel.gridwidth = 1;
211
                cPanel.gridheight = 1;
212
                cPanel.fill = GridBagConstraints.HORIZONTAL;
213
                cPanel.anchor = GridBagConstraints.NORTHWEST;
214
                cPanel.insets = new Insets(2, 2, 1, 2);
215
 
216
                // Periode d'application
217
                this.addView("ID_PERIODE_VALIDITE", REQ + ";" + DEC + ";" + SEP);
218
                ElementSQLObject eltInfosPaye = (ElementSQLObject) this.getView("ID_PERIODE_VALIDITE");
219
                cPanel.gridy = 0;
220
                cPanel.gridx = 0;
221
                cPanel.gridheight = GridBagConstraints.REMAINDER;
222
                JPanel panelPeriodeVal = new JPanel();
223
                panelPeriodeVal.setBorder(BorderFactory.createTitledBorder("Période de validité"));
224
                panelPeriodeVal.add(eltInfosPaye);
225
                cPanel.fill = GridBagConstraints.NONE;
226
                cPanel.weightx = 0;
227
                cPanel.weighty = 1;
228
                panelProp.add(panelPeriodeVal, cPanel);
229
                cPanel.weightx = 0;
230
                cPanel.weighty = 0;
231
                cPanel.gridheight = 1;
232
                cPanel.fill = GridBagConstraints.HORIZONTAL;
233
 
234
                // Impression
235
                JLabel labelSelTypeImpression = new JLabel("Impression");
236
                cPanel.gridy++;
237
                cPanel.gridx = 1;
238
                cPanel.weightx = 0;
239
                panelProp.add(labelSelTypeImpression, cPanel);
240
 
156 ilm 241
                SQLRequestComboBox comboSelTypeImpression = new SQLRequestComboBox(false);
18 ilm 242
                cPanel.gridx++;
243
                cPanel.weightx = 1;
244
                panelProp.add(comboSelTypeImpression, cPanel);
245
 
151 ilm 246
                // Impression
247
                JCheckBox boxReduction = new JCheckBox("Avantage baisse des cotisations");
248
                cPanel.gridy++;
249
                cPanel.gridx = 1;
250
                cPanel.gridwidth = 2;
251
                cPanel.weightx = 0;
252
                addView(boxReduction, "REDUCTION_GVT_COM");
253
                panelProp.add(boxReduction, cPanel);
254
                cPanel.gridwidth = 1;
255
 
18 ilm 256
                // Tabbed Pane
257
                JTabbedPane tab = new JTabbedPane();
258
                tab.add("Calcul", new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, paneTree, panelCalcul));
259
                tab.add("Propriétés", panelProp);
260
 
261
                c.gridwidth = GridBagConstraints.REMAINDER;
262
                c.gridy++;
263
                c.gridx = 0;
264
                c.fill = GridBagConstraints.BOTH;
265
                c.weightx = 1;
266
                c.weighty = 1;
267
                this.add(tab, c);
268
 
269
                tree.addMouseListener(new MouseAdapter() {
270
 
271
                    public void mousePressed(MouseEvent e) {
272
 
273
                        if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
274
                            TreePath path = tree.getClosestPathForLocation(e.getPoint().x, e.getPoint().y);
275
 
276
                            final Object obj = path.getLastPathComponent();
277
 
278
                            if (obj == null) {
279
                                return;
280
                            } else {
281
                                if (obj instanceof FormuleTreeNode) {
282
                                    FormuleTreeNode n = (FormuleTreeNode) obj;
283
 
284
                                    if (radioBase.isSelected()) {
285
                                        int start = formuleBase.getSelectionStart();
286
                                        String tmp = formuleBase.getText();
287
 
288
                                        formuleBase.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
289
                                    } else {
290
 
291
                                        if (radioTxPat.isSelected()) {
292
                                            int start = formuleTxPat.getSelectionStart();
293
                                            String tmp = formuleTxPat.getText();
294
 
295
                                            formuleTxPat.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
296
                                        } else {
297
                                            if (radioMontantPat.isSelected()) {
298
                                                int start = formuleMontantPat.getSelectionStart();
299
                                                String tmp = formuleMontantPat.getText();
300
 
301
                                                formuleMontantPat.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
302
                                            } else {
303
                                                if (radioMontantsalAd.isSelected()) {
304
                                                    int start = formuleMontantSalAd.getSelectionStart();
305
                                                    String tmp = formuleMontantSalAd.getText();
306
 
307
                                                    formuleMontantSalAd.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
308
                                                } else {
309
                                                    if (radioMontantSalDed.isSelected()) {
310
                                                        int start = formuleMontantSalDed.getSelectionStart();
311
                                                        String tmp = formuleMontantSalDed.getText();
312
 
313
                                                        formuleMontantSalDed.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length()));
314
                                                    }
315
                                                }
316
                                            }
317
 
318
                                        }
319
                                    }
320
                                }
321
 
322
                            }
323
                        }
324
                    }
325
                });
326
 
327
                this.addSQLObject(this.formuleBase, "NB_BASE");
328
                this.addSQLObject(this.formuleTxPat, "TAUX_PAT");
329
                this.addSQLObject(this.formuleTxSal, "TAUX_SAL");
330
                this.addSQLObject(this.formuleMontantPat, "MONTANT_PAT");
331
                this.addSQLObject(this.formuleMontantSalAd, "MONTANT_SAL_AJ");
332
                this.addSQLObject(this.formuleMontantSalDed, "MONTANT_SAL_DED");
333
                this.addRequiredSQLObject(comboSelTypeImpression, "ID_IMPRESSION_RUBRIQUE");
334
                this.addRequiredSQLObject(checkAffichNom, "NOM_VISIBLE");
335
 
336
                selSalarie.addValueListener(new PropertyChangeListener() {
337
                    public void propertyChange(PropertyChangeEvent evt) {
338
 
339
                        formuleBase.setSalarieID(selSalarie.getSelectedId());
340
                        formuleTxPat.setSalarieID(selSalarie.getSelectedId());
341
                        formuleTxSal.setSalarieID(selSalarie.getSelectedId());
342
                        formuleMontantPat.setSalarieID(selSalarie.getSelectedId());
343
                        formuleMontantSalAd.setSalarieID(selSalarie.getSelectedId());
344
                        formuleMontantSalDed.setSalarieID(selSalarie.getSelectedId());
345
                    }
346
                });
347
 
348
            }
349
        };
350
    }
57 ilm 351
 
352
    @Override
353
    protected String createCode() {
354
        return "humanresources.payroll.category.comment";
355
    }
18 ilm 356
}