1 package fr.ifremer.tutti.ui.swing.content.home.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 com.google.common.base.Preconditions;
26 import fr.ifremer.tutti.persistence.entities.protocol.TuttiProtocol;
27 import fr.ifremer.tutti.service.PersistenceService;
28 import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUI;
29 import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUIHandler;
30 import fr.ifremer.tutti.ui.swing.content.home.SelectCruiseUIModel;
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 import java.util.List;
36
37 import static org.nuiton.i18n.I18n.t;
38
39
40
41
42
43
44
45 public class DeleteProtocolAction extends LongActionSupport<SelectCruiseUIModel, SelectCruiseUI, SelectCruiseUIHandler> {
46
47
48 private static final Log log = LogFactory.getLog(EditProtocolAction.class);
49
50 public DeleteProtocolAction(SelectCruiseUIHandler handler) {
51 super(handler, false);
52 }
53
54 @Override
55 public boolean prepareAction() throws Exception {
56 boolean result = super.prepareAction();
57
58 TuttiProtocol protocol = getHandler().getModel().getProtocol();
59
60 result &=
61 askBeforeDelete(
62 t("tutti.selectCruise.action.deleteProtocol.title"),
63 t("tutti.selectCruise.action.deleteProtocol.message", protocol.getName())
64 );
65
66 return result;
67 }
68
69 @Override
70 public void doAction() {
71 TuttiProtocol protocol = getModel().getProtocol();
72 Preconditions.checkNotNull(protocol);
73 String id = protocol.getId();
74 Preconditions.checkNotNull(id);
75 if (log.isInfoEnabled()) {
76 log.info("Delete protocol: " + id);
77 }
78
79 PersistenceService service = getContext().getPersistenceService();
80 service.deleteProtocol(id);
81
82 getModel().setProtocol(null);
83
84 List<TuttiProtocol> protocols = getModel().getProtocols();
85 protocols.remove(protocol);
86
87 if (log.isInfoEnabled()) {
88 log.info("nb protocols: " + protocols.size());
89 }
90
91 getModel().setProtocols(null);
92
93
94 getModel().setProtocols(protocols);
95
96 }
97
98 @Override
99 public void postSuccessAction() {
100
101 getHandler().resetComboBoxAction(getUI().getEditProtocolComboBox());
102 super.postSuccessAction();
103
104 }
105 }