Project

General

Profile

« Previous | Next » 

Revision 6b3711bc

Added by Patrick Plitzner about 6 years ago

ref #7095 Overhauled categorical data cell editor

  • encapsulated data fetching and storing in RowWrapper
  • simplified data accesion by caching States in RowWrapper

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenColumnPropertyAccessor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Set;
15

  
16 11
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
17 12

  
18
import eu.etaxonomy.cdm.model.description.CategoricalData;
19
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
20 13
import eu.etaxonomy.cdm.model.description.Feature;
21
import eu.etaxonomy.cdm.model.description.State;
22
import eu.etaxonomy.cdm.model.description.StateData;
23 14

  
24 15
/**
25 16
 * @author pplitzner
......
56 47
                break;
57 48
            }
58 49
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
59
            return rowWrapper.getDescriptionElementForFeature(feature);
50
            return rowWrapper.getDataValueForFeature(feature);
60 51
        } else if (columnIndex == 0) {
61 52
            return rowObject;
62 53
        }
......
71 62
        if(rowObject instanceof RowWrapper){
72 63
            RowWrapper rowWrapper = (RowWrapper)rowObject;
73 64
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
74
            Set<DescriptionElementBase> elements = rowWrapper.getSpecimenDescription().getElements();
75
            for (DescriptionElementBase descriptionElementBase : elements) {
76
                if(descriptionElementBase.getFeature().equals(feature)){
77
                    setDescriptionElement(descriptionElementBase, feature, newValue);
78
                    return;
79
                }
80
            }
81
        }
82
    }
83

  
84

  
85
    private void setDescriptionElement(DescriptionElementBase descriptionElementBase, Feature feature, Object newValue) {
86
        //FIXME move this to cdmlib service layer
87
        if(feature.isSupportsCategoricalData() && descriptionElementBase instanceof CategoricalData && newValue instanceof Collection){
88
            CategoricalData categoricalData = (CategoricalData)descriptionElementBase;
89
            List<StateData> stateData = new ArrayList<>(categoricalData.getStateData());
90
            for (StateData stateData2 : stateData) {
91
                categoricalData.removeStateData(stateData2);
92
            }
93
            Collection<State> states = (Collection<State>) newValue;
94
            for (State state : states) {
95
                categoricalData.addStateData(state);
96
            }
65
            rowWrapper.setDataValueForFeature(feature, newValue);
97 66
        }
98 67
    }
99 68

  

Also available in: Unified diff