OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | 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
 *
182 ilm 4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
18 ilm 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.supplychain.stock.action;
15
 
156 ilm 16
import org.openconcerto.erp.action.CreateIListFrameAbstractAction;
17
import org.openconcerto.erp.config.ComptaPropsConfiguration;
93 ilm 18
import org.openconcerto.erp.core.common.ui.IListFilterDatePanel;
18 ilm 19
import org.openconcerto.erp.core.supplychain.stock.element.MouvementStockSQLElement;
93 ilm 20
import org.openconcerto.sql.element.SQLElement;
182 ilm 21
import org.openconcerto.sql.model.SQLRowAccessor;
22
import org.openconcerto.sql.model.SQLSelect;
23
import org.openconcerto.sql.model.Where;
18 ilm 24
import org.openconcerto.sql.view.IListFrame;
182 ilm 25
import org.openconcerto.sql.view.list.SQLTableModelSource;
93 ilm 26
import org.openconcerto.ui.DefaultGridBagConstraints;
182 ilm 27
import org.openconcerto.utils.cc.ITransformer;
18 ilm 28
 
93 ilm 29
import java.awt.GridBagConstraints;
18 ilm 30
import java.awt.event.ActionEvent;
31
import java.awt.event.MouseAdapter;
32
import java.awt.event.MouseEvent;
33
 
34
import javax.swing.AbstractAction;
35
import javax.swing.JPopupMenu;
36
import javax.swing.JTable;
37
 
156 ilm 38
public class ListeDesMouvementsStockAction extends CreateIListFrameAbstractAction<MouvementStockSQLElement> {
18 ilm 39
 
182 ilm 40
    private final SQLRowAccessor rowArtFilter;
41
 
156 ilm 42
    public ListeDesMouvementsStockAction(final ComptaPropsConfiguration conf) {
182 ilm 43
        this(conf, null);
44
    }
45
 
46
    public ListeDesMouvementsStockAction(final ComptaPropsConfiguration conf, SQLRowAccessor rowArticleFilter) {
156 ilm 47
        super(conf, MouvementStockSQLElement.class);
182 ilm 48
        this.rowArtFilter = rowArticleFilter;
18 ilm 49
    }
50
 
182 ilm 51
    protected SQLTableModelSource createTableSource() {
52
 
53
        SQLTableModelSource source = this.getElem().createTableSource();
54
        if (this.rowArtFilter != null && !this.rowArtFilter.isUndefined()) {
55
            source.getReq().setSelectTransf(new ITransformer<SQLSelect, SQLSelect>() {
56
 
57
                @Override
58
                public SQLSelect transformChecked(SQLSelect input) {
59
                    input.setWhere(new Where(input.getTable("MOUVEMENT_STOCK").getField("ID_ARTICLE"), "=", ListeDesMouvementsStockAction.this.rowArtFilter.getID()));
60
                    return input;
61
                }
62
            });
63
        }
64
        return source;
65
    }
66
 
156 ilm 67
    @Override
68
    protected void initFrame(IListFrame frame) {
69
        super.initFrame(frame);
18 ilm 70
 
182 ilm 71
        if (this.rowArtFilter != null && !this.rowArtFilter.isUndefined()) {
72
            frame.setTextTitle("Mouvements de stocks, article " + this.rowArtFilter.getString("CODE") + " " + this.rowArtFilter.getString("NOM"));
73
        }
156 ilm 74
        final SQLElement element = getElem();
18 ilm 75
 
76
        JTable table = frame.getPanel().getListe().getJTable();
77
 
78
        table.addMouseListener(new MouseAdapter() {
79
            public void mousePressed(MouseEvent e) {
80
                if (e.getButton() == MouseEvent.BUTTON3) {
81
                    JPopupMenu menuDroit = new JPopupMenu();
82
                    menuDroit.add(new AbstractAction("Voir la source") {
83
                        public void actionPerformed(ActionEvent e) {
84
                            MouvementStockSQLElement.showSource(frame.getPanel().getListe().getSelectedId());
85
                        }
86
                    });
87
                    menuDroit.show(e.getComponent(), e.getPoint().x, e.getPoint().y);
88
                }
89
            }
90
        });
93 ilm 91
 
92
        // Date panel
93
        IListFilterDatePanel datePanel = new IListFilterDatePanel(frame.getPanel().getListe(), element.getTable().getField("DATE"), IListFilterDatePanel.getDefaultMap());
94
        GridBagConstraints c = new DefaultGridBagConstraints();
95
        c.gridwidth = GridBagConstraints.REMAINDER;
96
        c.fill = GridBagConstraints.NONE;
97
        c.weightx = 0;
98
        c.gridy++;
99
        c.gridy++;
100
        c.anchor = GridBagConstraints.CENTER;
101
        datePanel.setFilterOnDefault();
102
        frame.getPanel().add(datePanel, c);
18 ilm 103
    }
104
}