import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.DescriptionBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Feature;
private Map<Integer, Feature> indexToFeatureMap = new HashMap<>();
+ private Map<Feature, List<State>> categoricalFeatureToStateMap = new HashMap<>();
+
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
private Properties natTableState;
FeatureTree tree = workingSet.getDescriptiveSystem();
features = new ArrayList<>(tree.getDistinctFeatures());
Collections.sort(features);
+ //init state data for categorical features
+ features.forEach(feature->
+ {
+ if(feature.isSupportsCategoricalData()){
+ List<State> supportedStates = new ArrayList<>();
+ feature.getSupportedCategoricalEnumerations().forEach(voc->supportedStates.addAll(voc.getTerms()));
+ categoricalFeatureToStateMap.put(feature, supportedStates);
+ }
+ });
descriptions = GlazedLists.eventList(getDescriptions(workingSet));
}
@Override
public List<?> getValues(int columnIndex, int rowIndex) {
- List<State> states = new ArrayList<>();
Feature feature = indexToFeatureMap.get(columnIndex);
- if(feature.isSupportsCategoricalData()){
- Set<TermVocabulary<State>> stateVocs = feature.getSupportedCategoricalEnumerations();
- for (TermVocabulary<State> voc : stateVocs) {
- states.addAll(voc.getTerms());
- }
- }
- return states;
+ return getSupportedStatesForCategoricalFeature(feature);
}
- }, 5, this, feature);
+ }, 10, this, feature);
//register editor
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
comboBoxCellEditor,
return rowWrappers;
}
+ public List<State> getSupportedStatesForCategoricalFeature(Feature feature){
+ return categoricalFeatureToStateMap.get(feature);
+ }
+
public Map<Integer, Feature> getIndexToFeatureMap() {
return indexToFeatureMap;
}
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
private FieldUnit fieldUnit;
private String identifier;
private NamedArea country;
+ private Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
public RowWrapper(SpecimenDescription description) {
this.description = description;
IOccurrenceService occurrenceService = CdmStore.getService(IOccurrenceService.class);
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(description.getDescribedSpecimenOrObservation(), SpecimenOrObservationBase.class);
+ //supplemental information
if(specimen!=null){
Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null, null);
if(associatedTaxa!=null){
country = fieldUnit.getGatheringEvent().getCountry();
}
}
+ //description elements
+ Set<DescriptionElementBase> elements = description.getElements();
+ for (DescriptionElementBase descriptionElementBase : elements) {
+ Feature feature = descriptionElementBase.getFeature();
+ featureToElementMap.put(feature, descriptionElementBase);
+ }
+ }
+
+ public QuantitativeData addQuantitativeData(Feature feature){
+ QuantitativeData data = QuantitativeData.NewInstance(feature);
+ description.addElement(data);
+ featureToElementMap.put(feature, data);
+ return data;
+ }
+
+ public CategoricalData addCategoricalData(Feature feature){
+ CategoricalData data = CategoricalData.NewInstance(feature);
+ description.addElement(data);
+ featureToElementMap.put(feature, data);
+ return data;
}
public SpecimenDescription getSpecimenDescription() {
return country;
}
+ public DescriptionElementBase getDescriptionElementForFeature(Feature feature){
+ return featureToElementMap.get(feature);
+ }
+
}
break;
}
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
- Set<DescriptionElementBase> elements = rowWrapper.getSpecimenDescription().getElements();
- for (DescriptionElementBase descriptionElementBase : elements) {
- if(descriptionElementBase.getFeature().equals(feature)){
- return descriptionElementBase;
- }
- }
+ return rowWrapper.getDescriptionElementForFeature(feature);
} else if (columnIndex == 0) {
return rowObject;
}
if(canonicalValue==null){
Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
if(rowWrapper instanceof RowWrapper){
- CategoricalData data = CategoricalData.NewInstance(feature);
- ((RowWrapper) rowWrapper).getSpecimenDescription().addElement(data);
- canonicalValue = data;
+ canonicalValue = ((RowWrapper) rowWrapper).addCategoricalData(feature);
}
}
- if (canonicalValue instanceof CategoricalData) {
+ else if (canonicalValue instanceof CategoricalData) {
CategoricalData data = (CategoricalData)canonicalValue;
List<State> states = data.getStatesOnly();
String[] result = new String[states.size()];
if(rowObject instanceof RowWrapper){
this.editorControl = createEditorControl(parent);
if(originalCanonicalValue==null){
- QuantitativeData data = QuantitativeData.NewInstance(feature);
- ((RowWrapper) rowObject).getSpecimenDescription().addElement(data);
- originalCanonicalValue = data;
+ originalCanonicalValue = ((RowWrapper) rowObject).addQuantitativeData(feature);
}
this.setEditorValue(originalCanonicalValue);