Search in sources :

Example 6 with Pair

use of com.revolsys.util.Pair in project com.revolsys.open by revolsys.

the class Form method setFieldValues.

public void setFieldValues(final Map<String, ? extends Object> values) {
    if (Property.hasValue(values)) {
        Invoke.later(() -> {
            final Map<String, Object> newValues = new HashMap<>();
            final Map<String, Pair<Object, Throwable>> fieldValueErrors = new HashMap<>();
            try (BaseCloseable settingFieldValue = this.settingFieldValue.closeable(true)) {
                for (final Entry<String, ? extends Object> entry : values.entrySet()) {
                    final String fieldName = entry.getKey();
                    Object fieldValue = entry.getValue();
                    final Field field = getField(fieldName);
                    if (field != null) {
                        try {
                            final boolean valueSet = field.setFieldValue(fieldValue);
                            fieldValue = field.getFieldValue();
                            if (!DataType.equal(this.fieldValueByName.put(fieldName, fieldValue), fieldValue) || valueSet) {
                                newValues.put(fieldName, fieldValue);
                            }
                        } catch (final Throwable e) {
                            fieldValueErrors.put(fieldName, new Pair<>(fieldValue, e));
                        }
                    }
                }
            }
            for (final Entry<String, Object> entry : newValues.entrySet()) {
                final String fieldName = entry.getKey();
                final Object fieldValue = entry.getValue();
                fireFieldValueChanged(null, fieldName, fieldValue);
                fireFieldValueChanged(fieldName, fieldName, fieldValue);
            }
            if (!isSettingFieldValue()) {
                if (!fieldValueErrors.isEmpty()) {
                    postSetFieldValuesErrors(fieldValueErrors);
                }
                if (!newValues.isEmpty()) {
                    postSetFieldValues(newValues);
                }
            }
        });
    }
}
Also used : Field(com.revolsys.swing.field.Field) BaseCloseable(com.revolsys.io.BaseCloseable) HashMap(java.util.HashMap) Pair(com.revolsys.util.Pair)

Aggregations

Pair (com.revolsys.util.Pair)6 Segment (com.revolsys.geometry.model.segment.Segment)2 Vertex (com.revolsys.geometry.model.vertex.Vertex)2 MapEx (com.revolsys.collection.map.MapEx)1 LasPoint (com.revolsys.elevation.cloud.las.pointformat.LasPoint)1 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)1 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)1 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)1 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)1 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)1 LineStringSegment (com.revolsys.geometry.model.segment.LineStringSegment)1 AbstractVertex (com.revolsys.geometry.model.vertex.AbstractVertex)1 LineStringVertex (com.revolsys.geometry.model.vertex.LineStringVertex)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 Field (com.revolsys.swing.field.Field)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1