View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.menu;
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 fr.ifremer.reefdb.dto.referential.TaxonDTO;
27  import fr.ifremer.reefdb.ui.swing.action.AbstractCheckModelAction;
28  import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbSaveAction;
29  import fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.ManageTaxonsUI;
30  import fr.ifremer.reefdb.ui.swing.content.manage.referential.taxon.SaveAction;
31  import org.apache.commons.lang3.StringUtils;
32  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
33  
34  import java.util.List;
35  
36  import static org.nuiton.i18n.I18n.t;
37  
38  /**
39   * Action permettant la recherche de taxons au niveau national
40   */
41  public class SearchAction extends AbstractCheckModelAction<TaxonMenuUIModel, TaxonMenuUI, TaxonMenuUIHandler> {
42  
43      private List<TaxonDTO> result;
44  
45      /**
46       * Constructor.
47       *
48       * @param handler Le controller
49       */
50      public SearchAction(final TaxonMenuUIHandler handler) {
51          super(handler, false);
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      protected Class<? extends AbstractReefDbSaveAction> getSaveActionClass() {
57          return SaveAction.class;
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      protected boolean isModelModify() {
63          return getParentUI() != null && getParentUI().getModel().isModify();
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      protected void setModelModify(boolean modelModify) {
69          if (getParentUI() == null) {
70              return;
71          }
72          getParentUI().getModel().setModify(modelModify);
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      protected boolean isModelValid() {
78          return getParentUI() == null || getParentUI().getModel().isValid();
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
84          return getParentUI() != null ? getParentUI().getHandler() : null;
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public boolean prepareAction() throws Exception {
90          if (!super.prepareAction()) {
91              return false;
92          }
93  
94          if (!getModel().isLocal() && getModel().getLevel() == null && StringUtils.isBlank(getModel().getName())) {
95  
96              getContext().getDialogHelper().showWarningDialog(t("reefdb.action.search.missingCriteria"));
97              return false;
98          }
99  
100         return true;
101     }
102 
103     /** {@inheritDoc} */
104     @Override
105     public void doAction() {
106 
107         result = getContext().getReferentialService().searchTaxons(getModel());
108     }
109 
110     /** {@inheritDoc} */
111     @Override
112     public void postSuccessAction() {
113 
114         getModel().setResults(result);
115 
116         super.postSuccessAction();
117     }
118 
119     private ManageTaxonsUI getParentUI() {
120         return getUI().getParentContainer(ManageTaxonsUI.class);
121     }
122 
123 }