OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Rev 28 | 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.sales.quote.action;
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
18
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
19
import org.openconcerto.erp.core.common.ui.IListTotalPanel;
20
import org.openconcerto.erp.core.common.ui.PanelFrame;
21
import org.openconcerto.erp.core.sales.quote.element.DevisSQLElement;
22
import org.openconcerto.erp.core.sales.quote.report.DevisTextSheet;
23
import org.openconcerto.erp.core.sales.quote.ui.ListeDesDevisPanel;
25 ilm 24
import org.openconcerto.erp.generationDoc.DocumentLocalStorageManager;
18 ilm 25
import org.openconcerto.erp.generationDoc.SheetUtils;
26
import org.jopendocument.link.OOConnexion;
27
import org.openconcerto.sql.Configuration;
28
import org.openconcerto.sql.model.SQLField;
29
import org.openconcerto.sql.model.SQLRow;
30
import org.openconcerto.sql.view.IListFrame;
31
import org.openconcerto.sql.view.ListeAddPanel;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.utils.ExceptionHandler;
34
 
35
import java.awt.Font;
36
import java.awt.GridBagConstraints;
37
import java.awt.event.ActionEvent;
38
import java.awt.event.ActionListener;
39
import java.awt.event.MouseEvent;
40
import java.awt.event.MouseListener;
41
import java.io.File;
42
import java.text.DateFormat;
43
import java.text.SimpleDateFormat;
44
import java.util.ArrayList;
45
import java.util.Date;
46
import java.util.List;
47
 
48
import javax.swing.AbstractAction;
49
import javax.swing.Action;
50
import javax.swing.JFrame;
51
import javax.swing.JMenu;
52
import javax.swing.JMenuItem;
53
import javax.swing.JPopupMenu;
54
 
55
public class ListeDesDevisAction extends CreateFrameAbstractAction implements MouseListener {
56
 
57
    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
58
 
59
    public ListeDesDevisAction() {
60
        super();
61
        this.putValue(Action.NAME, "Liste des devis");
62
    }
63
 
64
    IListFrame frame = null;
65
    final DevisSQLElement element = (DevisSQLElement) Configuration.getInstance().getDirectory().getElement("DEVIS");
66
 
67
    public JFrame createFrame() {
68
            final PanelFrame frame2 = new PanelFrame(new ListeDesDevisPanel(), "Liste des devis");
69
            return frame2;
70
    }
71
 
72
    public void mouseClicked(MouseEvent e) {
73
    }
74
 
75
    public void mousePressed(MouseEvent e) {
76
 
77
        int selectedId = this.frame.getPanel().getListe().getSelectedId();
78
        if (selectedId > 1 && e.getButton() == MouseEvent.BUTTON3) {
79
 
80
            final SQLRow row = this.frame.getPanel().getListe().getSelectedRow();
81
            JPopupMenu menu = new JPopupMenu();
82
            final DevisTextSheet s = new DevisTextSheet(row);
83
 
84
            // Voir le document
85
            AbstractAction actionOpen = new AbstractAction("Voir le document") {
86
                public void actionPerformed(ActionEvent e) {
87
                    s.generate(false, false, "");
88
                    s.showDocument();
89
                }
90
            };
91
            JMenuItem openItem = new JMenuItem(actionOpen);
92
            openItem.setFont(openItem.getFont().deriveFont(Font.BOLD));
93
            menu.add(openItem);
94
 
25 ilm 95
            final File outpuDirectory = DocumentLocalStorageManager.getInstance().getDocumentOutputDirectory(s.getTemplateId());
96
            List<File> files = SheetUtils.getHistorique(s.getFileName(), outpuDirectory);
18 ilm 97
            if (files.size() > 0) {
98
                JMenu item = new JMenu("Historique");
99
                int i = 0;
100
                for (final File file : files) {
101
                    JMenuItem subItem = new JMenuItem("Version " + i + " du " + this.dateFormat.format(new Date(file.lastModified())));
102
                    subItem.addActionListener(new ActionListener() {
103
 
104
                        @Override
105
                        public void actionPerformed(ActionEvent e) {
106
                            if (file.exists()) {
107
                                try {
108
                                    final OOConnexion ooConnexion = ComptaPropsConfiguration.getOOConnexion();
109
                                    if (ooConnexion == null) {
110
                                        return;
111
                                    }
112
                                    ooConnexion.loadDocument(file, false);
113
 
114
                                } catch (Exception ex) {
115
                                    ex.printStackTrace();
116
                                    ExceptionHandler.handle("Impossible de charger le document OpenOffice", ex);
117
                                }
118
 
119
                            }
120
                        }
121
                    });
122
                    i++;
123
                    item.add(subItem);
124
 
125
                }
126
                menu.add(item);
127
            }
128
 
129
            // Voir le document
130
            AbstractAction actionTransfert = new AbstractAction("Transférer en facture") {
131
                public void actionPerformed(ActionEvent e) {
132
 
133
                    ListeDesDevisAction.this.element.transfertFacture(row.getID());
134
                }
135
            };
136
            menu.add(actionTransfert);
137
 
138
            // Impression
139
            AbstractAction actionPrint = new AbstractAction("Imprimer") {
140
                public void actionPerformed(ActionEvent e) {
141
                    s.fastPrintDocument();
142
                }
143
            };
144
            menu.add(actionPrint);
145
 
146
            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
147
        }
148
    }
149
 
150
    public void mouseReleased(MouseEvent e) {
151
    }
152
 
153
    public void mouseEntered(MouseEvent e) {
154
    }
155
 
156
    public void mouseExited(MouseEvent e) {
157
    }
158
}