View Javadoc
1   /*
2    * To change this license header, choose License Headers in Project Properties.
3    * To change this template file, choose Tools | Templates
4    * and open the template in the editor.
5    */
6   
7   package fr.ifremer.dali.ui.swing.content.manage.filter.element.menu;
8   
9   /*
10   * #%L
11   * Dali :: UI
12   * $Id:$
13   * $HeadURL:$
14   * %%
15   * Copyright (C) 2014 - 2015 Ifremer
16   * %%
17   * This program is free software: you can redistribute it and/or modify
18   * it under the terms of the GNU Affero General Public License as published by
19   * the Free Software Foundation, either version 3 of the License, or
20   * (at your option) any later version.
21   * 
22   * This program is distributed in the hope that it will be useful,
23   * but WITHOUT ANY WARRANTY; without even the implied warranty of
24   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25   * GNU General Public License for more details.
26   * 
27   * You should have received a copy of the GNU Affero General Public License
28   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29   * #L%
30   */
31  
32  import fr.ifremer.quadrige3.ui.core.dto.QuadrigeBean;
33  import fr.ifremer.dali.ui.swing.action.AbstractDaliAction;
34  
35  import java.util.List;
36  
37  /**
38   * <p>ApplyFilterAction class.</p>
39   *
40   * @author Lionel Touseau <lionel.touseau@e-is.pro>
41   */
42  public class ApplyFilterAction extends AbstractDaliAction<ApplyFilterUIModel, ApplyFilterUI, ApplyFilterUIHandler> {
43  
44      private List<? extends QuadrigeBean> elements;
45  
46      /**
47       * Constructor.
48       *
49       * @param handler Le controller
50       */
51      public ApplyFilterAction(ApplyFilterUIHandler handler) {
52          super(handler, false);
53      }
54  
55      /** {@inheritDoc} */
56      @Override
57      public void doAction() throws Exception {
58  
59          if (getModel().getFilter() != null) {
60  
61              // load filtered elements if needed
62              if (!getModel().getFilter().isFilterLoaded()) {
63                  getContext().getContextService().loadFilteredElements(getModel().getFilter());
64              }
65  
66              elements = getModel().getFilter().getElements();
67  
68          } else {
69  
70              // empty elements
71              elements = null;
72          }
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public void postSuccessAction() {
78  
79          getModel().setElements(elements);
80  
81          super.postSuccessAction();
82      }
83  }