View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.parameter.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.decorator.DecoratorService;
27  import fr.ifremer.reefdb.dto.referential.pmfm.ParameterDTO;
28  import fr.ifremer.reefdb.service.StatusFilter;
29  import fr.ifremer.reefdb.ui.swing.util.AbstractReefDbUIHandler;
30  import fr.ifremer.reefdb.ui.swing.util.ReefDbUIs;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  import java.util.List;
35  
36  /**
37   * Controlleur du menu pour la gestion des Parameters au niveau local
38   */
39  public class ManageParametersMenuUIHandler extends AbstractReefDbUIHandler<ManageParametersMenuUIModel, ManageParametersMenuUI> {
40  
41      /**
42       * Logger.
43       */
44      private static final Log LOG = LogFactory.getLog(ManageParametersMenuUIHandler.class);
45  
46      /** {@inheritDoc} */
47      @Override
48      public void beforeInit(final ManageParametersMenuUI ui) {
49          super.beforeInit(ui);
50  
51          // create model and register to the JAXX context
52          final ManageParametersMenuUIModel model = new ManageParametersMenuUIModel();
53          ui.setContextValue(model);
54      }
55  
56      /** {@inheritDoc} */
57      @Override
58      public void afterInit(final ManageParametersMenuUI ui) {
59          initUI(ui);
60  
61          // listen to model changes on 'local' to adapt combo box content
62          getModel().addPropertyChangeListener(ManageParametersMenuUIModel.PROPERTY_LOCAL, evt -> {
63              getUI().getStatusCombo().setData(getContext().getReferentialService().getStatus(getModel().getStatusFilter()));
64              reloadComboBox();
65          });
66  
67  
68          // Initialiser les combobox
69          initComboBox();
70      }
71  
72  	/**
73  	 * Initialisation des combobox
74  	 */
75  	private void initComboBox() {
76  
77          List<ParameterDTO> parameters = getContext().getReferentialService().getParameters(getModel().getStatusFilter());
78  
79  		initBeanFilterableComboBox(
80  				getUI().getLabelCombo(),
81                  parameters,
82  				null,
83                  DecoratorService.NAME);
84  		
85  		initBeanFilterableComboBox(
86  				getUI().getCodeCombo(),
87                  parameters,
88  				null);
89  		
90  		initBeanFilterableComboBox(getUI().getStatusCombo(),
91  				getContext().getReferentialService().getStatus(getModel().getStatusFilter()),
92  				null);
93  		
94          initBeanFilterableComboBox(getUI().getParameterGroupCombo(), 
95  				getContext().getReferentialService().getParameterGroup(StatusFilter.ACTIVE),
96  				null);
97  
98          ReefDbUIs.forceComponentSize(getUI().getLabelCombo());
99          ReefDbUIs.forceComponentSize(getUI().getCodeCombo());
100         ReefDbUIs.forceComponentSize(getUI().getStatusCombo());
101         ReefDbUIs.forceComponentSize(getUI().getParameterGroupCombo());
102 	}
103 
104     /**
105      * <p>reloadComboBox.</p>
106      */
107     public void reloadComboBox() {
108         List<ParameterDTO> parameters = getContext().getReferentialService().getParameters(getModel().getStatusFilter());
109         getUI().getLabelCombo().setData(parameters);
110         getUI().getCodeCombo().setData(parameters);
111     }
112 }