1 package fr.ifremer.dali.ui.swing.content.home.survey;
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.quadrige3.ui.swing.ApplicationUIUtil;
27 import fr.ifremer.quadrige3.ui.swing.DialogHelper;
28 import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
29 import fr.ifremer.dali.ui.swing.content.home.HomeUI;
30 import fr.ifremer.dali.ui.swing.content.home.SaveAction;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 import javax.swing.JOptionPane;
35 import java.util.Set;
36
37 import static org.nuiton.i18n.I18n.t;
38
39
40
41
42
43 public class ControlSurveyAction extends AbstractDaliAction<SurveysTableUIModel, SurveysTableUI, SurveysTableUIHandler> {
44
45
46
47
48 private static final Log LOG = LogFactory.getLog(ControlSurveyAction.class);
49
50 private Set<SurveysTableRowModel> selectedSurveys;
51
52
53
54
55
56
57 public ControlSurveyAction(final SurveysTableUIHandler handler) {
58 super(handler, false);
59 }
60
61
62
63
64 @Override
65 public boolean prepareAction() throws Exception {
66 if (!super.prepareAction()) {
67 return false;
68 }
69
70 if (getModel().getSelectedRows().isEmpty()) {
71 LOG.warn("Aucune Observation de selectionne");
72 return false;
73 }
74
75 selectedSurveys = getModel().getSelectedRows();
76
77 boolean alreadyControlled = false;
78 for (SurveysTableRowModel rowModel : selectedSurveys) {
79 if (rowModel.getValidationDate() != null) {
80
81 getContext().getDialogHelper().showWarningDialog(t("dali.action.control.survey.error.alreadyValid"));
82 return false;
83 }
84 if (!alreadyControlled && rowModel.getControlDate() != null) {
85 alreadyControlled = true;
86 }
87 }
88
89 return getContext().getDialogHelper().showOptionDialog(null,
90 ApplicationUIUtil.getHtmlString(alreadyControlled ? t("dali.action.control.survey.multiple.message") : t("dali.action.control.survey.message")),
91 alreadyControlled ? t("dali.action.control.survey.multiple.titre") : t("dali.action.control.survey.titre"),
92 JOptionPane.QUESTION_MESSAGE,
93 DialogHelper.CUSTOM_OPTION,
94 t("dali.common.control"),
95 t("dali.common.cancel")
96 ) == JOptionPane.OK_OPTION;
97
98 }
99
100
101
102
103 @Override
104 public void doAction() throws Exception {
105
106 SaveAction saveAction = getContext().getActionFactory().createLogicAction(getUI().getParentContainer(HomeUI.class).getHandler(), SaveAction.class);
107 saveAction.setSurveysToSave(selectedSurveys);
108 saveAction.setShowControlIfSuccess(true);
109 saveAction.setUpdateControlDateWhenControlSucceed(true);
110 getContext().getActionEngine().runFullInternalAction(saveAction);
111 }
112 }