OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 75 | Rev 128 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
75 ilm 1
/*
2
 * Créé le 3 juin 2012
3
 */
4
package org.openconcerto.modules.project;
5
 
6
import java.awt.GridBagConstraints;
7
import java.awt.event.WindowAdapter;
8
import java.awt.event.WindowEvent;
9
import java.io.File;
10
import java.util.Arrays;
11
import java.util.LinkedHashMap;
12
import java.util.List;
13
import java.util.Map;
14
 
15
import javax.swing.JFrame;
16
import javax.swing.event.TableModelEvent;
17
import javax.swing.event.TableModelListener;
18
 
19
import org.openconcerto.erp.config.ComptaPropsConfiguration;
20
import org.openconcerto.erp.config.Gestion;
21
import org.openconcerto.erp.core.reports.history.ui.ListeHistoriquePanel;
22
import org.openconcerto.sql.Configuration;
23
import org.openconcerto.sql.model.SQLBase;
24
import org.openconcerto.sql.request.ComboSQLRequest;
25
import org.openconcerto.sql.view.IListPanel;
26
import org.openconcerto.ui.DefaultGridBagConstraints;
27
import org.openconcerto.ui.PanelFrame;
28
import org.openconcerto.ui.state.WindowStateManager;
29
 
30
public class ProjectHistory {
31
    private PanelFrame panelFrame;
32
    private ListeHistoriquePanel listPanel;
33
 
34
    public ListeHistoriquePanel getHistoriquePanel() {
35
        return this.listPanel;
36
    }
37
 
38
    public ProjectHistory() {
39
 
40
        final ComptaPropsConfiguration comptaPropsConfiguration = ((ComptaPropsConfiguration) Configuration.getInstance());
41
        final SQLBase b = comptaPropsConfiguration.getSQLBaseSociete();
42
 
43
        final Map<String, List<String>> mapList = new LinkedHashMap<String, List<String>>();
44
        mapList.put("Devis", Arrays.asList("DEVIS"));
45
        mapList.put("Bons de commande", Arrays.asList("COMMANDE_CLIENT"));
46
        mapList.put("Factures", Arrays.asList("SAISIE_VENTE_FACTURE"));
47
        mapList.put("Avoirs", Arrays.asList("AVOIR_CLIENT"));
48
 
49
        if (Configuration.getInstance().getRoot().findTable("AFFAIRE_TEMPS") != null) {
50
            mapList.put("Temps", Arrays.asList("AFFAIRE_TEMPS"));
51
        }
52
 
53
        final ComboSQLRequest request = new org.openconcerto.sql.request.ComboSQLRequest(b.getTable("AFFAIRE"), Arrays.asList("NUMERO", "ID_CLIENT"));
54
        request.setUndefLabel("Toutes les affaires");
55
        request.setFieldSeparator(" ");
56
 
88 ilm 57
        this.listPanel = new ListeHistoriquePanel("Affaires", request, mapList, null, null, "Toutes les affaires", true, null, null);
75 ilm 58
 
59
        final IListPanel listeDevis = listPanel.getIListePanelFromTableName("DEVIS");
60
        GridBagConstraints c = new DefaultGridBagConstraints();
61
        c.gridy = 4;
62
        c.fill = GridBagConstraints.BOTH;
63
        final ProjectHistoryDevisBottomPanel devisPanel = new ProjectHistoryDevisBottomPanel();
64
        listeDevis.add(devisPanel, c);
65
        listeDevis.getListe().getTableModel().addTableModelListener(new TableModelListener() {
66
 
67
            @Override
68
            public void tableChanged(TableModelEvent e) {
69
                devisPanel.updateDevis(listeDevis.getListe());
70
                devisPanel.updateTimeDevis(listeDevis.getListe());
71
            }
72
        });
73
 
74
        final IListPanel listeCmd = listPanel.getIListePanelFromTableName("COMMANDE_CLIENT");
75
        final ProjectHistoryCmdBottomPanel cmdPanel = new ProjectHistoryCmdBottomPanel();
76
 
77
        listeCmd.add(cmdPanel, c);
78
        listeCmd.getListe().getTableModel().addTableModelListener(new TableModelListener() {
79
 
80
            @Override
81
            public void tableChanged(TableModelEvent e) {
82
                cmdPanel.updateCmd(listeCmd.getListe());
83
                cmdPanel.updateTimeCmd(listeCmd.getListe());
84
            }
85
        });
86
 
88 ilm 87
        // If time tracking is installed
75 ilm 88
        final IListPanel listeTemps = listPanel.getIListePanelFromTableName("AFFAIRE_TEMPS");
88 ilm 89
        if (listeTemps != null) {
90
            final ProjectHistoryTimeBottomPanel timePanel = new ProjectHistoryTimeBottomPanel();
91
            listeTemps.add(timePanel, c);
92
            listeTemps.getListe().getTableModel().addTableModelListener(new TableModelListener() {
75 ilm 93
 
88 ilm 94
                @Override
95
                public void tableChanged(TableModelEvent e) {
96
                    timePanel.updateTime(listeTemps.getListe());
97
                }
98
            });
99
        }
100
        // History
75 ilm 101
        this.panelFrame = new PanelFrame(this.listPanel, "Historique affaires");
102
        this.panelFrame.addWindowListener(new WindowAdapter() {
103
            public void windowClosing(WindowEvent e) {
104
                listPanel.removeAllTableListener();
105
            };
106
        });
107
 
108
        this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
109
 
110
    }
111
 
112
    public PanelFrame getFrame() {
113
        this.panelFrame.setIconImages(Gestion.getFrameIcon());
114
        final WindowStateManager stateManager = new WindowStateManager(this.panelFrame, new File(Configuration.getInstance().getConfDir(), "Configuration" + File.separator + "Frame" + File.separator
115
                + "HistoAffaires.xml"), true);
116
        this.panelFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
117
        this.panelFrame.pack();
118
        this.panelFrame.setLocationRelativeTo(null);
119
        stateManager.loadState();
120
        return this.panelFrame;
121
    }
122
}