1 package fr.ifremer.dali.ui.swing.content.manage.filter;
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 com.google.common.collect.Lists;
27 import fr.ifremer.dali.dto.configuration.filter.FilterDTO;
28 import fr.ifremer.dali.ui.swing.action.AbstractDaliSaveAction;
29 import fr.ifremer.quadrige3.ui.swing.model.AbstractBeanUIModel;
30
31 import java.util.List;
32
33
34
35
36 public class SaveAction extends AbstractDaliSaveAction<FilterUIModel, FilterUI, FilterUIHandler> {
37
38 private List<? extends FilterDTO> filtersToSave;
39
40
41
42
43
44
45 public SaveAction(final FilterUIHandler handler) {
46 super(handler, false);
47 }
48
49
50 @Override
51 public boolean prepareAction() throws Exception {
52 if (!super.prepareAction() || !getModel().isModify() || !getModel().isValid()) {
53 return false;
54 }
55
56 filtersToSave = getUI().getFilterListUI().getModel().getRows();
57 return !filtersToSave.isEmpty();
58 }
59
60
61 @Override
62 public void doAction() throws Exception {
63
64
65 getContext().getContextService().saveFilters(filtersToSave);
66 }
67
68
69 @Override
70 protected List<AbstractBeanUIModel> getModelsToModify() {
71 return Lists.newArrayList(
72 getModel().getFilterListUIModel(),
73 getModel().getFilterElementUIModel()
74 );
75 }
76
77
78 @Override
79 public void postSuccessAction() {
80
81 getUI().getFilterListUI().getHandler().reloadComboBox();
82
83 super.postSuccessAction();
84
85 }
86 }