ref #8242 Set max items for dropdown to 10 + sort items
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / matrix / categorical / CategoricalDataCellEditor.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical;
10
11 import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
12 import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
13 import org.eclipse.swt.events.SelectionEvent;
14 import org.eclipse.swt.events.SelectionListener;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17
18 import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
19 import eu.etaxonomy.cdm.model.description.Feature;
20 import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
21
22 /**
23 * Cell editor for CategoricalData
24 * @author pplitzner
25 * @since Dec 7, 2017
26 *
27 */
28 public class CategoricalDataCellEditor extends ComboBoxCellEditor{
29
30 private CharacterMatrix matrix;
31
32 public CategoricalDataCellEditor(CharacterMatrix matrix, CategoricalComboBoxDataProvider categoricalComboBoxDataProvider) {
33 super(categoricalComboBoxDataProvider, 10);
34 this.matrix = matrix;
35 setUseCheckbox(true);
36 setMultiselect(true);
37 }
38
39 @Override
40 public void setCanonicalValue(Object canonicalValue) {
41 if(canonicalValue==null){
42 Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
43 if(rowWrapper instanceof RowWrapperDTO){
44 Feature feature = matrix.getIndexToCharacterMap().get(getColumnIndex());
45 ((RowWrapperDTO) rowWrapper).addCategoricalData(feature);
46 }
47 }
48 super.setCanonicalValue(canonicalValue);
49 }
50
51 @Override
52 protected Control activateCell(Composite parent, Object originalCanonicalValue) {
53 if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapperDTO){
54 NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
55 natCombo.addSelectionListener(new SelectionListener() {
56 @Override
57 public void widgetSelected(SelectionEvent e) {
58 matrix.setDirty();
59 }
60 @Override
61 public void widgetDefaultSelected(SelectionEvent e) {
62 }
63 });
64 return natCombo;
65 }
66 return null;
67 }
68
69 }