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.quadrige3.core.security.SecurityContextHelper;
27  import fr.ifremer.reefdb.dto.configuration.control.RuleListDTO;
28  import fr.ifremer.reefdb.dto.configuration.filter.FilterDTO;
29  import fr.ifremer.reefdb.service.StatusFilter;
30  import fr.ifremer.reefdb.ui.swing.content.manage.filter.element.menu.ApplyFilterUI;
31  import fr.ifremer.reefdb.ui.swing.content.manage.referential.menu.ReferentialMenuUIHandler;
32  import fr.ifremer.reefdb.ui.swing.util.ReefDbUIs;
33  import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
34  
35  import javax.swing.JComponent;
36  import javax.swing.SwingUtilities;
37  import java.util.List;
38  
39  /**
40   * Controlleur du menu de l'onglet prelevements mesures.
41   */
42  public class RulesMenuUIHandler extends ReferentialMenuUIHandler<RulesMenuUIModel, RulesMenuUI> {
43  
44      /**
45       * {@inheritDoc}
46       */
47      @Override
48      public void beforeInit(final RulesMenuUI ui) {
49          super.beforeInit(ui);
50  
51          // create model and register to the JAXX context
52          final RulesMenuUIModel model = new RulesMenuUIModel();
53          ui.setContextValue(model);
54      }
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public void afterInit(final RulesMenuUI ui) {
61          initUI(ui);
62  
63          initComboBox();
64          initListeners();
65      }
66  
67      /**
68       * Initialisation des combobox
69       */
70      private void initComboBox() {
71  
72          initBeanFilterableComboBox(
73              getUI().getRuleListComboBox(),
74              getContext().getRuleListService().getRuleLists(),
75              null);
76  
77          initBeanFilterableComboBox(
78              getUI().getProgramComboBox(),
79              getContext().getProgramStrategyService().getManagedProgramsByUserAndStatus(
80                  SecurityContextHelper.getQuadrigeUserId(),
81                  StatusFilter.ACTIVE
82              ),
83              null
84          );
85  
86          ReefDbUIs.forceComponentSize(getUI().getRuleListComboBox());
87          ReefDbUIs.forceComponentSize(getUI().getProgramComboBox());
88      }
89  
90      /**
91       * <p>reloadComboBox.</p>
92       */
93      public void reloadComboBox() {
94          getModel().setLoading(true);
95          BeanFilterableComboBox<RuleListDTO> cb = getUI().getRuleListComboBox();
96          cb.setData(null);
97          List<RuleListDTO> ruleLists = getContext().getRuleListService().getRuleLists();
98          cb.setData(ruleLists);
99  
100         // clear selected item if not present in list (Mantis #50537)
101         if (cb.getSelectedItem() instanceof RuleListDTO && !ruleLists.contains(cb.getSelectedItem())) {
102             cb.setSelectedItem(null);
103         }
104 
105         getModel().setLoading(false);
106     }
107 
108     private void initListeners() {
109 
110         getModel().addPropertyChangeListener(RulesMenuUIModel.PROPERTY_RULE_LIST, evt -> {
111             if (getModel().isLoading()) return;
112             if (getModel().getRuleList() != null) {
113                 getModel().setProgram(null);
114                 SwingUtilities.invokeLater(() -> getUI().getSearchButton().getAction().actionPerformed(null));
115             }
116         });
117     }
118 
119     @Override
120     public void enableSearch(boolean enabled) {
121     }
122 
123     @Override
124     public List<FilterDTO> getFilters() {
125         return null;
126     }
127 
128     @Override
129     public ApplyFilterUI getApplyFilterUI() {
130         return null;
131     }
132 
133     @Override
134     public JComponent getLocalFilterPanel() {
135         return null;
136     }
137 
138 }