102 |
ilm |
1 |
package org.openconcerto.modules.common.batchprocessing;
|
|
|
2 |
|
|
|
3 |
import java.sql.SQLException;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import javax.swing.ButtonGroup;
|
|
|
7 |
import javax.swing.JPanel;
|
|
|
8 |
import javax.swing.JRadioButton;
|
|
|
9 |
|
|
|
10 |
import org.openconcerto.sql.model.SQLField;
|
|
|
11 |
import org.openconcerto.sql.model.SQLRowAccessor;
|
|
|
12 |
import org.openconcerto.sql.model.SQLRowValues;
|
|
|
13 |
import org.openconcerto.ui.VFlowLayout;
|
|
|
14 |
|
|
|
15 |
public class BooleanProcessor extends JPanel implements BatchProcessor {
|
181 |
ilm |
16 |
private final BatchField field;
|
102 |
ilm |
17 |
|
|
|
18 |
private JRadioButton bTrue;
|
|
|
19 |
private JRadioButton bFalse;
|
|
|
20 |
private JRadioButton bInvert;
|
|
|
21 |
|
181 |
ilm |
22 |
public BooleanProcessor(BatchField field) {
|
102 |
ilm |
23 |
this.field = field;
|
|
|
24 |
this.setLayout(new VFlowLayout());
|
|
|
25 |
bTrue = new JRadioButton("forcer à vrai");
|
|
|
26 |
bFalse = new JRadioButton("forcer à faux");
|
|
|
27 |
bInvert = new JRadioButton("inverser");
|
|
|
28 |
final ButtonGroup group = new ButtonGroup();
|
|
|
29 |
group.add(bTrue);
|
|
|
30 |
group.add(bFalse);
|
|
|
31 |
group.add(bInvert);
|
|
|
32 |
this.add(bTrue);
|
|
|
33 |
this.add(bFalse);
|
|
|
34 |
this.add(bInvert);
|
|
|
35 |
group.setSelected(bTrue.getModel(), true);
|
|
|
36 |
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@Override
|
183 |
ilm |
40 |
public void process(List<SQLRowAccessor> r) throws SQLException {
|
102 |
ilm |
41 |
if (bTrue.isSelected()) {
|
|
|
42 |
for (SQLRowAccessor sqlRowAccessor : r) {
|
|
|
43 |
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
|
181 |
ilm |
44 |
rowValues.put(field.getField().getName(), Boolean.TRUE);
|
102 |
ilm |
45 |
processBeforeUpdate(sqlRowAccessor, rowValues);
|
|
|
46 |
rowValues.update();
|
|
|
47 |
}
|
|
|
48 |
} else if (bFalse.isSelected()) {
|
|
|
49 |
for (SQLRowAccessor sqlRowAccessor : r) {
|
|
|
50 |
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
|
181 |
ilm |
51 |
rowValues.put(field.getField().getName(), Boolean.FALSE);
|
102 |
ilm |
52 |
processBeforeUpdate(sqlRowAccessor, rowValues);
|
|
|
53 |
rowValues.update();
|
|
|
54 |
}
|
|
|
55 |
} else if (bInvert.isSelected()) {
|
|
|
56 |
for (SQLRowAccessor sqlRowAccessor : r) {
|
|
|
57 |
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
|
181 |
ilm |
58 |
final Boolean boolean1 = sqlRowAccessor.asRow().getBoolean(field.getField().getName());
|
102 |
ilm |
59 |
if (boolean1 != null) {
|
181 |
ilm |
60 |
rowValues.put(field.getField().getName(), boolean1.equals(Boolean.FALSE));
|
102 |
ilm |
61 |
processBeforeUpdate(sqlRowAccessor, rowValues);
|
|
|
62 |
rowValues.update();
|
|
|
63 |
}
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
@Override
|
|
|
69 |
public boolean checkParameters() {
|
|
|
70 |
return true;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
|
|
|
74 |
}
|
|
|
75 |
}
|