OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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