Search in sources :

Example 46 with BaseCloseable

use of com.revolsys.io.BaseCloseable 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

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2