View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.matrix.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.util.AbstractReefDbUIHandler;
27  import fr.ifremer.reefdb.ui.swing.util.ReefDbUIs;
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  /**
32   * Controlleur du menu pour la gestion des Matrices au niveau local
33   */
34  public class ManageMatricesMenuUIHandler extends AbstractReefDbUIHandler<ManageMatricesMenuUIModel, ManageMatricesMenuUI> {
35  
36      /**
37       * Logger.
38       */
39      private static final Log LOG = LogFactory.getLog(ManageMatricesMenuUIHandler.class);
40  
41      /** {@inheritDoc} */
42      @Override
43      public void beforeInit(final ManageMatricesMenuUI ui) {
44          super.beforeInit(ui);
45  
46          // create model and register to the JAXX context
47          final ManageMatricesMenuUIModel model = new ManageMatricesMenuUIModel();
48          ui.setContextValue(model);
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public void afterInit(final ManageMatricesMenuUI ui) {
54          initUI(ui);
55  
56          // listen to model changes on 'local' to adapt combo box content
57          getModel().addPropertyChangeListener(ManageMatricesMenuUIModel.PROPERTY_LOCAL, evt -> {
58              getUI().getStatusCombo().setData(getContext().getReferentialService().getStatus(getModel().getStatusFilter()));
59              reloadComboBox();
60          });
61  
62          // Initialiser les combobox
63          initComboBox();
64      }
65  
66  	/**
67  	 * Initialisation des combobox
68  	 */
69  	private void initComboBox() {
70  		initBeanFilterableComboBox(
71  				getUI().getLabelCombo(),
72  				getContext().getReferentialService().getMatrices(getModel().getStatusFilter()),
73  				null);
74  		
75  		initBeanFilterableComboBox(
76  				getUI().getStatusCombo(),
77  				getContext().getReferentialService().getStatus(getModel().getStatusFilter()),
78  				null);
79          ReefDbUIs.forceComponentSize(getUI().getLabelCombo());
80          ReefDbUIs.forceComponentSize(getUI().getStatusCombo());
81  	}
82  
83      /**
84       * <p>reloadComboBox.</p>
85       */
86      public void reloadComboBox() {
87  
88          getUI().getLabelCombo().setData(getContext().getReferentialService().getMatrices(getModel().getStatusFilter()));
89      }
90  }