OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 166 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 ilm 1
package org.openconcerto.modules.common.batchprocessing;
2
 
3
import java.awt.Dimension;
4
import java.awt.event.ActionEvent;
5
import java.io.IOException;
6
import java.util.List;
7
 
8
import javax.swing.AbstractAction;
9
import javax.swing.JFrame;
10
 
11
import org.openconcerto.erp.modules.AbstractModule;
12
import org.openconcerto.erp.modules.ComponentsContext;
13
import org.openconcerto.erp.modules.ModuleFactory;
14
import org.openconcerto.sql.element.SQLElement;
15
import org.openconcerto.sql.model.SQLField;
16
import org.openconcerto.sql.model.SQLRowValues;
17
import org.openconcerto.sql.view.list.IListe;
18
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
19
import org.openconcerto.sql.view.list.RowAction;
20
import org.openconcerto.ui.FrameUtil;
21
 
22
public final class Module extends AbstractModule {
23
 
24
    public Module(ModuleFactory f) throws IOException {
25
        super(f);
26
    }
27
 
28
    @Override
181 ilm 29
    protected void setupComponents(final ComponentsContext ctxt) {
102 ilm 30
 
31
        super.setupComponents(ctxt);
32
        final SQLElement element = ctxt.getElement("ARTICLE");
33
        final RowAction.PredicateRowAction editAction = new RowAction.PredicateRowAction(new AbstractAction("Traitement par lot...") {
34
 
35
            @Override
36
            public void actionPerformed(ActionEvent e) {
37
                final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
38
                final int size = rows.size();
39
                if (size > 0) {
40
                    final JFrame f = new JFrame();
41
                    if (size > 1) {
42
                        f.setTitle("Traitement des " + size + " " + element.getPluralName());
43
                    } else {
44
                        f.setTitle("Traitement d'" + element.getSingularName());
45
                    }
46
                    FieldFilter filter = new FieldFilter() {
47
 
48
                        @Override
49
                        public boolean isFiltered(SQLField f) {
50
                            final String fieldName = f.getName();
51
                            return fieldName.contains("METRIQUE") || fieldName.equals("ID_STOCK");
52
                        }
53
 
54
                    };
55
 
181 ilm 56
                    f.setContentPane(new BatchEditorPanel(ctxt.getElement("ARTICLE").getDirectory(), rows, filter));
102 ilm 57
                    f.pack();
58
                    f.setMinimumSize(new Dimension(400, 300));
59
                    f.setLocationRelativeTo(IListe.get(e));
60
                    FrameUtil.show(f);
61
                }
62
            }
63
        }, false) {
64
        };
65
        editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
66
        element.getRowActions().add(editAction);
67
 
68
    }
69
 
70
    @Override
71
    protected void start() {
72
    }
73
 
74
    @Override
75
    protected void stop() {
76
    }
77
 
78
}