import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.description.MeasurementUnit;
import eu.etaxonomy.cdm.model.description.QuantitativeData;
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
import eu.etaxonomy.taxeditor.model.ImageResources;
public class QuantitativeDataDialogComposite extends Composite {
private Map<StatisticalMeasure, List<Text>> textFieldMap = new HashMap<>();
+ QuantitativeData editorValue;
+ Combo unitCombo;
+ Map<MeasurementUnit, Integer> unitMap = null;
- public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorValue, Composite parent, int style) {
+ public QuantitativeDataDialogComposite(Character initialInput, QuantitativeData editorVal, Composite parent, int style) {
super(parent, style);
+ this.editorValue = editorVal;
+ if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size()>0){
+ unitMap = new HashMap<>();
+ Integer i = 0;
+ for (MeasurementUnit unit: editorValue.getFeature().getRecommendedMeasurementUnits()){
+ unitMap.put(unit, i);
+ i++;
+ }
+ }
+
setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
setLayout(new GridLayout(1, false));
gl_valuesComposite.marginHeight = 0;
valuesComposite.setLayout(gl_valuesComposite);
+ 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);
+ 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("Measurement Unit");
+ lblNewLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() == 1){
+ Label lblUnit = new Label(composite_2, SWT.BORDER);
+ lblUnit.setText(editorValue.getFeature().getRecommendedMeasurementUnits().iterator().next().getLabel());
+ lblUnit.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ }else if (editorValue.getFeature().getRecommendedMeasurementUnits() != null && editorValue.getFeature().getRecommendedMeasurementUnits().size() > 1){
+ unitCombo = new Combo(composite_2, SWT.NONE | SWT.READ_ONLY);
+ unitCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+ for (Entry<MeasurementUnit, Integer> unit: unitMap.entrySet()){
+ unitCombo.add(unit.getKey().getTitleCache(), unit.getValue());
+ unitCombo.setData(unit.getKey().getTitleCache(), unit.getKey());
+ }
+ if (editorValue.getUnit()!= null){
+ unitCombo.select(unitMap.get(editorValue.getUnit()));
+ }
+
+ unitCombo.addSelectionListener(new SelectionAdapter(){
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String name = unitCombo.getText();
+ editorValue.setUnit((MeasurementUnit)unitCombo.getData(name));
+ }
+
+ });
+ }
+
//add empty text field for exact value
Text emptyTextField = addText(valuesComposite, StatisticalMeasure.EXACT_VALUE(), initialInput==null?null:initialInput.toString());
emptyTextField.setFocus();
lblNewLabel.setText(type.getLabel());
Text text = new Text(composite_2, SWT.BORDER);
- text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
+
+ GridData gd_text = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ gd_text.widthHint = 15;
+ text.setLayoutData(gd_text);
if(value!=null){
text.setText(value);
}
return textFieldMap;
}
+ public QuantitativeData getEditorValue() {
+ return editorValue;
+ }
+
}