1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.unit;
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.reefdb.ui.swing.action.QuitScreenAction;
27 import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbBeanUIModel;
28 import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbUIHandler;
29 import jaxx.runtime.SwingUtil;
30 import jaxx.runtime.validator.swing.SwingValidator;
31 import org.apache.commons.logging.Log;
32 import org.apache.commons.logging.LogFactory;
33 import org.nuiton.jaxx.application.swing.util.CloseableUI;
34
35 import java.beans.PropertyChangeEvent;
36 import java.beans.PropertyChangeListener;
37
38
39
40
41 public class ReferentialUnitsUIHandler extends AbstractReefDbUIHandler<ReferentialUnitsUIModel, ReferentialUnitsUI> implements CloseableUI {
42
43
44
45
46 private static final Log LOG = LogFactory.getLog(ReferentialUnitsUIHandler.class);
47
48
49 @Override
50 public void beforeInit(ReferentialUnitsUI ui) {
51 super.beforeInit(ui);
52
53
54 ui.setContextValue(new ReferentialUnitsUIModel());
55 ui.setContextValue(SwingUtil.createActionIcon("config"));
56
57 }
58
59
60 @Override
61 public void afterInit(ReferentialUnitsUI ui) {
62 initUI(ui);
63
64
65 getContext().clearObservationPrelevementsIds();
66
67 getModel().setLocalUIModel(getUI().getReferentialUnitsLocalUI().getModel());
68
69 listenModelModify(getModel().getLocalUIModel());
70 getModel().getLocalUIModel().addPropertyChangeListener(AbstractReefDbBeanUIModel.PROPERTY_VALID, evt -> getValidator().doValidate());
71 registerValidators(getValidator());
72 listenValidatorValid(getValidator(), getModel());
73
74 }
75
76
77 @Override
78 public SwingValidator<ReferentialUnitsUIModel> getValidator() {
79 return getUI().getValidator();
80 }
81
82
83 @Override
84 @SuppressWarnings("unchecked")
85 public boolean quitUI() {
86 try {
87 QuitScreenAction action = new QuitScreenAction(this, false, SaveAction.class);
88 if (action.prepareAction()) {
89 return true;
90 }
91 } catch (Exception e) {
92 LOG.error(e.getLocalizedMessage(), e);
93 }
94 return false;
95
96 }
97 }