OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Go to most recent revision | Details | 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.finance.accounting.ui;
15
 
16
 
17
import org.openconcerto.erp.generationDoc.gestcomm.PointageXmlSheet;
18
import org.openconcerto.sql.Configuration;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.request.ComboSQLRequest;
21
import org.openconcerto.sql.sqlobject.SQLRequestComboBox;
22
import org.openconcerto.ui.DefaultGridBagConstraints;
23
 
24
 
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.beans.PropertyChangeEvent;
30
import java.beans.PropertyChangeListener;
31
import java.util.Calendar;
32
 
33
 
34
import javax.swing.JButton;
35
import javax.swing.JFrame;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
import javax.swing.JSpinner;
39
import javax.swing.JTextArea;
40
import javax.swing.SpinnerModel;
41
import javax.swing.SpinnerNumberModel;
42
import javax.swing.SwingUtilities;
43
 
44
public class GenerationPointagePanel extends JPanel implements ActionListener {
45
    private final JButton gen = new JButton("Générer");
46
    private final JButton close = new JButton("Fermer");
47
    private final SQLRequestComboBox combo = new SQLRequestComboBox(false);
48
 
49
    private final int currentYear = Calendar.getInstance().get(Calendar.YEAR);
50
    private final SpinnerModel model = new SpinnerNumberModel(this.currentYear, this.currentYear - 5, this.currentYear + 5, 1);
51
    private final JSpinner spinYear = new JSpinner(this.model);
52
 
53
    final JTextArea infos = new JTextArea();
54
 
55
    public GenerationPointagePanel() {
56
        super(new GridBagLayout());
57
        GridBagConstraints c = new DefaultGridBagConstraints();
58
        SQLElement moisElt = Configuration.getInstance().getDirectory().getElement("MOIS");
59
 
60
        // Mois
61
        this.add(new JLabel("Mois"), c);
62
        c.gridx++;
63
 
64
        ComboSQLRequest comboReq = new ComboSQLRequest(moisElt.getComboRequest());
65
        this.combo.uiInit(comboReq);
66
        this.add(this.combo, c);
67
 
68
        // Annee
69
        this.add(new JLabel("Année"), c);
70
        c.gridx++;
71
 
72
        this.add(this.spinYear, c);
73
 
74
 
75
        JPanel panelButton = new JPanel();
76
        panelButton.add(this.gen);
77
        panelButton.add(this.close);
78
        this.gen.setEnabled(false);
79
 
80
        c.fill = GridBagConstraints.NONE;
81
        c.weightx = 0;
82
        c.anchor = GridBagConstraints.EAST;
83
        c.weighty = 0;
84
        c.gridy++;
85
        this.add(panelButton, c);
86
 
87
        this.combo.addValueListener(new PropertyChangeListener() {
88
            @Override
89
            public void propertyChange(PropertyChangeEvent evt) {
90
                gen.setEnabled(combo.getSelectedRow() != null);
91
            }
92
        });
93
 
94
        this.gen.addActionListener(this);
95
        this.close.addActionListener(this);
96
    }
97
 
98
    @Override
99
    public void actionPerformed(ActionEvent e) {
100
        if (e.getSource() == this.gen) {
101
 
102
            int mois = this.combo.getValue() - 2;
103
            int year = Integer.valueOf(this.spinYear.getValue().toString());
104
            PointageXmlSheet sheet = new PointageXmlSheet(mois, year);
105
            sheet.genere(true, false);
106
        } else {
107
            if (e.getSource() == this.close) {
108
                ((JFrame) SwingUtilities.getRoot(this)).dispose();
109
            }
110
        }
111
    }
112
}