View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.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.ReefDbBeans;
28  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
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.taxon.ManageTaxonsUI;
33  import fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.local.replace.ReplaceTaxonUI;
34  import fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.local.replace.ReplaceTaxonUIModel;
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  public class OpenReplaceTaxonAction extends AbstractReefDbAction<TaxonsLocalUIModel, TaxonsLocalUI, TaxonsLocalUIHandler> {
45  
46      /**
47       * <p>Constructor for OpenReplaceTaxonAction.</p>
48       *
49       * @param handler a {@link fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.local.TaxonsLocalUIHandler} object.
50       */
51      public OpenReplaceTaxonAction(TaxonsLocalUIHandler handler) {
52          super(handler, false);
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public void doAction() {
58  
59          AbstractOpenReplaceUIAction<TaxonDTO, ReplaceTaxonUIModel, ReplaceTaxonUI> openAction =
60                  new AbstractOpenReplaceUIAction<TaxonDTO, ReplaceTaxonUIModel, ReplaceTaxonUI>(getContext().getMainUI().getHandler()) {
61  
62                      @Override
63                      protected String getEntityLabel() {
64                          return t("reefdb.property.taxon");
65                      }
66  
67                      @Override
68                      protected ReplaceTaxonUIModel createNewModel() {
69                          return new ReplaceTaxonUIModel();
70                      }
71  
72                      @Override
73                      protected ReplaceTaxonUI createUI(JAXXInitialContext ctx) {
74                          return new ReplaceTaxonUI(ctx);
75                      }
76  
77                      @Override
78                      protected List<TaxonDTO> getReferentialList(ReferentialService referentialService) {
79                          return Lists.newArrayList(referentialService.getTaxons(null));
80                      }
81  
82                      @Override
83                      protected List<TaxonDTO> getSourceListFromReferentialList(List<TaxonDTO> list) {
84                          return ReefDbBeans.filterLocalReferential(list);
85                      }
86  
87                      @Override
88                      protected TaxonDTO getSelectedSource() {
89                          List<TaxonDTO> selectedBeans = OpenReplaceTaxonAction.this.getModel().getSelectedBeans();
90                          return selectedBeans.size() == 1 ? selectedBeans.get(0) : null;
91                      }
92  
93                      @Override
94                      protected TaxonDTO getSelectedTarget() {
95                          ManageTaxonsUI ui = OpenReplaceTaxonAction.this.getUI().getParentContainer(ManageTaxonsUI.class);
96                          List<TaxonDTO> selectedBeans = ui.getTaxonsNationalUI().getModel().getSelectedBeans();
97                          return selectedBeans.size() == 1 ? selectedBeans.get(0) : null;
98                      }
99                  };
100 
101         getActionEngine().runFullInternalAction(openAction);
102     }
103 }