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.dali.dto.DaliBeans;
27 import fr.ifremer.dali.dto.data.survey.SurveyDTO;
28 import fr.ifremer.dali.dto.referential.QualityLevelDTO;
29 import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
30 import fr.ifremer.dali.ui.swing.content.home.HomeUIModel;
31 import fr.ifremer.dali.ui.swing.content.home.survey.qualify.QualifySurveyUI;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 import java.util.Collection;
36
37 import static org.nuiton.i18n.I18n.t;
38
39
40
41
42
43 public class QualifySurveyAction extends AbstractDaliAction<SurveysTableUIModel, SurveysTableUI, SurveysTableUIHandler> {
44
45 private Collection<? extends SurveyDTO> selectedSurveys;
46
47 private String qualificationComment;
48 private QualityLevelDTO qualityLevel;
49
50
51
52
53 private static final Log LOG = LogFactory.getLog(QualifySurveyAction.class);
54
55
56
57
58
59
60 public QualifySurveyAction(final SurveysTableUIHandler handler) {
61 super(handler, false);
62 }
63
64
65 @Override
66 public boolean prepareAction() throws Exception {
67 if (!super.prepareAction()) {
68 return false;
69 }
70
71 if (getModel().getSelectedRows().isEmpty()) {
72 LOG.warn("Aucune Observation de selectionne");
73 return false;
74 }
75
76 if (!getContext().getDataContext().isRecorderQualifier()) {
77 displayErrorMessage(t("dali.action.qualify.survey.title"), t("dali.action.qualify.survey.error.forbidden"));
78 return false;
79 }
80
81 selectedSurveys = getModel().getSelectedRows();
82
83
84 for (SurveyDTO survey : selectedSurveys) {
85
86
87 if (survey.isDirty()) {
88 getContext().getDialogHelper().showWarningDialog(t("dali.action.qualify.survey.error.dirty"));
89 return false;
90 }
91
92
93 if (!DaliBeans.isSurveyValidated(survey)) {
94 displayWarningMessage(t("dali.action.qualify.survey.title"), t("dali.action.qualify.survey.error.notValid"));
95 return false;
96 }
97
98 }
99
100
101 QualifySurveyUI qualifySurveyUI = new QualifySurveyUI(getContext());
102 getHandler().openDialog(qualifySurveyUI);
103
104 if (qualifySurveyUI.getModel().isValid()) {
105 qualificationComment = qualifySurveyUI.getModel().getComment();
106 qualityLevel = qualifySurveyUI.getModel().getQualityLevel();
107 return true;
108 }
109
110 return false;
111 }
112
113
114 @Override
115 public void doAction() throws Exception {
116 boolean isModifyModelState = getModel().isModify();
117
118
119 getContext().getObservationService().qualifySurveys(selectedSurveys, qualificationComment, qualityLevel, createProgressionUIModel());
120
121 getModel().setModify(isModifyModelState);
122 }
123
124
125 @Override
126 public void postSuccessAction() {
127
128
129 getModel().getMainUIModel().firePropertyChanged(HomeUIModel.PROPERTY_SELECTED_SURVEY, null, null);
130
131 super.postSuccessAction();
132 }
133 }