OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 18 | Rev 67 | 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.shipment.action;
15
 
16
import org.openconcerto.erp.action.CreateFrameAbstractAction;
17
import org.openconcerto.erp.core.sales.shipment.element.BonDeLivraisonSQLElement;
18
import org.openconcerto.erp.core.sales.shipment.report.BonLivraisonXmlSheet;
19
import org.openconcerto.erp.core.sales.shipment.ui.BonLivraisionRenderer;
20
import org.openconcerto.erp.model.MouseSheetXmlListeListener;
21
import org.openconcerto.sql.Configuration;
22
import org.openconcerto.sql.model.SQLRow;
23
import org.openconcerto.sql.view.IListFrame;
24
import org.openconcerto.sql.view.ListeAddPanel;
25 ilm 25
import org.openconcerto.sql.view.list.IListe;
26
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
27
import org.openconcerto.sql.view.list.RowAction;
28
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
18 ilm 29
import org.openconcerto.ui.DefaultGridBagConstraints;
30
 
31
import java.awt.GridBagConstraints;
32
import java.awt.event.ActionEvent;
33
import java.util.ArrayList;
34
import java.util.List;
35
 
36
import javax.swing.AbstractAction;
37
import javax.swing.Action;
38
import javax.swing.BorderFactory;
39
import javax.swing.JFrame;
40
import javax.swing.JPanel;
41
import javax.swing.JTable;
42
 
43
public class ListeDesBonsDeLivraisonAction extends CreateFrameAbstractAction {
44
 
45
    public ListeDesBonsDeLivraisonAction() {
46
        super();
47
        this.putValue(Action.NAME, "Liste des bons de livraison");
48
    }
49
 
50
    public JFrame createFrame() {
51
        final IListFrame edit1 = new IListFrame(new ListeAddPanel(Configuration.getInstance().getDirectory().getElement("BON_DE_LIVRAISON")) {
52
            @Override
53
            protected GridBagConstraints createConstraints() {
54
                // TODO Auto-generated method stub
55
                GridBagConstraints c = super.createConstraints();
56
                c.gridy++;
57
                return c;
58
            }
59
        });
60
 
61
        JTable table = edit1.getPanel().getListe().getJTable();
62
 
63
        final BonLivraisionRenderer rend = BonLivraisionRenderer.getInstance();
64
        GridBagConstraints c = new DefaultGridBagConstraints();
65
        final JPanel legendePanel = rend.getLegendePanel();
66
        legendePanel.setBorder(BorderFactory.createTitledBorder("Légende"));
67
        legendePanel.setOpaque(true);
68
        c.fill = GridBagConstraints.NONE;
69
        edit1.getPanel().add(legendePanel, c);
70
 
71
        for (int i = 0; i < table.getColumnCount(); i++) {
72
            table.getColumnModel().getColumn(i).setCellRenderer(rend);
73
        }
74
 
25 ilm 75
        edit1.getPanel().getListe().addIListeActions(new MouseSheetXmlListeListener(BonLivraisonXmlSheet.class) {
18 ilm 76
            @Override
25 ilm 77
            public List<RowAction> addToMenu() {
78
                PredicateRowAction actionTransfertFacture = new PredicateRowAction(new AbstractAction("Transfert en facture") {
18 ilm 79
                    public void actionPerformed(ActionEvent ev) {
25 ilm 80
                        transfertFactureClient(IListe.get(ev).getSelectedRow());
18 ilm 81
                    }
25 ilm 82
                }, false);
83
                actionTransfertFacture.setPredicate(IListeEvent.getSingleSelectionPredicate());
84
                List<RowAction> l = new ArrayList<RowAction>();
18 ilm 85
                l.add(actionTransfertFacture);
86
 
87
                return l;
88
            }
25 ilm 89
        }.getRowActions());
18 ilm 90
 
91
        return edit1;
92
    }
93
 
94
    /**
95
     * Transfert en Facture
96
     *
97
     * @param row
98
     */
99
    private void transfertFactureClient(SQLRow row) {
100
        BonDeLivraisonSQLElement elt = (BonDeLivraisonSQLElement) Configuration.getInstance().getDirectory().getElement("BON_DE_LIVRAISON");
101
        elt.transfertFacture(row.getID());
102
    }
103
}