OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
180 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
 /*
15
 * Créé le 23 avr. 2012
16
 */
17
package org.openconcerto.erp.core.customerrelationship.customer.report;
18
 
19
import org.openconcerto.sql.model.DBRoot;
20
import org.openconcerto.ui.DefaultGridBagConstraints;
21
import org.openconcerto.ui.JDate;
22
import org.openconcerto.utils.ExceptionHandler;
23
 
24
import java.awt.Desktop;
25
import java.awt.Frame;
26
import java.awt.GridBagConstraints;
27
import java.awt.GridBagLayout;
28
import java.awt.event.ActionEvent;
29
import java.beans.PropertyChangeEvent;
30
import java.beans.PropertyChangeListener;
31
import java.io.File;
32
import java.io.IOException;
33
import java.util.ArrayList;
34
import java.util.Calendar;
35
import java.util.List;
36
 
37
import javax.swing.AbstractAction;
38
import javax.swing.JButton;
39
import javax.swing.JLabel;
40
import javax.swing.JPanel;
41
import javax.swing.SwingUtilities;
42
 
43
public class ReportingCommercialFournisseurPanel extends JPanel {
44
 
45
    public ReportingCommercialFournisseurPanel(final DBRoot root) {
46
        super(new GridBagLayout());
47
 
48
        JLabel labelCom = new JLabel("Période du ");
49
 
50
        GridBagConstraints c = new DefaultGridBagConstraints();
51
        this.add(labelCom, c);
52
        c.gridx++;
53
        final JDate dateDeb = new JDate();
54
        this.add(dateDeb, c);
55
        c.gridx++;
56
        JLabel labelYear = new JLabel("au");
57
        final JDate dateFin = new JDate();
58
 
59
        Calendar cal = Calendar.getInstance();
60
        cal.set(Calendar.MONTH, Calendar.JANUARY);
61
        cal.set(Calendar.DAY_OF_MONTH, 1);
62
        dateDeb.setValue(cal.getTime());
63
 
64
        this.add(labelYear, c);
65
        c.gridx++;
66
        this.add(dateFin, c);
67
        cal.set(Calendar.MONTH, Calendar.DECEMBER);
68
        cal.set(Calendar.DAY_OF_MONTH, 31);
69
        dateFin.setValue(cal.getTime());
70
 
71
        final JButton buttonValid = new JButton(new AbstractAction("Valider") {
72
 
73
            @Override
74
            public void actionPerformed(ActionEvent e) {
75
 
76
                new Thread() {
77
                    public void run() {
78
                        ReportingCommercialFournisseurCreator creator = new ReportingCommercialFournisseurCreator(dateDeb.getValue(), dateFin.getValue(), root);
79
 
80
                        List<ReportingCommercial> list = new ArrayList<>(creator.getValues());
81
                        ReportingCommercialPDF reporting = new ReportingCommercialPDF(list);
82
                        File file;
83
                        try {
84
                            file = File.createTempFile("ReportingCommericalFournisseur", ".pdf");
85
                            reporting.export(file);
86
                            Desktop.getDesktop().open(file);
87
                        } catch (IOException e) {
88
                            ExceptionHandler.handle("Erreur lors de la cration du fichier", e);
89
                        }
90
                        SwingUtilities.invokeLater(new Runnable() {
91
 
92
                            @Override
93
                            public void run() {
94
                                Frame frame = (Frame) SwingUtilities.getRoot(ReportingCommercialFournisseurPanel.this);
95
                                if (frame != null) {
96
                                    frame.dispose();
97
                                }
98
                            }
99
                        });
100
                    };
101
                }.start();
102
 
103
            }
104
 
105
        });
106
        c.gridx++;
107
        // buttonValid.setEnabled(false);
108
        this.add(buttonValid, c);
109
        dateDeb.addValueListener(new PropertyChangeListener() {
110
 
111
            @Override
112
            public void propertyChange(PropertyChangeEvent evt) {
113
                buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null);
114
            }
115
        });
116
        dateFin.addValueListener(new PropertyChangeListener() {
117
 
118
            @Override
119
            public void propertyChange(PropertyChangeEvent evt) {
120
                buttonValid.setEnabled(dateDeb.getValue() != null && dateFin.getValue() != null);
121
            }
122
        });
123
    }
124
 
125
}