1 package fr.ifremer.tutti.ui.swing.content.operation.fishing.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.TuttiEntities;
26 import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
27 import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
28 import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUI;
29 import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIHandler;
30 import fr.ifremer.tutti.ui.swing.content.operation.FishingOperationsUIModel;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33
34 import static org.nuiton.i18n.I18n.t;
35
36
37
38
39
40
41
42 public class DeleteFishingOperationAction extends LongActionSupport<FishingOperationsUIModel, FishingOperationsUI, FishingOperationsUIHandler> {
43
44
45 private static final Log log =
46 LogFactory.getLog(DeleteFishingOperationAction.class);
47
48 public DeleteFishingOperationAction(FishingOperationsUIHandler handler) {
49 super(handler, true);
50 setActionDescription(
51 t("tutti.editFishingOperation.action.deleteFishingOperation.tip"));
52 }
53
54 @Override
55 public boolean prepareAction() throws Exception {
56 boolean canContinue = super.prepareAction();
57 FishingOperation fishingOperation = getModel().getSelectedFishingOperation();
58 canContinue &= fishingOperation != null &&
59 !TuttiEntities.isNew(fishingOperation) &&
60 askBeforeDelete(
61 t("tutti.editFishingOperation.action.deleteFishingOperation.title"),
62 t("tutti.editFishingOperation.action.deleteFishingOperation.message", decorate(fishingOperation))
63 );
64 return canContinue;
65 }
66
67 @Override
68 public void doAction() throws Exception {
69
70 FishingOperation fishingOperation =
71 getModel().getSelectedFishingOperation();
72
73 if (log.isInfoEnabled()) {
74 log.info("Will delete fishingOperation: " + fishingOperation);
75 }
76
77 getContext().getPersistenceService().deleteFishingOperation(fishingOperation.getIdAsInt());
78
79 FishingOperationsUIModel model = getModel();
80
81
82 model.setSelectedFishingOperation(null);
83
84
85 model.removeFishingOperation(fishingOperation);
86
87 sendMessage(t("tutti.editFishingOperation.message.operation.deleted", decorate(fishingOperation)));
88 }
89 }