View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.fraction.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.FractionDTO;
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.fraction.ManageFractionsUI;
30  import fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.fraction.SaveAction;
31  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
32  
33  import java.util.List;
34  
35  /**
36   * Search action.
37   */
38  public class SearchAction extends AbstractCheckModelAction<ManageFractionsMenuUIModel, ManageFractionsMenuUI, ManageFractionsMenuUIHandler> {
39  
40      private List<FractionDTO> result;
41  
42      /**
43       * Constructor.
44       *
45       * @param handler Le controller
46       */
47      public SearchAction(final ManageFractionsMenuUIHandler 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 AbstractApplicationUIHandler<?, ?> getSaveHandler() {
60          return getParentUI() != null ? getParentUI().getHandler() : null;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      protected boolean isModelModify() {
66          return getParentUI() != null && getParentUI().getModel().isModify();
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      protected void setModelModify(boolean modelModify) {
72          if (getParentUI() == null) {
73              return;
74          }
75          getParentUI().getModel().setModify(modelModify);
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      protected boolean isModelValid() {
81          return getParentUI() == null || getParentUI().getModel().isValid();
82      }
83  
84      /** {@inheritDoc} */
85      @Override
86      public void doAction() {
87  
88          result = getContext().getReferentialService().searchFractions(
89                          getModel().getStatusFilter(),
90                          getModel().getFractionId(),
91                          getModel().getStatusCode());
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public void postSuccessAction() {
97  
98          getModel().setResults(result);
99  
100         super.postSuccessAction();
101     }
102 
103     private ManageFractionsUI getParentUI() {
104         return getUI().getParentContainer(ManageFractionsUI.class);
105     }
106 }