1 package fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local;
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.reefdb.dto.referential.SamplingEquipmentDTO;
28 import fr.ifremer.reefdb.service.StatusFilter;
29 import fr.ifremer.reefdb.service.referential.ReferentialService;
30 import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbAction;
31 import fr.ifremer.reefdb.ui.swing.content.manage.referential.replace.AbstractOpenReplaceUIAction;
32 import fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.ManageSamplingEquipmentsUI;
33 import fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local.replace.ReplaceSamplingEquipmentUI;
34 import fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local.replace.ReplaceSamplingEquipmentUIModel;
35 import jaxx.runtime.context.JAXXInitialContext;
36
37 import java.util.List;
38
39 import static org.nuiton.i18n.I18n.t;
40
41
42
43
44
45
46 public class OpenReplaceSamplingEquipmentAction extends AbstractReefDbAction<SamplingEquipmentsLocalUIModel, SamplingEquipmentsLocalUI, SamplingEquipmentsLocalUIHandler> {
47
48
49
50
51
52
53 public OpenReplaceSamplingEquipmentAction(SamplingEquipmentsLocalUIHandler handler) {
54 super(handler, false);
55 }
56
57
58 @Override
59 public void doAction() {
60
61 AbstractOpenReplaceUIAction<SamplingEquipmentDTO, ReplaceSamplingEquipmentUIModel, ReplaceSamplingEquipmentUI> openAction =
62 new AbstractOpenReplaceUIAction<SamplingEquipmentDTO, ReplaceSamplingEquipmentUIModel, ReplaceSamplingEquipmentUI>(getContext().getMainUI().getHandler()) {
63
64 @Override
65 protected String getEntityLabel() {
66 return t("reefdb.property.samplingEquipment");
67 }
68
69 @Override
70 protected ReplaceSamplingEquipmentUIModel createNewModel() {
71 return new ReplaceSamplingEquipmentUIModel();
72 }
73
74 @Override
75 protected ReplaceSamplingEquipmentUI createUI(JAXXInitialContext ctx) {
76 return new ReplaceSamplingEquipmentUI(ctx);
77 }
78
79 @Override
80 protected List<SamplingEquipmentDTO> getReferentialList(ReferentialService referentialService) {
81 return Lists.newArrayList(referentialService.getSamplingEquipments(StatusFilter.ACTIVE));
82 }
83
84 @Override
85 protected SamplingEquipmentDTO getSelectedSource() {
86 List<SamplingEquipmentDTO> selectedBeans = OpenReplaceSamplingEquipmentAction.this.getModel().getSelectedBeans();
87 return selectedBeans.size() == 1 ? selectedBeans.get(0) : null;
88 }
89
90 @Override
91 protected SamplingEquipmentDTO getSelectedTarget() {
92 ManageSamplingEquipmentsUI ui = OpenReplaceSamplingEquipmentAction.this.getUI().getParentContainer(ManageSamplingEquipmentsUI.class);
93 List<SamplingEquipmentDTO> selectedBeans = ui.getSamplingEquipmentsNationalUI().getModel().getSelectedBeans();
94 return selectedBeans.size() == 1 ? selectedBeans.get(0) : null;
95 }
96 };
97
98 getActionEngine().runFullInternalAction(openAction);
99 }
100 }