OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Go to most recent revision | Details | 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.File;
6
import java.io.IOException;
7
import java.util.List;
8
 
9
import javax.swing.AbstractAction;
10
import javax.swing.JFrame;
11
 
12
import org.openconcerto.erp.config.Gestion;
13
import org.openconcerto.erp.modules.AbstractModule;
14
import org.openconcerto.erp.modules.ComponentsContext;
15
import org.openconcerto.erp.modules.ModuleFactory;
16
import org.openconcerto.erp.modules.ModuleManager;
17
import org.openconcerto.erp.modules.ModulePackager;
18
import org.openconcerto.erp.modules.RuntimeModuleFactory;
19
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.SQLField;
21
import org.openconcerto.sql.model.SQLRequestLog;
22
import org.openconcerto.sql.model.SQLRowValues;
23
import org.openconcerto.sql.ui.ConnexionPanel;
24
import org.openconcerto.sql.view.list.IListe;
25
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
26
import org.openconcerto.sql.view.list.RowAction;
27
import org.openconcerto.ui.FrameUtil;
28
 
29
public final class Module extends AbstractModule {
30
 
31
    public Module(ModuleFactory f) throws IOException {
32
        super(f);
33
    }
34
 
35
    @Override
36
    protected void setupComponents(ComponentsContext ctxt) {
37
 
38
        super.setupComponents(ctxt);
39
        final SQLElement element = ctxt.getElement("ARTICLE");
40
        final RowAction.PredicateRowAction editAction = new RowAction.PredicateRowAction(new AbstractAction("Traitement par lot...") {
41
 
42
            @Override
43
            public void actionPerformed(ActionEvent e) {
44
                final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
45
                final int size = rows.size();
46
                if (size > 0) {
47
                    final JFrame f = new JFrame();
48
                    if (size > 1) {
49
                        f.setTitle("Traitement des " + size + " " + element.getPluralName());
50
                    } else {
51
                        f.setTitle("Traitement d'" + element.getSingularName());
52
                    }
53
                    FieldFilter filter = new FieldFilter() {
54
 
55
                        @Override
56
                        public boolean isFiltered(SQLField f) {
57
                            final String fieldName = f.getName();
58
                            return fieldName.contains("METRIQUE") || fieldName.equals("ID_STOCK");
59
                        }
60
 
61
                    };
62
 
63
                    f.setContentPane(new BatchEditorPanel(rows, filter));
64
                    f.pack();
65
                    f.setMinimumSize(new Dimension(400, 300));
66
                    f.setLocationRelativeTo(IListe.get(e));
67
                    FrameUtil.show(f);
68
                }
69
            }
70
        }, false) {
71
        };
72
        editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
73
        element.getRowActions().add(editAction);
74
 
75
    }
76
 
77
    @Override
78
    protected void start() {
79
    }
80
 
81
    @Override
82
    protected void stop() {
83
    }
84
 
85
    public static void main(String[] args) throws IOException {
86
        System.setProperty(ConnexionPanel.QUICK_LOGIN, "true");
87
        final File propsFile = new File("module.properties");
88
        final ModuleFactory factory = new RuntimeModuleFactory(propsFile);
89
        SQLRequestLog.setEnabled(true);
90
        SQLRequestLog.showFrame();
91
        // uncomment to create and use the jar
92
        final ModulePackager modulePackager = new ModulePackager(propsFile, new File("bin/"));
93
        modulePackager.writeToDir(new File("../OpenConcerto/Modules"));
94
        // final ModuleFactory factory = new JarModuleFactory(jar);
95
        ModuleManager.getInstance().addFactories(new File("../OpenConcerto/Modules"));
96
        ModuleManager.getInstance().addFactoryAndStart(factory, false);
97
        Gestion.main(args);
98
    }
99
 
100
}