OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18 Rev 174
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.erp.core.finance.accounting.ui;
14
 package org.openconcerto.erp.core.finance.accounting.ui;
15
 
15
 
16
import org.openconcerto.sql.Configuration;
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.State;
17
import org.openconcerto.sql.State;
-
 
18
import org.openconcerto.sql.model.SQLBackgroundTableCache;
-
 
19
import org.openconcerto.sql.model.SQLRow;
-
 
20
import org.openconcerto.sql.model.SQLRowAccessor;
-
 
21
import org.openconcerto.sql.model.SQLTable;
-
 
22
import org.openconcerto.sql.model.Where;
-
 
23
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
-
 
24
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
18
import org.openconcerto.ui.state.WindowStateManager;
25
import org.openconcerto.ui.state.WindowStateManager;
19
 
26
 
20
import java.awt.DisplayMode;
27
import java.awt.DisplayMode;
21
import java.awt.GraphicsEnvironment;
28
import java.awt.GraphicsEnvironment;
22
import java.awt.GridLayout;
29
import java.awt.GridLayout;
-
 
30
import java.awt.event.ActionEvent;
23
import java.awt.event.ComponentAdapter;
31
import java.awt.event.ComponentAdapter;
24
import java.awt.event.ComponentEvent;
32
import java.awt.event.ComponentEvent;
25
import java.io.File;
33
import java.io.File;
-
 
34
import java.util.ArrayList;
-
 
35
import java.util.Collections;
-
 
36
import java.util.Comparator;
-
 
37
import java.util.List;
26
 
38
 
-
 
39
import javax.swing.AbstractAction;
27
import javax.swing.JFrame;
40
import javax.swing.JFrame;
28
import javax.swing.event.TableModelEvent;
41
import javax.swing.event.TableModelEvent;
29
import javax.swing.event.TableModelListener;
42
import javax.swing.event.TableModelListener;
30
 
43
 
31
 
-
 
32
public class ConsultationCompteFrame extends JFrame {
44
public class ConsultationCompteFrame extends JFrame {
33
    // panel contenant la liste des ecritures
45
    // panel contenant la liste des ecritures
34
    private final ListPanelEcritures panelEcritures;
46
    private final ListPanelEcritures panelEcritures;
35
    // panel complet liste des ecritures + totaux
47
    // panel complet liste des ecritures + totaux
36
    private final ListeDesEcrituresPanel panel;
48
    private final ListeDesEcrituresPanel panel;
37
 
49
 
38
    private String titre;
50
    private String titre;
39
 
51
 
-
 
52
    private int indexID;
-
 
53
 
40
    public ConsultationCompteFrame(ListeDesEcrituresPanel panel, String titre) {
54
    public ConsultationCompteFrame(ListeDesEcrituresPanel panel, SQLRowAccessor rowCpt) {
41
        super();
55
        super();
42
        this.panel = panel;
56
        this.panel = panel;
43
        this.panelEcritures = panel.getListPanelEcritures();
57
        this.panelEcritures = panel.getListPanelEcritures();
44
        this.titre = titre;
58
        this.titre = "Consultation compte n°" + rowCpt.getString("NUMERO") + " " + rowCpt.getString("NOM");
45
 
-
 
46
        // rafraichir le titre à chaque changement de la liste
59
        // rafraichir le titre à chaque changement de la liste
47
        this.panelEcritures.getListe().addListener(new TableModelListener() {
60
        this.panelEcritures.getListe().addListener(new TableModelListener() {
48
            public void tableChanged(TableModelEvent e) {
61
            public void tableChanged(TableModelEvent e) {
49
                setTitle();
62
                setTitle();
50
            }
63
            }
Line 61... Line 74...
61
                public void componentShown(ComponentEvent e) {
74
                public void componentShown(ComponentEvent e) {
62
                    State.INSTANCE.frameShown();
75
                    State.INSTANCE.frameShown();
63
                }
76
                }
64
            });
77
            });
65
        }
78
        }
-
 
79
 
-
 
80
        SQLTable ecrTable = rowCpt.getTable().getTable("ECRITURE");
-
 
81
 
-
 
82
        final int id = rowCpt.getID();
-
 
83
        Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", id);
-
 
84
        getPanel().getListe().getRequest().setWhere(w);
-
 
85
 
-
 
86
        final SQLTable cptTable = ecrTable.getForeignTable("ID_COMPTE_PCE");
-
 
87
        List<SQLRow> rowsCpt = new ArrayList<SQLRow>(SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRows());
-
 
88
        Collections.sort(rowsCpt, new Comparator<SQLRow>() {
-
 
89
            @Override
-
 
90
            public int compare(SQLRow o1, SQLRow o2) {
-
 
91
 
-
 
92
                return o1.getString("NUMERO").compareTo(o2.getString("NUMERO"));
-
 
93
            }
-
 
94
        });
-
 
95
        final List<Integer> idsCpt = new ArrayList<>();
-
 
96
        for (SQLRow sqlRow : rowsCpt) {
-
 
97
            idsCpt.add(sqlRow.getID());
-
 
98
        }
-
 
99
        this.indexID = idsCpt.indexOf(rowCpt.getID());
-
 
100
 
-
 
101
        final PredicateRowAction prec = new PredicateRowAction(new AbstractAction("Précédent") {
-
 
102
 
-
 
103
            @Override
-
 
104
            public void actionPerformed(ActionEvent e) {
-
 
105
 
-
 
106
                if (indexID > 0) {
-
 
107
                    int newCptId = idsCpt.get(indexID - 1);
-
 
108
                    Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", newCptId);
-
 
109
                    getPanel().getListe().getRequest().setWhere(w);
-
 
110
                    SQLRow rowCptNew = SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRowFromId(newCptId);
-
 
111
                    setTitle("Consultation compte n°" + rowCptNew.getString("NUMERO") + " " + rowCptNew.getString("NOM"));
-
 
112
                    indexID--;
-
 
113
                }
-
 
114
 
-
 
115
            }
-
 
116
        }, true, false);
-
 
117
        prec.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
-
 
118
        panel.getListPanelEcritures().getListe().addIListeAction(prec);
-
 
119
 
-
 
120
        final PredicateRowAction suivant = new PredicateRowAction(new AbstractAction("Suivant") {
-
 
121
 
-
 
122
            @Override
-
 
123
            public void actionPerformed(ActionEvent e) {
-
 
124
 
-
 
125
                if (indexID < idsCpt.size() - 1) {
-
 
126
                    int newCptId = idsCpt.get(indexID + 1);
-
 
127
                    Where w = new Where(ecrTable.getField("ID_COMPTE_PCE"), "=", newCptId);
-
 
128
                    getPanel().getListe().getRequest().setWhere(w);
-
 
129
                    SQLRow rowCptNew = SQLBackgroundTableCache.getInstance().getCacheForTable(cptTable).getRowFromId(newCptId);
-
 
130
                    setTitle("Consultation compte n°" + rowCptNew.getString("NUMERO") + " " + rowCptNew.getString("NOM"));
-
 
131
                    indexID++;
-
 
132
                }
-
 
133
 
-
 
134
            }
-
 
135
        }, true, false);
-
 
136
        suivant.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
-
 
137
        panel.getListPanelEcritures().getListe().addIListeAction(suivant);
-
 
138
 
-
 
139
    }
-
 
140
 
-
 
141
    @Override
-
 
142
    public void setTitle(String title) {
-
 
143
        this.titre = title;
-
 
144
        super.setTitle(title);
66
    }
145
    }
67
 
146
 
68
    private String getPlural(String s, int nb) {
147
    private String getPlural(String s, int nb) {
69
        return nb + " " + s + (nb > 1 ? "s" : "");
148
        return nb + " " + s + (nb > 1 ? "s" : "");
70
    }
149
    }