View Javadoc
1   package fr.ifremer.dali.ui.swing.content.manage.context.filterslist;
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 com.google.common.collect.Lists;
27  import fr.ifremer.dali.dto.configuration.filter.FilterDTO;
28  import fr.ifremer.dali.service.administration.context.ContextService;
29  import fr.ifremer.quadrige3.core.dao.technical.decorator.Decorator;
30  import fr.ifremer.quadrige3.ui.swing.component.bean.ExtendedComboBox;
31  import fr.ifremer.quadrige3.ui.swing.table.editor.FilterableComboBoxCellEditor;
32  
33  import javax.swing.JTable;
34  import java.awt.Component;
35  import java.util.ArrayList;
36  import java.util.List;
37  
38  /**
39   * <p>FilterComboCellEditor class.</p>
40   *
41   */
42  public class FilterComboCellEditor extends FilterableComboBoxCellEditor<FilterDTO> {
43  
44  	private final ManageFiltersListTableUIModel uiModel;
45  	private final ContextService service;
46  
47  	/**
48  	 * <p>Constructor for FilterComboCellEditor.</p>
49  	 *
50  	 * @param uiModel a {@link fr.ifremer.dali.ui.swing.content.manage.context.filterslist.ManageFiltersListTableUIModel} object.
51  	 * @param comboBox a {@link fr.ifremer.quadrige3.ui.swing.component.bean.ExtendedComboBox} object.
52  	 * @param decorator a {@link Decorator} object.
53  	 * @param service a {@link fr.ifremer.dali.service.administration.context.ContextService} object.
54  	 */
55  	public FilterComboCellEditor(ManageFiltersListTableUIModel uiModel, ExtendedComboBox<FilterDTO> comboBox,
56  								 Decorator<FilterDTO> decorator, ContextService service) {
57  		super(comboBox);
58          // Init combo
59          getCombo().init(decorator, new ArrayList<>());
60          
61          this.uiModel = uiModel;
62          this.service = service;
63  	}
64  
65  	/** {@inheritDoc} */
66  	@Override
67  	public Component getTableCellEditorComponent(
68  			final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
69  		
70  		// Selected ControlElementDTO
71  		final Integer filterTypeId = this.uiModel.getSingleSelectedRow().getFilterTypeId();
72  		if (filterTypeId == null) {
73  			
74  			// Empty list
75  	        getCombo().setData(new ArrayList<>());
76  		} else {
77  			
78  			// New ComboBox data
79  			final List<FilterDTO> data = service.getFiltersByType(filterTypeId);
80  	        getCombo().setData(Lists.newArrayList(data));
81  		}
82  		
83  		// Call super method 
84  		return super.getTableCellEditorComponent(table, value, isSelected, row, column);
85  	}
86  }