View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.campaign.menu;
2   
3   /*
4    * #%L
5    * Dali :: 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.dali.dto.data.survey.CampaignDTO;
27  import fr.ifremer.dali.ui.swing.action.AbstractCheckModelAction;
28  import fr.ifremer.dali.ui.swing.content.manage.campaign.CampaignsUI;
29  import fr.ifremer.dali.ui.swing.content.manage.campaign.CampaignsUIModel;
30  import fr.ifremer.dali.ui.swing.content.manage.program.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<CampaignsMenuUIModel, CampaignsMenuUI, CampaignsMenuUIHandler> {
39  
40      private List<CampaignDTO> results;
41  
42      /**
43       * Constructor.
44       *
45       * @param handler Le controller
46       */
47      public SearchAction(final CampaignsMenuUIHandler handler) {
48          super(handler, false);
49      }
50  
51      /**
52       * {@inheritDoc}
53       */
54      @Override
55      protected Class<SaveAction> getSaveActionClass() {
56          return SaveAction.class;
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      @Override
63      protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
64          return getHandler().getCampaignsUI().getHandler();
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      protected boolean isModelModify() {
72          final CampaignsUIModel model = getLocalModel();
73          return model != null && model.isModify();
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      protected void setModelModify(boolean modelModify) {
81          final CampaignsUIModel model = getLocalModel();
82          if (model != null) {
83              model.setModify(modelModify);
84          }
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      @Override
91      protected boolean isModelValid() {
92          final CampaignsUIModel model = getLocalModel();
93          return model == null || model.isValid();
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public void doAction() throws Exception {
101 
102         // Load program by code
103         results = getContext().getCampaignService().findCampaignsByCriteria(
104                 getModel().getName(),
105                 getModel().getSearchStartDate(), getModel().getStartDate1(), getModel().getStartDate2(),
106                 getModel().getSearchEndDate(), getModel().getEndDate1(), getModel().getEndDate2()
107         );
108 
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     @Override
115     public void postSuccessAction() {
116 
117         getModel().setResults(results);
118 
119         super.postSuccessAction();
120     }
121 
122     private CampaignsUIModel getLocalModel() {
123         CampaignsUI ui = getHandler().getCampaignsUI();
124         return ui != null ? ui.getModel() : null;
125     }
126 
127 }