Search in sources :

Example 71 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method getPasteRecordGeometry.

protected Geometry getPasteRecordGeometry(final LayerRecord record, final boolean alert) {
    try {
        if (record == null) {
            return null;
        } else {
            final RecordDefinition recordDefinition = getRecordDefinition();
            final FieldDefinition geometryField = recordDefinition.getGeometryField();
            if (geometryField != null) {
                final MapPanel parentComponent = getMapPanel();
                Geometry geometry = null;
                DataType geometryDataType = null;
                Class<?> layerGeometryClass = null;
                final GeometryFactory geometryFactory = getGeometryFactory();
                geometryDataType = geometryField.getDataType();
                layerGeometryClass = geometryDataType.getJavaClass();
                RecordReader reader = ClipboardUtil.getContents(RecordReaderTransferable.DATA_OBJECT_READER_FLAVOR);
                if (reader == null) {
                    final String string = ClipboardUtil.getContents(DataFlavor.stringFlavor);
                    if (Property.hasValue(string)) {
                        try {
                            geometry = geometryFactory.geometry(string);
                            geometry = geometryFactory.geometry(layerGeometryClass, geometry);
                            if (geometry != null) {
                                return geometry;
                            }
                        } catch (final Throwable e) {
                        }
                        final Resource resource = new ByteArrayResource("t.csv", string);
                        reader = RecordReader.newRecordReader(resource);
                    } else {
                        return null;
                    }
                }
                if (reader != null) {
                    try {
                        for (final Record sourceRecord : reader) {
                            if (geometry == null) {
                                final Geometry sourceGeometry = sourceRecord.getGeometry();
                                if (sourceGeometry == null) {
                                    if (alert) {
                                        JOptionPane.showMessageDialog(parentComponent, "Clipboard does not contain a record with a geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                    }
                                    return null;
                                }
                                geometry = geometryFactory.geometry(layerGeometryClass, sourceGeometry);
                                if (geometry == null) {
                                    if (alert) {
                                        JOptionPane.showMessageDialog(parentComponent, "Clipboard should contain a record with a " + geometryDataType + " not a " + sourceGeometry.getGeometryType() + ".", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                    }
                                    return null;
                                }
                            } else {
                                if (alert) {
                                    JOptionPane.showMessageDialog(parentComponent, "Clipboard contains more than one record. Copy a single record.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                                }
                                return null;
                            }
                        }
                    } finally {
                        FileUtil.closeSilent(reader);
                    }
                    if (geometry == null) {
                        if (alert) {
                            JOptionPane.showMessageDialog(parentComponent, "Clipboard does not contain a record with a geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                        }
                    } else if (geometry.isEmpty()) {
                        if (alert) {
                            JOptionPane.showMessageDialog(parentComponent, "Clipboard contains an empty geometry.", "Paste Geometry", JOptionPane.ERROR_MESSAGE);
                        }
                        return null;
                    } else {
                        return geometry;
                    }
                }
            }
            return null;
        }
    } catch (final Throwable t) {
        return null;
    }
}
Also used : MapPanel(com.revolsys.swing.map.MapPanel) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordReader(com.revolsys.record.io.RecordReader) ListRecordReader(com.revolsys.record.io.ListRecordReader) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource) Resource(com.revolsys.spring.resource.Resource) LineString(com.revolsys.geometry.model.LineString) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource) RecordDefinition(com.revolsys.record.schema.RecordDefinition) Geometry(com.revolsys.geometry.model.Geometry) DataType(com.revolsys.datatype.DataType) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record)

Example 72 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class RecordValidationDialog method propertyChange.

@Override
public void propertyChange(final PropertyChangeEvent e) {
    final Object source = e.getSource();
    if (source instanceof LayerRecord) {
        final LayerRecord record = (LayerRecord) source;
        if (this.layer.isLayerRecord(record)) {
            final String fieldName = e.getPropertyName();
            final FieldDefinition fieldDefinition = record.getFieldDefinition(fieldName);
            validateField(record, fieldDefinition);
        }
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 73 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class AbstractRecordTableModel method toObjectValue.

public Object toObjectValue(final String fieldName, final Object displayValue) {
    if (!Property.hasValue(displayValue)) {
        return null;
    }
    final RecordDefinition recordDefinition = getRecordDefinition();
    final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
    if (codeTable == null) {
        final FieldDefinition field = recordDefinition.getField(fieldName);
        final Object recordValue = field.toFieldValue(displayValue);
        return recordValue;
    } else {
        if (displayValue instanceof Identifier) {
            final Identifier identifier = (Identifier) displayValue;
            return identifier;
        } else {
            final Object objectValue = codeTable.getIdentifier(displayValue);
            return objectValue;
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Identifier(com.revolsys.identifier.Identifier) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 74 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class RecordRowTableModel method setSortOrder.

// TODO initial sort order for session layers doesn't always work
public SortOrder setSortOrder(final String fieldName) {
    int index = 0;
    if (Property.hasValue(fieldName)) {
        index = this.fieldNames.indexOf(fieldName);
        if (index == -1) {
            index = 0;
        }
    }
    final FieldDefinition fieldDefinition = getColumnFieldDefinition(index);
    if (fieldDefinition != null) {
        final Class<?> fieldClass = fieldDefinition.getTypeClass();
        if (Geometry.class.isAssignableFrom(fieldClass)) {
            return SortOrder.ASCENDING;
        }
    }
    return setSortOrder(index + this.fieldsOffset, SortOrder.ASCENDING);
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Example 75 with FieldDefinition

use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.

the class RecordRowTableModel method getPrototypeValue.

@Override
public Object getPrototypeValue(final int columnIndex) {
    FieldDefinition fieldDefinition = getColumnFieldDefinition(columnIndex);
    if (fieldDefinition == null) {
        return null;
    } else {
        final CodeTable codeTable = fieldDefinition.getCodeTable();
        if (codeTable != null) {
            final FieldDefinition valueFieldDefinition = codeTable.getValueFieldDefinition();
            if (valueFieldDefinition != null) {
                fieldDefinition = valueFieldDefinition;
            } else {
                Object maxValue = "";
                int maxLength = 0;
                for (final Object value : codeTable.getValues()) {
                    if (value != null) {
                        final int length = DataTypes.toString(value).length();
                        if (length > maxLength) {
                            maxValue = value;
                            maxLength = length;
                        }
                    }
                }
                return maxValue;
            }
        }
        final DataType fieldType = fieldDefinition.getDataType();
        final Class<?> fieldClass = fieldDefinition.getTypeClass();
        final int fieldLength = fieldDefinition.getLength();
        if (DataTypes.BOOLEAN.equals(fieldType)) {
            return Byte.MIN_VALUE;
        } else if (DataTypes.BYTE.equals(fieldType)) {
            return Byte.MIN_VALUE;
        } else if (DataTypes.SHORT.equals(fieldType)) {
            return Short.MAX_VALUE;
        } else if (DataTypes.INT.equals(fieldType)) {
            return Integer.MAX_VALUE;
        } else if (DataTypes.LONG.equals(fieldType)) {
            return Long.MAX_VALUE;
        } else if (DataTypes.SQL_DATE.equals(fieldType)) {
            return Dates.getSqlDate("9999-12-31");
        } else if (DataTypes.DATE.equals(fieldType)) {
            return Dates.getDate("9999-12-29 23:59:59.999");
        } else if (DataTypes.DATE_TIME.equals(fieldType)) {
            return Dates.getTimestamp("9999-12-29 23:59:59.999");
        } else if (DataTypes.TIMESTAMP.equals(fieldType)) {
            return Dates.getTimestamp("9999-12-29 23:59:59.999");
        } else if (Geometry.class.isAssignableFrom(fieldClass)) {
            return fieldType.getName();
        } else {
            if (fieldLength < 1 || fieldLength > 30) {
                return "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            } else {
                final StringBuilder string = new StringBuilder();
                for (int i = 0; i < fieldLength; i++) {
                    string.append("X");
                }
                return string.toString();
            }
        }
    // if (Number.class.isAssignableFrom(fieldClass)) {
    // final StringBuilder numberString = new StringBuilder();
    // final Object maxValue = fieldDefinition.getMaxValue();
    // final Object minValue = fieldDefinition.getMinValue();
    // if (maxValue == null) {
    // for (int i = 0; i <= maxLength; i++) {
    // numberString.append("9");
    // }
    // return fieldType.toObject(numberString.toString());
    // } else {
    // if (minValue instanceof Number) {
    // numberString.append(((Number)minValue).longValue());
    // }
    // }
    // if (Float.class.isAssignableFrom(fieldClass) ||
    // Double.class.isAssignableFrom(fieldClass)
    // || BigDecimal.class.isAssignableFrom(fieldClass)) {
    // numberString.append('.');
    // final int fieldScale = fieldDefinition.getScale();
    // for (int i = 0; i <= fieldScale; i++) {
    // numberString.append("9");
    // }
    // final BigDecimal scaleValue = new BigDecimal(numberString.toString());
    // }
    // }
    // return super.getPrototypeValue(columnIndex);
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Geometry(com.revolsys.geometry.model.Geometry) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4