View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.rule.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.ui.swing.action.AbstractCheckModelAction;
27  import fr.ifremer.reefdb.ui.swing.action.AbstractReefDbSaveAction;
28  import fr.ifremer.reefdb.ui.swing.content.manage.rule.RulesUI;
29  import fr.ifremer.reefdb.ui.swing.content.manage.rule.RulesUIModel;
30  import fr.ifremer.reefdb.ui.swing.content.manage.rule.SaveAction;
31  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
32  
33  /**
34   * Action permettant d effacer la recherche sur les regles
35   */
36  public class ClearAction extends AbstractCheckModelAction<RulesMenuUIModel, RulesMenuUI, RulesMenuUIHandler> {
37  
38      /**
39       * Constructor.
40       *
41       * @param handler Controller
42       */
43      public ClearAction(final RulesMenuUIHandler handler) {
44          super(handler, false);
45      }
46  
47      /**
48       * {@inheritDoc}
49       */
50      @Override
51      public void doAction() {
52  
53          // Suppression choix de regle
54          getModel().clear();
55  
56          RulesUI rulesUI = getUI().getParentContainer(RulesUI.class);
57          rulesUI.getRuleListUI().getHandler().clearTable();
58      }
59  
60      /**
61       * {@inheritDoc}
62       */
63      @Override
64      protected Class<? extends AbstractReefDbSaveAction> getSaveActionClass() {
65          return SaveAction.class;
66      }
67  
68      /**
69       * {@inheritDoc}
70       */
71      @Override
72      protected boolean isModelModify() {
73          final RulesUIModel model = getLocalModel();
74          return model != null && model.isModify();
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      @Override
81      protected void setModelModify(boolean modelModify) {
82          final RulesUIModel model = getLocalModel();
83          if (model != null) {
84              model.setModify(modelModify);
85          }
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      protected boolean isModelValid() {
93          final RulesUIModel model = getLocalModel();
94          return model == null || model.isValid();
95      }
96  
97      /**
98       * {@inheritDoc}
99       */
100     @Override
101     protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
102         final RulesUI rulesUI = getUI().getParentContainer(RulesUI.class);
103         return rulesUI.getHandler();
104     }
105 
106     private RulesUIModel getLocalModel() {
107         final RulesUI ui = getUI().getParentContainer(RulesUI.class);
108         if (ui != null) {
109             return ui.getModel();
110         }
111         return null;
112     }
113 
114 }