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;
}
}
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);
}
}
}
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;
}
}
}
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);
}
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);
}
}
Aggregations