View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.context.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.util.AbstractDaliUIHandler;
27  import fr.ifremer.dali.ui.swing.util.DaliUIs;
28  import jaxx.runtime.swing.editor.bean.BeanFilterableComboBox;
29  
30  import javax.swing.SwingUtilities;
31  
32  /**
33   * Controlleur du menu pour la gestion des lieux au niveau National
34   */
35  public class ManageContextsListMenuUIHandler extends AbstractDaliUIHandler<ManageContextsListMenuUIModel, ManageContextsListMenuUI> {
36  
37      /** {@inheritDoc} */
38      @Override
39      public void beforeInit(final ManageContextsListMenuUI ui) {
40          super.beforeInit(ui);
41  
42          // create model and register to the JAXX context
43          final ManageContextsListMenuUIModel model = new ManageContextsListMenuUIModel();
44          ui.setContextValue(model);
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public void afterInit(final ManageContextsListMenuUI ui) {
50          initUI(ui);
51  
52          // Initialize combobox
53          initComboBox();
54      }
55  
56      /**
57       * Initialize  combobox
58       */
59      private void initComboBox() {
60  
61          initBeanFilterableComboBox(
62                  getUI().getContextsLabelsCombo(),
63                  getContext().getContextService().getAllContexts(),
64                  null);
65  
66          DaliUIs.forceComponentSize(getUI().getContextsLabelsCombo());
67  
68          getUI().getContextsLabelsCombo().getComboBoxModel().addWillChangeSelectedItemListener(event -> {
69              if (getModel().isLoading()) return;
70              if (event.getNextSelectedItem() != null) SwingUtilities.invokeLater(() -> getUI().getSearchButton().getAction().actionPerformed(null));
71          });
72  
73      }
74  
75      /**
76       * <p>reloadComboBox.</p>
77       */
78      @SuppressWarnings("unchecked")
79      public void reloadComboBox() {
80          getModel().setLoading(true);
81          BeanFilterableComboBox cb = getUI().getContextsLabelsCombo();
82          cb.setData(null);
83          cb.setData(getContext().getContextService().getAllContexts());
84          getModel().setLoading(false);
85      }
86  }