View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.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.pmfm.PmfmDTO;
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.pmfm.ManagePmfmsUI;
30  import fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.SaveAction;
31  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
32  
33  import java.util.List;
34  
35  /**
36   * Action permettant la recherche de Quadruplets au niveau national
37   */
38  public class SearchAction extends AbstractCheckModelAction<PmfmMenuUIModel, PmfmMenuUI, PmfmMenuUIHandler> {
39  
40      private List<PmfmDTO> result;
41  
42      /**
43       * Constructor.
44       *
45       * @param handler Le controller
46       */
47      public SearchAction(final PmfmMenuUIHandler handler) {
48          super(handler, false);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      protected Class<? extends AbstractReefDbSaveAction> getSaveActionClass() {
54          return SaveAction.class;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      protected boolean isModelModify() {
60          return getParentUI() != null && getParentUI().getModel().isModify();
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      protected void setModelModify(boolean modelModify) {
66          if (getParentUI() == null) {
67              return;
68          }
69          getParentUI().getModel().setModify(modelModify);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      protected boolean isModelValid() {
75          return getParentUI() == null || getParentUI().getModel().isValid();
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
81          return getParentUI() != null ? getParentUI().getHandler() : null;
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public void doAction() {
87  
88          // load data in UI
89          result = getContext().getReferentialService().searchPmfms(
90                  getModel().getStatusFilter(),
91                  getModel().getParameterCode(),
92                  getModel().getMatrixId(),
93                  getModel().getFractionId(),
94                  getModel().getMethodId(),
95                  getModel().getUnitId(),
96                  getModel().getName(), getModel().getStatusCode());
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public void postSuccessAction() {
102 
103         getModel().setResults(result);
104 
105         super.postSuccessAction();
106     }
107 
108     private ManagePmfmsUI getParentUI() {
109         return getUI().getParentContainer(ManagePmfmsUI.class);
110     }
111 
112 }