OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 147 Rev 181
Line 22... Line 22...
22
import javax.swing.JOptionPane;
22
import javax.swing.JOptionPane;
23
import javax.swing.JPanel;
23
import javax.swing.JPanel;
24
import javax.swing.SwingUtilities;
24
import javax.swing.SwingUtilities;
25
import javax.swing.SwingWorker;
25
import javax.swing.SwingWorker;
26
 
26
 
27
import org.openconcerto.sql.Configuration;
-
 
28
import org.openconcerto.sql.PropsConfiguration;
27
import org.openconcerto.sql.element.SQLElementDirectory;
29
import org.openconcerto.sql.model.SQLField;
28
import org.openconcerto.sql.model.SQLField;
-
 
29
import org.openconcerto.sql.model.SQLRow;
-
 
30
import org.openconcerto.sql.model.SQLRowListRSH;
30
import org.openconcerto.sql.model.SQLRowValues;
31
import org.openconcerto.sql.model.SQLRowValues;
-
 
32
import org.openconcerto.sql.model.SQLSelect;
-
 
33
import org.openconcerto.sql.model.SQLTable;
31
import org.openconcerto.sql.request.SQLFieldTranslator;
34
import org.openconcerto.sql.request.SQLFieldTranslator;
32
import org.openconcerto.ui.DefaultGridBagConstraints;
35
import org.openconcerto.ui.DefaultGridBagConstraints;
33
import org.openconcerto.ui.JLabelBold;
36
import org.openconcerto.ui.JLabelBold;
34
import org.openconcerto.ui.ReloadPanel;
37
import org.openconcerto.ui.ReloadPanel;
35
import org.openconcerto.utils.ExceptionHandler;
38
import org.openconcerto.utils.ExceptionHandler;
36
 
39
 
37
public class BatchEditorPanel extends JPanel {
40
public class BatchEditorPanel extends JPanel {
38
 
41
 
39
    public BatchEditorPanel(final List<SQLRowValues> rows, FieldFilter filter) {
42
    public BatchEditorPanel(final SQLElementDirectory dir, final List<SQLRowValues> rows, FieldFilter filter) {
40
        Configuration conf = PropsConfiguration.getInstance();
-
 
41
        final SQLFieldTranslator translator = conf.getTranslator();
43
        SQLFieldTranslator translator = dir.getTranslator();
42
        Set<SQLField> fields = rows.get(0).getTable().getFields();
44
        Set<SQLField> fields = rows.get(0).getTable().getFields();
43
        List<SQLField> f = new ArrayList<SQLField>();
45
        List<BatchField> f = new ArrayList<BatchField>();
44
        for (SQLField sqlField : fields) {
46
        for (SQLField sqlField : fields) {
45
            if (ForbiddenFieldName.isAllowed(sqlField.getName()) && translator.getLabelFor(sqlField) != null) {
47
            if (ForbiddenFieldName.isAllowed(sqlField.getName()) && translator.getLabelFor(sqlField) != null) {
46
                if (filter == null || !filter.isFiltered(sqlField)) {
48
                if (filter == null || !filter.isFiltered(sqlField)) {
47
                    f.add(sqlField);
49
                    f.add(new BatchField(dir, sqlField, null));
48
                }
50
                }
49
            }
51
            }
50
        }
52
        }
-
 
53
        SQLTable tableTarif = rows.get(0).getTable().getTable("TARIF");
-
 
54
        SQLTable tableArticleTarif = rows.get(0).getTable().getTable("ARTICLE_TARIF");
-
 
55
        SQLSelect sel = new SQLSelect();
-
 
56
        sel.addSelectStar(tableTarif);
-
 
57
        List<SQLRow> rowTarif = SQLRowListRSH.execute(sel);
-
 
58
        for (SQLRow sqlRow : rowTarif) {
-
 
59
            f.add(new BatchField(dir, tableArticleTarif.getField("PV_HT"), sqlRow));
-
 
60
            if (tableArticleTarif.contains("POURCENT_REMISE")) {
-
 
61
                f.add(new BatchField(dir, tableArticleTarif.getField("POURCENT_REMISE"), sqlRow));
-
 
62
            }
-
 
63
        }
51
 
64
 
52
        Collections.sort(f, new Comparator<SQLField>() {
65
        Collections.sort(f, new Comparator<BatchField>() {
53
 
66
 
54
            @Override
67
            @Override
55
            public int compare(SQLField o1, SQLField o2) {
68
            public int compare(BatchField o1, BatchField o2) {
56
                return translator.getLabelFor(o1).compareToIgnoreCase(translator.getLabelFor(o2));
69
                return o1.getComboName().compareToIgnoreCase(o2.getComboName());
57
            }
70
            }
58
        });
71
        });
59
        this.setLayout(new GridBagLayout());
72
        this.setLayout(new GridBagLayout());
60
        GridBagConstraints c = new DefaultGridBagConstraints();
73
        GridBagConstraints c = new DefaultGridBagConstraints();
61
        this.add(new JLabel("Champ"), c);
74
        this.add(new JLabel("Champ"), c);
62
 
75
 
63
        final JComboBox<SQLField> combo = new JComboBox<SQLField>(f.toArray(new SQLField[1]));
76
        final JComboBox<BatchField> combo = new JComboBox<BatchField>(f.toArray(new BatchField[1]));
64
        combo.setRenderer(new DefaultListCellRenderer() {
77
        combo.setRenderer(new DefaultListCellRenderer() {
65
            @Override
78
            @Override
66
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
79
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
67
                String label = translator.getLabelFor(((SQLField) value));
80
                String label = ((BatchField) value).getComboName();
68
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
81
                return super.getListCellRendererComponent(list, label, index, isSelected, cellHasFocus);
69
            }
82
            }
70
        });
83
        });
71
 
84
 
72
        combo.setSelectedIndex(0);
85
        combo.setSelectedIndex(0);
Line 84... Line 97...
84
        c.weighty = 1;
97
        c.weighty = 1;
85
        c.fill = GridBagConstraints.HORIZONTAL;
98
        c.fill = GridBagConstraints.HORIZONTAL;
86
        c.gridy++;
99
        c.gridy++;
87
        c.anchor = GridBagConstraints.NORTHWEST;
100
        c.anchor = GridBagConstraints.NORTHWEST;
88
        final BatchDetailPanel comp = new BatchDetailPanel();
101
        final BatchDetailPanel comp = new BatchDetailPanel();
89
        comp.setField((SQLField) combo.getSelectedItem());
102
        comp.setField((BatchField) combo.getSelectedItem());
90
        this.add(comp, c);
103
        this.add(comp, c);
91
 
104
 
92
        JPanel actions = new JPanel();
105
        JPanel actions = new JPanel();
93
        actions.setLayout(new FlowLayout(FlowLayout.RIGHT));
106
        actions.setLayout(new FlowLayout(FlowLayout.RIGHT));
94
        final JButton buttonProcess = new JButton("Lancer le traitement");
107
        final JButton buttonProcess = new JButton("Lancer le traitement");
Line 106... Line 119...
106
 
119
 
107
        combo.addItemListener(new ItemListener() {
120
        combo.addItemListener(new ItemListener() {
108
 
121
 
109
            @Override
122
            @Override
110
            public void itemStateChanged(ItemEvent e) {
123
            public void itemStateChanged(ItemEvent e) {
111
                comp.setField((SQLField) combo.getSelectedItem());
124
                comp.setField((BatchField) combo.getSelectedItem());
112
 
125
 
113
            }
126
            }
114
        });
127
        });
115
        buttonProcess.addActionListener(new ActionListener() {
128
        buttonProcess.addActionListener(new ActionListener() {
116
 
129