import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataCellEditor;
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.categorical.CategoricalDataDisplayConverter;
-import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataCellEditor;
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataDialogEditor;
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataEditModeDisplayConverter;
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative.QuantitativeDataNormalModeDisplayConverter;
DisplayMode.NORMAL,
CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
- /**
- * exact value editor
- */
//Open cell editor in dialog
configRegistry.registerConfigAttribute(
EditConfigAttributes.OPEN_IN_DIALOG,
Boolean.TRUE,
DisplayMode.EDIT,
- CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+ CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
//register quantitative editor
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITOR,
new QuantitativeDataDialogEditor(matrix),
DisplayMode.EDIT,
- CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+ CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
// configure custom dialog settings
Map<String, Object> editDialogSettings = new HashMap<>();
editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Quantitative Data");
Point size = new Point(250, 300);
editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);
- // add custum message
//FIXME: this is not displayed because the cell editor
//is already a dialog. Maybe the cell editor and the
//dialog can be merged
EditConfigAttributes.EDIT_DIALOG_SETTINGS,
editDialogSettings,
DisplayMode.EDIT,
- CharacterMatrixConfigLabelAccumulator.QUANT_EXACT);
+ CharacterMatrixConfigLabelAccumulator.QUANTITATIVE);
//TODO: this for loop can maybe be avoided
}
private void registerColumnConfiguration(Feature feature, IConfigRegistry configRegistry) {
- if(feature.isSupportsQuantitativeData()){
- /**
- * aggregated value editor
- */
- configRegistry.registerConfigAttribute(
- EditConfigAttributes.CELL_EDITOR,
- new QuantitativeDataCellEditor(feature, matrix),
- DisplayMode.EDIT,
- CharacterMatrixConfigLabelAccumulator.QUANT_AGGREGATED);
- }
- else if(feature.isSupportsCategoricalData()){
+ if(feature.isSupportsCategoricalData()){
//add combo box cell editor
//register editor
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
MatrixUtility.getProperty(feature));
}
-
}
}
public class CharacterMatrixConfigLabelAccumulator implements IConfigLabelAccumulator {
public static final String QUANTITATIVE = "QUANTITATIVE";
- public static final String QUANT_AGGREGATED = QUANTITATIVE+"_AGGREGATED";
- public static final String QUANT_EXACT = QUANTITATIVE+"_EXACT";
public static final String CATEGORICAL = "CATEGORICAL";
private CharacterMatrix matrix;
this.matrix = matrix;
}
-
@Override
public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
Object rowObject = matrix.getBodyDataProvider().getRowObject(rowPosition);
}
else if(feature.isSupportsQuantitativeData()){
configLabels.addLabel(QUANTITATIVE);
- configLabels.addLabel(matrix.isExactQuantitativeValue()?QUANT_EXACT:QUANT_AGGREGATED);
}
}
}
+++ /dev/null
-/**
-* Copyright (C) 2017 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.nebula.widgets.nattable.edit.editor.AbstractCellEditor;
-import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer.MoveDirectionEnum;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-
-import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
-import eu.etaxonomy.cdm.model.description.Feature;
-import eu.etaxonomy.cdm.model.description.QuantitativeData;
-import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
-import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrix;
-
-/**
- * Cell editor for QuantitativeData
- * @author pplitzner
- * @since Dec 7, 2017
- *
- */
-public class QuantitativeDataCellEditor extends AbstractCellEditor{
-
- private Control editorControl;
-
- private Feature feature;
-
- private Map<StatisticalMeasure, Text> measureToTextMap = new HashMap<>();
-
- private Object editorValue;
-
- private CharacterMatrix matrix;
-
- private boolean dirty = false;
-
- public QuantitativeDataCellEditor(Feature feature, CharacterMatrix matrix) {
- super();
- this.matrix = matrix;
- this.feature = feature;
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object getEditorValue() {
- return this.editorValue;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setEditorValue(Object value) {
- this.editorValue = value;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Control getEditorControl() {
- return editorControl;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Control createEditorControl(Composite parent) {
- Composite composite = new Composite(parent, SWT.NONE);
- composite.setLayout(new FillLayout(SWT.HORIZONTAL));
-
- for (StatisticalMeasure measure: feature.getRecommendedStatisticalMeasures()) {
- Composite measureComposite = new Composite(composite, SWT.NONE);
- GridLayout layout = new GridLayout(2, false);
- layout.horizontalSpacing = 0;
- layout.marginBottom = 0;
- layout.marginHeight = 0;
- layout.marginLeft = 0;
- layout.marginRight = 0;
- layout.marginTop = 0;
- layout.marginWidth = 0;
- layout.verticalSpacing = 0;
- measureComposite.setLayout(layout);
- Label label = new Label(measureComposite, SWT.NONE);
- GridData layoutData = new GridData(SWT.CENTER, SWT.TOP, false, false);
- label.setLayoutData(layoutData);
- label.setText(measure.getLabel().substring(0, 3));
-
- Text text = new Text(measureComposite, SWT.NONE);
- label.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, false, false));
-
- measureToTextMap.put(measure, text);
- }
- return composite;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean commit(MoveDirectionEnum direction, boolean closeAfterCommit, boolean skipValidation) {
- if(dirty){
- matrix.setDirty();
- dirty = false;
- }
- return super.commit(direction, closeAfterCommit, skipValidation);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control activateCell(Composite parent, Object originalCanonicalValue) {
- Object rowObject = matrix.getBodyDataProvider().getRowObject(this.getRowIndex());
- if(rowObject instanceof RowWrapperDTO){
- this.editorControl = createEditorControl(parent);
- if(originalCanonicalValue==null){
- originalCanonicalValue = ((RowWrapperDTO) rowObject).addQuantitativeData(feature);
- }
- this.setEditorValue(originalCanonicalValue);
-
- if(originalCanonicalValue instanceof QuantitativeData){
- QuantitativeData quantitativeData = (QuantitativeData)originalCanonicalValue;
- Set<StatisticalMeasure> statisticalValues = quantitativeData.getFeature().getRecommendedStatisticalMeasures();
- //Fill text controls with actual values and add modify listeners for editing
- for (StatisticalMeasure value : statisticalValues) {
- Text text = measureToTextMap.get(value);
- text.addModifyListener(e->{
- try {
- float parseFloat = Float.parseFloat(text.getText());
- quantitativeData.setSpecificStatisticalValue(parseFloat, null, value);
- dirty = true;
- } catch (NumberFormatException|NullPointerException ex) {
- // ignore exception for wrong number format
- }
- });
-
- Float specificStatisticalValue = quantitativeData.getSpecificStatisticalValue(value);
- if(specificStatisticalValue!=null){
- Listener[] listeners = text.getListeners(SWT.Modify);
- for (Listener listener : listeners) {
- text.removeListener(SWT.Modify, listener);
- }
- text.setText(Float.toString(specificStatisticalValue));
- for (Listener listener : listeners) {
- text.addListener(SWT.Modify, listener);
- }
- }
- }
- }
- }
- return this.editorControl;
- }
-
-}
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
import java.util.List;
-import java.util.stream.Collectors;
+import java.util.Map;
import org.eclipse.jface.window.Window;
import org.eclipse.nebula.widgets.nattable.config.IConfigRegistry;
return super.close();
}
- void updateQuantitativeData(QuantitativeData object){
- QuantitativeData quantitativeData = object;
- //get all non-exact values
- List<StatisticalMeasurementValue> values = quantitativeData.getStatisticalValues().stream()
- .filter(value->!value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
- .collect(Collectors.toList());
+ void updateQuantitativeData(QuantitativeData quantitativeData){
//clear values
quantitativeData.getStatisticalValues().clear();
- //add back all non-exact values
- values.forEach(value->quantitativeData.addStatisticalValue(value));
- //get exact values from text fields
- List<Text> textFields = composite.getTextFields();
- for (Text text : textFields) {
+ //add back all values from text fields
+ Map<StatisticalMeasure, List<Text>> textFields = composite.getTextFields();
+ textFields.forEach((measure, texts)->{
+ texts.forEach(text->{
String string = text.getText();
try {
float exactValue = Float.parseFloat(string);
- quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(StatisticalMeasure.EXACT_VALUE(), exactValue));
+ quantitativeData.addStatisticalValue(StatisticalMeasurementValue.NewInstance(measure, exactValue));
} catch (NumberFormatException e) {
}
- }
+ });
+ });
}
}
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.quantitative;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
*/
public class QuantitativeDataDialogComposite extends Composite {
- private List<Text> textFields = new ArrayList<>();
+ private Map<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
super(parent, style);
setLayout(new GridLayout(1, false));
-
ScrolledComposite scrolledComposite_1 = new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL);
scrolledComposite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
scrolledComposite_1.setExpandHorizontal(true);
gl_valuesComposite.marginHeight = 0;
valuesComposite.setLayout(gl_valuesComposite);
- //add empty text field
- Text emptyTextField = addValue(initialInput==null?null:initialInput.toString(), valuesComposite);
+ //add empty text field for exact value
+ Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString());
emptyTextField.setFocus();
emptyTextField.setSelection(emptyTextField.getText().length());
- //add exisiting values
+ //add existing exact values
editorValue.getStatisticalValues().stream()
- .filter(value->value.getType().equals(StatisticalMeasure.EXACT_VALUE()))
- .forEach(exact->addValue(Float.toString(exact.getValue()), valuesComposite));
-
+ .filter(measure->measure.getType().equals(StatisticalMeasure.EXACT_VALUE()))
+ .forEach(exact->addText(valuesComposite, exact.getType(), Float.toString(exact.getValue())));
+
+ //add aggregation values
+ editorValue.getFeature().getRecommendedStatisticalMeasures()
+ .stream()
+ .filter(sm->!sm.equals(StatisticalMeasure.EXACT_VALUE()))
+ .forEach(measure->{
+ Float specificStatisticalValue = editorValue.getSpecificStatisticalValue(measure);
+ addText(valuesComposite, measure, specificStatisticalValue!=null?Float.toString(specificStatisticalValue):null);
+ });
scrolledComposite_1.setContent(valuesComposite);
scrolledComposite_1.setMinSize(valuesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
- private Text addValue(String value, Composite valuesComposite) {
+ private Text addText(Composite valuesComposite, StatisticalMeasure type, String value){
Composite composite_2 = new Composite(valuesComposite, SWT.NONE);
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
- GridLayout gl_composite_2 = new GridLayout(2, false);
+ GridLayout gl_composite_2 = new GridLayout(4, false);
gl_composite_2.marginHeight = 0;
gl_composite_2.marginWidth = 0;
gl_composite_2.verticalSpacing = 0;
gl_composite_2.horizontalSpacing = 2;
composite_2.setLayout(gl_composite_2);
+ Label lblNewLabel = new Label(composite_2, SWT.NONE);
+ lblNewLabel.setText(type.getLabel().substring(0, 3));
+
Text text = new Text(composite_2, SWT.BORDER);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
if(value!=null){
text.setText(value);
}
- textFields.add(text);
+
+ List<Text> list = textFieldMap.get(type);
+ if(list==null){
+ list = new ArrayList<>();
+ }
+ textFieldMap.put(type, list);
+ list.add(text);
Button btnNewButton_2 = new Button(composite_2, SWT.NONE);
btnNewButton_2.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+ new Label(composite_2, SWT.NONE);
btnNewButton_2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
return text;
}
- public List<Text> getTextFields() {
- return textFields;
+ public Map<StatisticalMeasure, List<Text>> getTextFields() {
+ return textFieldMap;
}
}