View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.rule.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.ui.swing.action.AbstractCheckModelAction;
27  import fr.ifremer.dali.ui.swing.action.AbstractDaliSaveAction;
28  import fr.ifremer.dali.ui.swing.content.manage.rule.RulesUI;
29  import fr.ifremer.dali.ui.swing.content.manage.rule.RulesUIModel;
30  import fr.ifremer.dali.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() throws Exception {
52  
53          // Suppression choix de regle
54          getModel().clear();
55  
56          getHandler().getRulesUI().getRuleListUI().getHandler().clearTable();
57      }
58  
59      /**
60       * {@inheritDoc}
61       */
62      @Override
63      protected Class<? extends AbstractDaliSaveAction> getSaveActionClass() {
64          return SaveAction.class;
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      protected boolean isModelModify() {
72          final RulesUIModel model = getLocalModel();
73          return model != null && model.isModify();
74      }
75  
76      /**
77       * {@inheritDoc}
78       */
79      @Override
80      protected void setModelModify(boolean modelModify) {
81          final RulesUIModel 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 RulesUIModel model = getLocalModel();
93          return model == null || model.isValid();
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
101         return getHandler().getRulesUI().getHandler();
102     }
103 
104     private RulesUIModel getLocalModel() {
105         final RulesUI ui = getHandler().getRulesUI();
106         if (ui != null) {
107             return ui.getModel();
108         }
109         return null;
110     }
111 
112 }