OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 102 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 102 Rev 181
Line 16... Line 16...
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
    }