View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.pmfm.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.configuration.filter.FilterDTO;
28  import fr.ifremer.reefdb.service.StatusFilter;
29  import fr.ifremer.reefdb.ui.swing.content.manage.filter.element.menu.ApplyFilterUI;
30  import fr.ifremer.reefdb.ui.swing.content.manage.referential.menu.ReferentialMenuUIHandler;
31  import fr.ifremer.reefdb.ui.swing.util.ReefDbUIs;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  import javax.swing.JComponent;
36  import java.util.List;
37  
38  /**
39   * Controlleur du menu pour la gestion des Quadruplets au niveau National
40   */
41  public class PmfmMenuUIHandler extends ReferentialMenuUIHandler<PmfmMenuUIModel, PmfmMenuUI> {
42  
43      /**
44       * Logger.
45       */
46      private static final Log LOG = LogFactory.getLog(PmfmMenuUIHandler.class);
47  
48      /** {@inheritDoc} */
49      @Override
50      public void beforeInit(final PmfmMenuUI ui) {
51          super.beforeInit(ui);
52  
53          // create model and register to the JAXX context
54          final PmfmMenuUIModel model = new PmfmMenuUIModel();
55          ui.setContextValue(model);
56      }
57  
58      /** {@inheritDoc} */
59      @Override
60      public void afterInit(final PmfmMenuUI ui) {
61          super.afterInit(ui);
62  
63          // listen to model changes on 'local' to adapt combo box content
64          getModel().addPropertyChangeListener(PmfmMenuUIModel.PROPERTY_LOCAL, evt -> {
65              getUI().getStatusCombo().setData(getContext().getReferentialService().getStatus(getModel().getStatusFilter()));
66              // reload these referential with correct status filter (Mantis #48500)
67              StatusFilter referentialStatusFilter = getModel().isLocal() ? StatusFilter.ALL : StatusFilter.NATIONAL;
68              getUI().getParametersCombo().setData(getContext().getReferentialService().getParameters(referentialStatusFilter));
69              getUI().getMatricesCombo().setData(getContext().getReferentialService().getMatrices(referentialStatusFilter));
70              getUI().getFractionsCombo().setData(getContext().getReferentialService().getFractions(referentialStatusFilter));
71              getUI().getMethodsCombo().setData(getContext().getReferentialService().getMethods(referentialStatusFilter));
72              getUI().getUnitsCombo().setData(getContext().getReferentialService().getUnits(referentialStatusFilter));
73          });
74  
75          // Initialiser les combobox
76          initComboBox();
77      }
78  
79      /** {@inheritDoc} */
80      @Override
81      public void enableSearch(boolean enabled) {
82          getUI().getLocalCombo().setEnabled(enabled);
83          getUI().getNameEditor().setEnabled(enabled);
84          getUI().getParametersCombo().setEnabled(enabled);
85          getUI().getMatricesCombo().setEnabled(enabled);
86          getUI().getFractionsCombo().setEnabled(enabled);
87          getUI().getMethodsCombo().setEnabled(enabled);
88          getUI().getUnitsCombo().setEnabled(enabled);
89          getUI().getStatusCombo().setEnabled(enabled);
90          getUI().getClearButton().setEnabled(enabled);
91          getUI().getSearchButton().setEnabled(enabled);
92          getApplyFilterUI().setEnabled(enabled);
93      }
94  
95      /** {@inheritDoc} */
96      @Override
97      public List<FilterDTO> getFilters() {
98          return getContext().getContextService().getAllPmfmFilters();
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public ApplyFilterUI getApplyFilterUI() {
104         return getUI().getApplyFilterUI();
105     }
106 
107     /** {@inheritDoc} */
108     @Override
109     public JComponent getLocalFilterPanel() {
110         return getUI().getLocalPanel();
111     }
112 
113     /**
114      * Initialisation des combobox
115      */
116     private void initComboBox() {
117 
118         // Combo local
119         initBeanFilterableComboBox(
120                 getUI().getLocalCombo(),
121                 getContext().getSystemService().getBooleanValues(),
122                 null);
123 
124         initBeanFilterableComboBox(
125                 getUI().getParametersCombo(),
126                 getContext().getReferentialService().getParameters(getModel().getStatusFilter()),
127                 null,
128                 DecoratorService.CODE_NAME);
129 
130         initBeanFilterableComboBox(
131                 getUI().getMatricesCombo(),
132                 getContext().getReferentialService().getMatrices(getModel().getStatusFilter()),
133                 null);
134 
135         initBeanFilterableComboBox(
136                 getUI().getFractionsCombo(),
137                 getContext().getReferentialService().getFractions(getModel().getStatusFilter()),
138                 null);
139 
140         initBeanFilterableComboBox(
141                 getUI().getMethodsCombo(),
142                 getContext().getReferentialService().getMethods(getModel().getStatusFilter()),
143                 null);
144 
145         initBeanFilterableComboBox(
146                 getUI().getUnitsCombo(),
147                 getContext().getReferentialService().getUnits(getModel().getStatusFilter()),
148                 null,
149                 DecoratorService.WITH_SYMBOL);
150 
151         initBeanFilterableComboBox(getUI().getStatusCombo(),
152                 getContext().getReferentialService().getStatus(getModel().getStatusFilter()),
153                 null);
154 
155         ReefDbUIs.forceComponentSize(getUI().getNameEditor());
156         ReefDbUIs.forceComponentSize(getUI().getLocalCombo());
157         ReefDbUIs.forceComponentSize(getUI().getParametersCombo());
158         ReefDbUIs.forceComponentSize(getUI().getMatricesCombo());
159         ReefDbUIs.forceComponentSize(getUI().getFractionsCombo());
160         ReefDbUIs.forceComponentSize(getUI().getMethodsCombo());
161         ReefDbUIs.forceComponentSize(getUI().getUnitsCombo());
162         ReefDbUIs.forceComponentSize(getUI().getStatusCombo());
163     }
164 
165     private void reloadComboBox() {
166 
167     }
168 
169 }