1 package fr.ifremer.tutti.ui.swing.content.operation.catches.actions;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import fr.ifremer.tutti.persistence.entities.data.CatchBatch;
26 import fr.ifremer.tutti.service.PersistenceService;
27 import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUI;
28 import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIHandler;
29 import fr.ifremer.tutti.ui.swing.content.operation.catches.EditCatchesUIModel;
30 import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor;
31 import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35
36
37
38
39
40
41 public class SaveCatchBatchAction extends LongActionSupport<EditCatchesUIModel, EditCatchesUI, EditCatchesUIHandler> {
42
43
44 private static final Log log = LogFactory.getLog(SaveCatchBatchAction.class);
45
46
47
48
49
50
51 protected boolean updateUI;
52
53 public SaveCatchBatchAction(EditCatchesUIHandler handler) {
54 super(handler, true);
55 }
56
57 public void setUpdateUI(boolean updateUI) {
58 this.updateUI = updateUI;
59 }
60
61 @Override
62 public void releaseAction() {
63 updateUI = true;
64 super.releaseAction();
65 }
66
67 @Override
68 public void doAction() throws Exception {
69
70 TuttiBeanMonitor<EditCatchesUIModel> monitor = handler.getCatchBatchMonitor();
71
72
73 EditCatchesUIModel beanToSave = monitor.getBean();
74
75
76 boolean mustSave = (beanToSave.isCreate() || beanToSave.isModify()) && beanToSave.isValid();
77
78 if (mustSave) {
79
80 PersistenceService persistenceService = getContext().getPersistenceService();
81
82 CatchBatch catchBatch = beanToSave.toEntity();
83
84 if (log.isInfoEnabled()) {
85 log.info("FishingOperation " + catchBatch.getId() + " was modified, will save it.");
86 }
87
88
89 sendMessage("[ Captures - Caractéristiques générales ] Sauvegarde des modifications du résumé de la capture.");
90
91 persistenceService.saveCatchBatch(catchBatch);
92
93 monitor.clearModified();
94 getModel().setModify(false);
95 }
96
97 getUI().getSpeciesTabPanel().getEditBatchesUI().getHandler().clearTableSelection();
98 getUI().getBenthosTabPanel().getEditBatchesUI().getHandler().clearTableSelection();
99
100 }
101
102 }