OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 102 | 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.BorderLayout;
4
import java.awt.FlowLayout;
5
import java.sql.SQLException;
6
import java.util.List;
7
 
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10
 
11
import org.openconcerto.erp.config.ComptaPropsConfiguration;
12
import org.openconcerto.sql.element.SQLElement;
13
import org.openconcerto.sql.model.SQLField;
14
import org.openconcerto.sql.model.SQLRowAccessor;
15
import org.openconcerto.sql.model.SQLRowValues;
16
import org.openconcerto.sql.sqlobject.ElementComboBox;
17
import org.openconcerto.ui.warning.JLabelWarning;
18
 
19
public class ReferenceProcessor extends JPanel implements BatchProcessor {
20
 
181 ilm 21
    private final BatchField field;
102 ilm 22
    final SQLElement element;
23
    private ElementComboBox combo;
24
 
181 ilm 25
    public ReferenceProcessor(BatchField field) {
102 ilm 26
        this.field = field;
181 ilm 27
        this.element = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElement(field.getField().getForeignTable());
102 ilm 28
 
29
        if (element != null) {
30
            this.setLayout(new BorderLayout());
31
            this.add(new JLabel("remplacer par "), BorderLayout.WEST);
181 ilm 32
            combo = new ElementComboBox(true, 10);
102 ilm 33
            combo.setMinimal();
34
            combo.setAddIconVisible(false);
35
            combo.init(element);
36
            this.add(combo, BorderLayout.CENTER);
37
        } else {
38
            this.setLayout(new FlowLayout());
181 ilm 39
            this.add(new JLabelWarning("No element for table " + field.getField().getTable().getName()));
102 ilm 40
        }
41
    }
42
 
43
    @Override
44
    public void process(List<SQLRowValues> r) throws SQLException {
45
 
46
        for (SQLRowAccessor sqlRowAccessor : r) {
47
            final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
181 ilm 48
            rowValues.put(field.getField().getName(), combo.getSelectedId());
102 ilm 49
            processBeforeUpdate(sqlRowAccessor, rowValues);
50
            rowValues.update();
51
        }
52
 
53
    }
54
 
55
    @Override
56
    public boolean checkParameters() {
57
        return this.element != null;
58
    }
59
 
60
    @Override
61
    public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
62
 
63
    }
64
}