View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local;
2   
3   /*
4    * #%L
5    * Reef DB :: UI
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
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   * Created on 7/6/14.
43   *
44   * @since 3.6
45   */
46  public class OpenReplaceSamplingEquipmentAction extends AbstractReefDbAction<SamplingEquipmentsLocalUIModel, SamplingEquipmentsLocalUI, SamplingEquipmentsLocalUIHandler> {
47  
48      /**
49       * <p>Constructor for OpenReplaceSamplingEquipmentAction.</p>
50       *
51       * @param handler a {@link fr.ifremer.reefdb.ui.swing.content.manage.referential.samplingequipment.local.SamplingEquipmentsLocalUIHandler} object.
52       */
53      public OpenReplaceSamplingEquipmentAction(SamplingEquipmentsLocalUIHandler handler) {
54          super(handler, false);
55      }
56  
57      /** {@inheritDoc} */
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 }