import org.eclipse.nebula.widgets.nattable.data.IDataProvider;
import org.eclipse.nebula.widgets.nattable.data.ListDataProvider;
import org.eclipse.nebula.widgets.nattable.edit.EditConfigAttributes;
-import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommand;
import org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler;
import org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer;
MatrixUtility.getProperty(feature));
//add combo box cell editor
- CategoricalDataCellEditor comboBoxCellEditor = new CategoricalDataCellEditor(new IComboBoxDataProvider() {
-
- @Override
- public List<?> getValues(int columnIndex, int rowIndex) {
- Feature feature = indexToFeatureMap.get(columnIndex);
- return getSupportedStatesForCategoricalFeature(feature);
- }
- }, 10, this, feature);
//register editor
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
- comboBoxCellEditor,
+ new CategoricalDataCellEditor(getSupportedStatesForCategoricalFeature(feature), this, feature),
DisplayMode.EDIT,
MatrixUtility.getProperty(feature));
*/
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
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.description.State;
+import eu.etaxonomy.cdm.model.description.StateData;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
return country;
}
- public DescriptionElementBase getDescriptionElementForFeature(Feature feature){
- return featureToElementMap.get(feature);
+ public Object getDataValueForFeature(Feature feature){
+ DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
+ if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class)){
+ CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class);
+ return categoricalData.getStatesOnly();
+ }
+ return descriptionElementBase;
+ }
+
+ public void setDataValueForFeature(Feature feature, Object newValue){
+ DescriptionElementBase descriptionElementBase = featureToElementMap.get(feature);
+ //FIXME move this to cdmlib service layer
+ if(descriptionElementBase!=null && descriptionElementBase.isInstanceOf(CategoricalData.class) && newValue instanceof Collection){
+ CategoricalData categoricalData = HibernateProxyHelper.deproxy(descriptionElementBase, CategoricalData.class);
+ List<StateData> stateData = new ArrayList<>(categoricalData.getStateData());
+ for (StateData stateData2 : stateData) {
+ categoricalData.removeStateData(stateData2);
+ }
+ Collection<State> states = (Collection<State>) newValue;
+ for (State state : states) {
+ categoricalData.addStateData(state);
+ }
+ }
}
}
*/
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
-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.State;
-import eu.etaxonomy.cdm.model.description.StateData;
/**
* @author pplitzner
break;
}
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
- return rowWrapper.getDescriptionElementForFeature(feature);
+ return rowWrapper.getDataValueForFeature(feature);
} else if (columnIndex == 0) {
return rowObject;
}
if(rowObject instanceof RowWrapper){
RowWrapper rowWrapper = (RowWrapper)rowObject;
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
- Set<DescriptionElementBase> elements = rowWrapper.getSpecimenDescription().getElements();
- for (DescriptionElementBase descriptionElementBase : elements) {
- if(descriptionElementBase.getFeature().equals(feature)){
- setDescriptionElement(descriptionElementBase, feature, newValue);
- return;
- }
- }
- }
- }
-
-
- private void setDescriptionElement(DescriptionElementBase descriptionElementBase, Feature feature, Object newValue) {
- //FIXME move this to cdmlib service layer
- if(feature.isSupportsCategoricalData() && descriptionElementBase instanceof CategoricalData && newValue instanceof Collection){
- CategoricalData categoricalData = (CategoricalData)descriptionElementBase;
- List<StateData> stateData = new ArrayList<>(categoricalData.getStateData());
- for (StateData stateData2 : stateData) {
- categoricalData.removeStateData(stateData2);
- }
- Collection<State> states = (Collection<State>) newValue;
- for (State state : states) {
- categoricalData.addStateData(state);
- }
+ rowWrapper.setDataValueForFeature(feature, newValue);
}
}
import java.util.List;
-import org.eclipse.nebula.widgets.nattable.edit.editor.IComboBoxDataProvider;
-import org.eclipse.nebula.widgets.nattable.filterrow.combobox.FilterRowComboBoxCellEditor;
+import org.eclipse.nebula.widgets.nattable.edit.editor.ComboBoxCellEditor;
import org.eclipse.nebula.widgets.nattable.widget.NatCombo;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import eu.etaxonomy.cdm.model.description.CategoricalData;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.State;
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.CharacterMatrix;
* @since Dec 7, 2017
*
*/
-public class CategoricalDataCellEditor extends FilterRowComboBoxCellEditor{
+public class CategoricalDataCellEditor extends ComboBoxCellEditor{
private CharacterMatrix matrix;
private Feature feature;
- public CategoricalDataCellEditor(IComboBoxDataProvider dataProvider, int maxVisibleItems, CharacterMatrix matrix, Feature feature) {
- super(dataProvider, maxVisibleItems);
+ public CategoricalDataCellEditor(List<State> list, CharacterMatrix matrix, Feature feature) {
+ super(list, 10);
this.matrix = matrix;
this.feature = feature;
+ setUseCheckbox(true);
+ setMultiselect(true);
}
@Override
if(canonicalValue==null){
Object rowWrapper = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
if(rowWrapper instanceof RowWrapper){
- canonicalValue = ((RowWrapper) rowWrapper).addCategoricalData(feature);
+ ((RowWrapper) rowWrapper).addCategoricalData(feature);
}
}
- else if (canonicalValue instanceof CategoricalData) {
- CategoricalData data = (CategoricalData)canonicalValue;
- List<State> states = data.getStatesOnly();
- String[] result = new String[states.size()];
- for (int i = 0; i < states.size(); i++) {
- result[i] = (String) this.displayConverter.canonicalToDisplayValue(
- this.layerCell, this.configRegistry, states.get(i));
- }
- setEditorValue(result);
- }
+ super.setCanonicalValue(canonicalValue);
}
/**
@Override
protected Control activateCell(Composite parent, Object originalCanonicalValue) {
if(matrix.getBodyDataProvider().getRowObject(this.getRowIndex()) instanceof RowWrapper){
- Control editorControl = super.activateCell(parent, originalCanonicalValue);
- ((NatCombo)editorControl).addSelectionListener(new SelectionListener() {
+ NatCombo natCombo = (NatCombo) super.activateCell(parent, originalCanonicalValue);
+ natCombo.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
matrix.setDirty();
public void widgetDefaultSelected(SelectionEvent e) {
}
});
- return editorControl;
+ return natCombo;
}
return null;
}
*/
package eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical;
+import java.util.Collection;
+
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
import eu.etaxonomy.cdm.model.description.CategoricalData;
else if(canonicalValue instanceof State){
return ((State) canonicalValue).getLabel();
}
+ else if (canonicalValue instanceof Collection) {
+ // Collection.toString() will add [ and ] around
+ // the values in the Collection
+ // So by removing the leading and ending
+ // character, we remove the brackets
+ String result = canonicalValue.toString();
+ result = result.substring(1, result.length() - 1);
+ return result;
+ }
else if(canonicalValue!=null){
return canonicalValue.toString();
}