OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Go to most recent revision | Details | 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.finance.accounting.ui;
15
 
16
import org.openconcerto.erp.core.common.ui.PanelFrame;
17
import org.openconcerto.erp.core.finance.accounting.element.MouvementSQLElement;
18
import org.openconcerto.sql.element.SQLElement;
19
import org.openconcerto.sql.model.SQLRow;
20
import org.openconcerto.sql.model.Where;
21
import org.openconcerto.sql.view.EditFrame;
22
import org.openconcerto.sql.view.EditPanel;
23
import org.openconcerto.sql.view.ListeAddPanel;
24
import org.openconcerto.sql.view.list.IListe;
25
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
26
 
27
import java.awt.event.ActionEvent;
28
 
29
import javax.swing.JButton;
30
 
31
public class ListeGestCommEltPanel extends ListeAddPanel {
32
 
33
    private static SQLTableModelSourceOnline copy(SQLElement elem, Where w) {
34
        final SQLTableModelSourceOnline res = elem.getTableSource(true);
35
        res.getReq().setWhere(w);
36
        return res;
37
    }
38
 
39
    private EditFrame editModifyFrame, editReadOnlyFrame;
40
 
41
    private ListeGestCommEltPanel(SQLElement elem, boolean showAdd, Where w) {
42
        // TODO verifier que l'element contient la clef etrangere ID_MOUVEMENT
43
        this(elem, new IListe(copy(elem, w)), showAdd);
44
    }
45
 
46
    public ListeGestCommEltPanel(SQLElement elem, IListe l) {
47
        this(elem, l, false);
48
    }
49
 
50
    public ListeGestCommEltPanel(SQLElement elem, IListe l, boolean showAdd) {
51
        super(elem, l);
52
        this.setAddVisible(showAdd);
53
        this.setOpaque(false);
54
    }
55
 
56
    public ListeGestCommEltPanel(SQLElement elem, boolean showAdd) {
57
        this(elem, showAdd, null);
58
    }
59
 
60
    public ListeGestCommEltPanel(SQLElement elem) {
61
        this(elem, false);
62
    }
63
 
64
    public ListeGestCommEltPanel(SQLElement elem, Where w) {
65
        this(elem, false, w);
66
    }
67
 
68
    protected void handleAction(JButton source, ActionEvent evt) {
69
 
70
        SQLRow row = this.getElement().getTable().getRow(this.getListe().getSelectedId());
71
 
72
        if (row != null && row.getID() > 1) {
73
            final int idMvt = row.getInt("ID_MOUVEMENT");
74
            if (source == this.buttonEffacer) {
75
 
76
                if (idMvt > 1) {
77
                    PanelFrame frame = new PanelFrame(new SuppressionEcrituresPanel(idMvt), "Suppression");
78
                    frame.pack();
79
                    frame.setLocationRelativeTo(null);
80
                    frame.setResizable(false);
81
                    frame.setVisible(true);
82
                } else {
83
                    super.handleAction(source, evt);
84
                }
85
            } else {
86
                if (source == this.buttonModifier) {
87
 
88
                    if (MouvementSQLElement.isEditable(idMvt)) {
89
                        if (this.editModifyFrame == null) {
90
                            this.editModifyFrame = new EditFrame(this.element, EditPanel.MODIFICATION);
91
                        }
92
                        this.editModifyFrame.selectionId(this.getListe().getSelectedId());
93
                        this.editModifyFrame.setVisible(true);
94
                    } else {
95
                        if (this.editReadOnlyFrame == null) {
96
                            this.editReadOnlyFrame = new EditFrame(this.element, EditPanel.READONLY);
97
                        }
98
                        this.editReadOnlyFrame.selectionId(this.getListe().getSelectedId());
99
                        this.editReadOnlyFrame.setVisible(true);
100
                    }
101
                } else {
102
                    super.handleAction(source, evt);
103
                }
104
            }
105
        } else {
106
            super.handleAction(source, evt);
107
        }
108
    }
109
}