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 com.google.common.collect.ImmutableList;
27  import com.google.common.collect.Lists;
28  import fr.ifremer.dali.dto.configuration.control.RuleListDTO;
29  import fr.ifremer.dali.ui.swing.action.AbstractCheckModelAction;
30  import fr.ifremer.dali.ui.swing.content.manage.rule.RulesUI;
31  import fr.ifremer.dali.ui.swing.content.manage.rule.RulesUIModel;
32  import fr.ifremer.dali.ui.swing.content.manage.rule.SaveAction;
33  import fr.ifremer.quadrige3.ui.swing.model.AbstractBeanUIModel;
34  import org.apache.commons.lang3.StringUtils;
35  import org.nuiton.jaxx.application.swing.AbstractApplicationUIHandler;
36  
37  import java.util.List;
38  
39  /**
40   * Search action.
41   */
42  public class SearchAction extends AbstractCheckModelAction<RulesMenuUIModel, RulesMenuUI, RulesMenuUIHandler> {
43  
44      private List<RuleListDTO> ruleLists;
45  
46      /**
47       * Constructor.
48       *
49       * @param handler Le controller
50       */
51      public SearchAction(final RulesMenuUIHandler handler) {
52          super(handler, false);
53      }
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      protected Class<SaveAction> getSaveActionClass() {
60          return SaveAction.class;
61      }
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      protected AbstractApplicationUIHandler<?, ?> getSaveHandler() {
68          return getHandler().getRulesUI().getHandler();
69      }
70  
71      /**
72       * {@inheritDoc}
73       */
74      @Override
75      protected boolean isModelModify() {
76          final RulesUIModel model = getLocalModel();
77          return model != null && model.isModify();
78      }
79  
80      /**
81       * {@inheritDoc}
82       */
83      @Override
84      protected void setModelModify(boolean modelModify) {
85          final RulesUIModel model = getLocalModel();
86          if (model != null) {
87              model.setModify(modelModify);
88          }
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      @Override
95      protected boolean isModelValid() {
96          final RulesUIModel model = getLocalModel();
97          return model == null || model.isValid();
98      }
99  
100     /**
101      * {@inheritDoc}
102      */
103     @Override
104     public void doAction() throws Exception {
105 
106         // Recuperation de la liste des regles
107         if (StringUtils.isNotBlank(getModel().getRuleListCode())) {
108             ruleLists = Lists.newArrayList(getContext().getRuleListService().getRuleList(getModel().getRuleListCode()));
109         } else if (StringUtils.isNotBlank(getModel().getProgramCode())) {
110             ruleLists = Lists.newArrayList(getContext().getRuleListService().getRuleListsForProgram(getModel().getProgramCode()));
111         } else {
112             ruleLists = getContext().getRuleListService().getAllRuleLists();
113         }
114 
115     }
116 
117     @Override
118     public void postSuccessAction() {
119 
120         getModel().setResults(ruleLists);
121 
122         super.postSuccessAction();
123     }
124 
125     private RulesUIModel getLocalModel() {
126         final RulesUI ui = getHandler().getRulesUI();
127         if (ui != null) {
128             return ui.getModel();
129         }
130         return null;
131     }
132 
133     @Override
134     protected List<AbstractBeanUIModel> getOtherModelsToModify() {
135         RulesUI ui = getHandler().getRulesUI();
136         if (ui != null) {
137             return ImmutableList.of(
138                 ui.getRuleListUI().getModel(),
139                 ui.getControlProgramTableUI().getModel(),
140                 ui.getControlDepartmentTableUI().getModel(),
141                 ui.getControlRuleTableUI().getModel(),
142                 ui.getControlPmfmTableUI().getModel()
143             );
144         }
145         return super.getOtherModelsToModify();
146     }
147 
148 }