View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.filter.list;
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 com.google.common.collect.Lists;
27  import fr.ifremer.dali.dto.configuration.filter.FilterDTO;
28  import fr.ifremer.dali.ui.swing.action.AbstractCheckModelAction;
29  import fr.ifremer.dali.ui.swing.action.AbstractDaliSaveAction;
30  import fr.ifremer.dali.ui.swing.content.manage.filter.FilterUIModel;
31  import fr.ifremer.dali.ui.swing.content.manage.filter.SaveAction;
32  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
33  
34  import java.util.List;
35  
36  /**
37   * Search action.
38   */
39  public class SearchAction extends AbstractCheckModelAction<FilterListUIModel, FilterListUI, FilterListUIHandler> {
40  
41      private List<FilterDTO> filters;
42  
43      /**
44       * Constructor.
45       *
46       * @param handler Le controller
47       */
48      public SearchAction(final FilterListUIHandler handler) {
49          super(handler, false);
50      }
51  
52      /** {@inheritDoc} */
53      @Override
54      public void doAction() throws Exception {
55  
56          // Filter selected
57          Integer idFiltre = null;
58          final FilterDTO filtre = (FilterDTO) getUI().getFiltersCombo().getSelectedItem();
59          if (filtre != null) {
60              idFiltre = filtre.getId();
61          }
62  
63          // Load filters
64          if (idFiltre == null) {
65              filters = getContext().getContextService().getFiltersByType(getHandler().getFilterTypeId());
66          } else {
67              filters = Lists.newArrayList(getContext().getContextService().getFilter(idFiltre));
68          }
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      protected Class<? extends AbstractDaliSaveAction> getSaveActionClass() {
74          return SaveAction.class;
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      protected boolean isModelModify() {
80          return getParentModel().isModify();
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      protected void setModelModify(boolean modelModify) {
86          getParentModel().setModify(modelModify);
87      }
88  
89      /** {@inheritDoc} */
90      @Override
91      protected boolean isModelValid() {
92          return getParentModel().isValid();
93      }
94  
95      private FilterUIModel getParentModel() {
96          return getHandler().getParentUI().getModel();
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
102         return getHandler().getParentUI().getHandler();
103     }
104 
105     /** {@inheritDoc} */
106     @Override
107     public void postSuccessAction() {
108         super.postSuccessAction();
109         getHandler().loadFilters(filters);
110     }
111 
112 
113 }