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.Component;
4
import java.math.BigDecimal;
5
import java.util.Date;
6
 
7
import javax.swing.JComponent;
8
import javax.swing.JPanel;
9
 
10
import org.openconcerto.modules.common.batchprocessing.product.HTProcessor;
11
import org.openconcerto.modules.common.batchprocessing.product.PurchaseProcessor;
12
import org.openconcerto.modules.common.batchprocessing.product.TTCProcessor;
13
import org.openconcerto.modules.common.batchprocessing.product.TVAProcessor;
14
import org.openconcerto.sql.model.SQLField;
15
import org.openconcerto.sql.model.SQLType;
16
import org.openconcerto.ui.VFlowLayout;
17
 
18
public class BatchDetailPanel extends JPanel {
19
    private BatchProcessor processor;
20
 
21
    BatchDetailPanel() {
22
        this.setLayout(new VFlowLayout());
23
    }
24
 
181 ilm 25
    public void setField(BatchField batchField) {
102 ilm 26
        this.removeAll();
27
 
181 ilm 28
        SQLField field = batchField.getField();
102 ilm 29
        final SQLType type = field.getType();
30
        final Class<?> javaType = type.getJavaType();
31
        final String fName = field.getName();
32
        if (fName.equals("PV_TTC")) {
181 ilm 33
            final NumberProcessor p = new TTCProcessor(batchField);
102 ilm 34
            this.add(p);
35
            this.processor = p;
36
        } else if (fName.equals("PV_HT")) {
181 ilm 37
            final NumberProcessor p = new HTProcessor(batchField);
102 ilm 38
            this.add(p);
39
            this.processor = p;
40
        } else if (fName.equals("ID_TAXE")) {
181 ilm 41
            final ReferenceProcessor p = new TVAProcessor(batchField);
102 ilm 42
            this.add(p);
43
            this.processor = p;
44
        } else if (fName.equals("PA_HT")) {
181 ilm 45
            final NumberProcessor p = new PurchaseProcessor(batchField);
102 ilm 46
            this.add(p);
47
            this.processor = p;
48
        } else if (javaType.equals(Boolean.class)) {
181 ilm 49
            final BooleanProcessor p = new BooleanProcessor(batchField);
102 ilm 50
            this.add(p);
51
            this.processor = p;
52
        } else if (field.isKey()) {
181 ilm 53
            final ReferenceProcessor p = new ReferenceProcessor(batchField);
102 ilm 54
            this.add(p);
55
            this.processor = p;
56
        } else if (javaType.equals(String.class)) {
181 ilm 57
            final StringProcessor p = new StringProcessor(batchField);
102 ilm 58
            this.add(p);
59
            this.processor = p;
60
        } else if (javaType.equals(Date.class)) {
181 ilm 61
            final DateProcessor p = new DateProcessor(batchField);
102 ilm 62
            this.add(p);
63
            this.processor = p;
64
        } else if (javaType.equals(BigDecimal.class) || javaType.equals(Float.class) || javaType.equals(Double.class) || javaType.equals(Integer.class) || javaType.equals(Long.class)) {
181 ilm 65
            final NumberProcessor p = new NumberProcessor(batchField);
102 ilm 66
            this.add(p);
67
            this.processor = p;
68
        }
69
 
70
        revalidate();
71
        repaint();
72
    }
73
 
74
    public BatchProcessor getProcessor() {
75
        return processor;
76
    }
77
 
78
    @Override
79
    public void setEnabled(boolean enabled) {
80
        if (processor != null && processor instanceof JComponent) {
81
            Component[] l = ((JComponent) processor).getComponents();
82
            for (int i = 0; i < l.length; i++) {
83
                l[i].setEnabled(false);
84
            }
85
        }
86
        super.setEnabled(enabled);
87
    }
88
}