View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.filter;
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.AbstractDaliSaveAction;
29  import fr.ifremer.quadrige3.ui.swing.model.AbstractBeanUIModel;
30  
31  import java.util.List;
32  
33  /**
34   * Save action.
35   */
36  public class SaveAction extends AbstractDaliSaveAction<FilterUIModel, FilterUI, FilterUIHandler> {
37  
38      private List<? extends FilterDTO> filtersToSave;
39  
40      /**
41       * Constructor.
42       *
43       * @param handler Controller
44       */
45      public SaveAction(final FilterUIHandler handler) {
46          super(handler, false);
47      }
48  
49      /** {@inheritDoc} */
50      @Override
51      public boolean prepareAction() throws Exception {
52          if (!super.prepareAction() || !getModel().isModify() || !getModel().isValid()) {
53              return false;
54          }
55  
56          filtersToSave = getUI().getFilterListUI().getModel().getRows();
57          return !filtersToSave.isEmpty();
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public void doAction() throws Exception {
63  
64          // Save Filters by generic method
65          getContext().getContextService().saveFilters(filtersToSave);
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      protected List<AbstractBeanUIModel> getModelsToModify() {
71          return Lists.newArrayList(
72                  getModel().getFilterListUIModel(),
73                  getModel().getFilterElementUIModel()
74          );
75      }
76  
77      /** {@inheritDoc} */
78      @Override
79      public void postSuccessAction() {
80  
81          getUI().getFilterListUI().getHandler().reloadComboBox();
82  
83          super.postSuccessAction();
84  
85      }
86  }