OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 102 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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