View Javadoc
1   package fr.ifremer.reefdb.ui.swing.content.manage.referential.department.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.dto.configuration.filter.FilterDTO;
27  import fr.ifremer.reefdb.service.StatusFilter;
28  import fr.ifremer.reefdb.ui.swing.content.manage.filter.element.menu.ApplyFilterUI;
29  import fr.ifremer.reefdb.ui.swing.content.manage.referential.menu.ReferentialMenuUIHandler;
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 javax.swing.*;
35  import java.util.List;
36  
37  /**
38   * Controlleur du menu pour la gestion des lieux au niveau National
39   */
40  public class DepartmentMenuUIHandler extends ReferentialMenuUIHandler<DepartmentMenuUIModel, DepartmentMenuUI> {
41  
42      /**
43       * Logger.
44       */
45      private static final Log LOG = LogFactory.getLog(DepartmentMenuUIHandler.class);
46      
47      /** {@inheritDoc} */
48      @Override
49      public void beforeInit(final DepartmentMenuUI ui) {
50          super.beforeInit(ui);
51          
52          // create model and register to the JAXX context
53          final DepartmentMenuUIModel model = new DepartmentMenuUIModel();
54          ui.setContextValue(model);
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public void afterInit(final DepartmentMenuUI ui) {
60          super.afterInit(ui);
61  
62          // listen to model changes on 'local' to adapt combo box content
63          getModel().addPropertyChangeListener(DepartmentMenuUIModel.PROPERTY_LOCAL, evt -> {
64              getUI().getStatusCombo().setData(getContext().getReferentialService().getStatus(getModel().getStatusFilter()));
65              getUI().getParentCombo().setData(getContext().getReferentialService().getDepartments(getModel().isLocal() ? StatusFilter.ALL : StatusFilter.NATIONAL));
66          });
67          
68          // Initialiser les combobox
69          initComboBox();
70  
71      }
72  
73      /** {@inheritDoc} */
74      @Override
75      public void enableSearch(boolean enabled) {
76          getUI().getLocalCombo().setEnabled(enabled);
77          getUI().getCodeEditor().setEnabled(enabled);
78          getUI().getNameEditor().setEnabled(enabled);
79          getUI().getParentCombo().setEnabled(enabled);
80          getUI().getStatusCombo().setEnabled(enabled);
81          getUI().getClearButton().setEnabled(enabled);
82          getUI().getSearchButton().setEnabled(enabled);
83          getApplyFilterUI().setEnabled(enabled);
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public List<FilterDTO> getFilters() {
89          return getContext().getContextService().getAllDepartmentFilters();
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public ApplyFilterUI getApplyFilterUI() {
95          return getUI().getApplyFilterUI();
96      }
97  
98      /** {@inheritDoc} */
99      @Override
100     public JComponent getLocalFilterPanel() {
101         return getUI().getLocalPanel();
102     }
103 
104     /**
105 	 * Initialisation des combobox
106 	 */
107 	private void initComboBox() {
108 		
109         // Combo local
110 		initBeanFilterableComboBox(
111 				getUI().getLocalCombo(), 
112 				getContext().getSystemService().getBooleanValues(),
113 				null);
114 		
115 		initBeanFilterableComboBox(
116 				getUI().getParentCombo(), 
117 				getContext().getReferentialService().getDepartments(StatusFilter.ALL),
118 				null);
119 		
120 		initBeanFilterableComboBox(getUI().getStatusCombo(), 
121 				getContext().getReferentialService().getStatus(getModel().getStatusFilter()),
122 				null);
123 		
124 				
125 		// Dimension forcee sur la combobox
126         ReefDbUIs.forceComponentSize(getUI().getLocalCombo());
127         ReefDbUIs.forceComponentSize(getUI().getParentCombo());
128         ReefDbUIs.forceComponentSize(getUI().getStatusCombo());
129         
130 	}
131 
132     /**
133      * <p>reloadComboBox.</p>
134      */
135     public void reloadComboBox() {
136         getUI().getParentCombo().setData(null);
137         getUI().getParentCombo().setData(getContext().getReferentialService().getDepartments(getModel().isLocal() ? StatusFilter.ALL : StatusFilter.NATIONAL));
138     }
139 
140 }