1 package fr.ifremer.dali.ui.swing.content.manage.program.locations.updatePeriod;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import fr.ifremer.dali.dto.configuration.programStrategy.AppliedStrategyDTO;
27 import fr.ifremer.dali.dto.referential.DepartmentDTO;
28 import fr.ifremer.dali.service.StatusFilter;
29 import fr.ifremer.dali.ui.swing.util.AbstractDaliUIHandler;
30 import org.nuiton.jaxx.application.swing.util.Cancelable;
31
32 import javax.swing.JComponent;
33 import java.time.LocalDate;
34
35 import static org.nuiton.i18n.I18n.t;
36
37
38
39
40 public class UpdatePeriodUIHandler extends AbstractDaliUIHandler<UpdatePeriodUIModel, UpdatePeriodUI> implements Cancelable {
41
42
43 @Override
44 public void beforeInit(UpdatePeriodUI ui) {
45 super.beforeInit(ui);
46
47 ui.setContextValue(new UpdatePeriodUIModel());
48 }
49
50
51 @Override
52 public void afterInit(UpdatePeriodUI ui) {
53 initUI(ui);
54
55
56 initBeanFilterableComboBox(
57 getUI().getSamplerCombo(),
58 getContext().getReferentialService().getDepartments(StatusFilter.ACTIVE),
59 null);
60
61 getUI().getSamplerCombo().setShowReset(true);
62 getUI().getSamplerCombo().setShowDecorator(false);
63
64 initBeanFilterableComboBox(
65 getUI().getAnalystCombo(),
66 getContext().getReferentialService().getDepartments(StatusFilter.ACTIVE),
67 null);
68
69 getUI().getAnalystCombo().setShowReset(true);
70 getUI().getAnalystCombo().setShowDecorator(false);
71
72 }
73
74
75
76
77 public void valid() {
78
79
80 final LocalDate startDate = getUI().getStartDateEditor().getLocalDate();
81 final LocalDate endDate = getUI().getEndDateEditor().getLocalDate();
82 final DepartmentDTO samplingDepartment = (DepartmentDTO) getUI().getSamplerCombo().getSelectedItem();
83 final DepartmentDTO analystDepartment = (DepartmentDTO) getUI().getAnalystCombo().getSelectedItem();
84
85 if (startDate == null ^ endDate == null) {
86
87
88 getContext().getDialogHelper().showErrorDialog(getUI(),
89 t("dali.program.location.periods.error.date.message"),
90 t("dali.program.location.periods.error.titre"));
91
92 } else if (startDate != null && endDate != null && endDate.isBefore(startDate)) {
93
94
95 getContext().getDialogHelper().showErrorDialog(getUI(),
96 t("dali.program.location.periods.error.date.before.message"),
97 t("dali.program.location.periods.error.titre"));
98
99 } else {
100
101
102 for (final AppliedStrategyDTO lieu : getModel().getTableModel().getSelectedRows()) {
103 lieu.setStartDate(startDate);
104 lieu.setEndDate(endDate);
105 lieu.setSamplingDepartment(samplingDepartment);
106 lieu.setAnalysisDepartment(analystDepartment);
107 }
108
109
110 closeDialog();
111 }
112 }
113
114
115 @Override
116 protected JComponent getComponentToFocus() {
117 return getUI().getStartDateEditor();
118 }
119
120
121 @Override
122 public void cancel() {
123 closeDialog();
124 }
125 }