OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
177 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.panel.compta.ImportFEC;
17
import org.openconcerto.sql.element.SQLElementDirectory;
18
import org.openconcerto.sql.users.UserManager;
19
import org.openconcerto.ui.DefaultGridBagConstraints;
20
import org.openconcerto.ui.ReloadPanel;
21
import org.openconcerto.ui.SwingThreadUtils;
22
 
23
import java.awt.FileDialog;
24
import java.awt.Frame;
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.io.File;
30
import java.io.IOException;
31
import java.sql.SQLException;
32
import java.util.HashMap;
33
import java.util.Map;
34
 
35
import javax.swing.JButton;
36
import javax.swing.JLabel;
37
import javax.swing.JOptionPane;
38
import javax.swing.JPanel;
39
import javax.swing.SwingUtilities;
40
 
41
public class ImportEcritureFECPanel extends JPanel {
42
 
43
    private final Map<String, Integer> mapJournal = new HashMap<>();
44
    private final Map<String, Integer> mapCompte = new HashMap<>();
45
 
46
    public ImportEcritureFECPanel(final SQLElementDirectory dir) {
47
        super(new GridBagLayout());
48
 
49
        JLabel label = new JLabel("Import depuis un fichier au format FEC.");
50
        final JButton button = new JButton("Sélectionner le ficher");
51
        GridBagConstraints c = new DefaultGridBagConstraints();
52
        c.gridwidth = 2;
53
        this.add(label, c);
54
        c.gridy++;
55
        c.gridwidth = 1;
56
        c.weightx = 1;
57
        final ReloadPanel rlPanel = new ReloadPanel();
58
        c.anchor = GridBagConstraints.EAST;
59
        c.fill = GridBagConstraints.NONE;
60
        this.add(rlPanel, c);
61
        c.gridx++;
62
        c.weightx = 0;
63
        this.add(button, c);
64
 
65
        button.addActionListener(new ActionListener() {
66
 
67
            @Override
68
            public void actionPerformed(ActionEvent e) {
69
                button.setEnabled(false);
70
                final Frame frame = SwingThreadUtils.getAncestorOrSelf(Frame.class, ImportEcritureFECPanel.this);
71
                final FileDialog fd = new FileDialog(frame, "Import d'écritures", FileDialog.LOAD);
72
                fd.setVisible(true);
73
                rlPanel.setMode(ReloadPanel.MODE_ROTATE);
74
                if (fd.getFile() != null) {
75
 
76
                    new Thread() {
77
                        @Override
78
                        public void run() {
79
                            final File fileToImport = new File(fd.getDirectory(), fd.getFile());
80
                            ImportFEC fec = new ImportFEC();
81
                            try {
82
                                fec.loadFrom(fileToImport);
83
                                fec.importTo(dir, dir.getElement("ECRITURE").getTable().getDBRoot(), UserManager.getUser());
84
                            } catch (IOException e) {
85
                                // TODO Auto-generated catch block
86
                                e.printStackTrace();
87
                            } catch (SQLException e) {
88
                                // TODO Auto-generated catch block
89
                                e.printStackTrace();
90
                            }finally {
91
                                SwingUtilities.invokeLater(new Runnable() {
92
 
93
                                    @Override
94
                                    public void run() {
95
                                        if (fd != null) {
96
                                            rlPanel.setMode(ReloadPanel.MODE_EMPTY);
97
                                        }
98
                                        JOptionPane.showMessageDialog(null, "Import terminé!");
99
                                    }
100
                                });
101
 
102
                            }
103
                        }
104
                    }.start();
105
                }
106
            }
107
        });
108
    }
109
 
110
}