Search in sources :

Example 46 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class WebMethodHandler method pathVariable.

@SuppressWarnings("unchecked")
public static WebParameterHandler pathVariable(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
    final Class<?> parameterClass = parameter.getType();
    final DataType dataType = DataTypes.getDataType(parameterClass);
    final PathVariable pathVariable = (PathVariable) annotation;
    final String name = getName(parameter, pathVariable.value());
    return // 
    WebParameterHandler.function(// 
    name, (request, response) -> {
        final Map<String, String> uriTemplateVariables = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
        if (uriTemplateVariables == null) {
            return null;
        } else {
            return uriTemplateVariables.get(name);
        }
    }, // 
    dataType, // 
    true, // 
    null);
}
Also used : DataType(com.revolsys.datatype.DataType) Map(java.util.Map) HashMap(java.util.HashMap) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) PathVariable(org.springframework.web.bind.annotation.PathVariable)

Example 47 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class WebMethodHandler method requestAttribute.

public static WebParameterHandler requestAttribute(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
    final Class<?> parameterClass = parameter.getType();
    final DataType dataType = DataTypes.getDataType(parameterClass);
    final RequestAttribute requestAttribute = (RequestAttribute) annotation;
    final String name = getName(parameter, requestAttribute.value());
    final boolean required = requestAttribute.required();
    final Object defaultValue = parseDefaultValueAttribute(dataType, requestAttribute.defaultValue());
    return // 
    WebParameterHandler.function(// 
    name, (request, response) -> {
        return request.getAttribute(name);
    }, // 
    dataType, // 
    required, // 
    defaultValue);
}
Also used : RequestAttribute(com.revolsys.ui.web.annotation.RequestAttribute) DataType(com.revolsys.datatype.DataType)

Example 48 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class EditRecordGeometryOverlay method getVertexGeometry.

protected Geometry getVertexGeometry(final MouseEvent event, final CloseLocation location) {
    final Geometry geometry = location.getGeometry();
    final DataType geometryDataType = DataTypes.getDataType(geometry);
    final DataType geometryPartDataType = getGeometryPartDataType(geometryDataType);
    int previousPointOffset;
    int[] vertexId = location.getVertexId();
    if (vertexId == null) {
        previousPointOffset = 0;
        vertexId = location.getSegmentId();
    } else {
        previousPointOffset = -1;
    }
    final GeometryFactory geometryFactory = location.getGeometryFactory();
    if (DataTypes.GEOMETRY.equals(geometryPartDataType)) {
    } else if (DataTypes.POINT.equals(geometryPartDataType)) {
    } else {
        final Point point = getPoint(geometryFactory, event);
        final Vertex vertex = geometry.getVertex(vertexId);
        Point previousPoint = null;
        Point nextPoint = null;
        if (DataTypes.LINE_STRING.equals(geometryPartDataType) || DataTypes.POLYGON.equals(geometryPartDataType)) {
            if (previousPointOffset == 0) {
                previousPoint = vertex;
            } else {
                previousPoint = vertex.getLinePrevious();
            }
            nextPoint = vertex.getLineNext();
        }
        final List<LineString> lines = new ArrayList<>();
        if (previousPoint != null && !previousPoint.isEmpty()) {
            lines.add(newXorLine(geometryFactory, previousPoint, point));
        }
        if (nextPoint != null && !nextPoint.isEmpty()) {
            lines.add(newXorLine(geometryFactory, nextPoint, point));
        }
        if (!lines.isEmpty()) {
            return geometryFactory.lineal(lines);
        }
    }
    return null;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) Vertex(com.revolsys.geometry.model.vertex.Vertex) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) GeometryDataType(com.revolsys.geometry.model.GeometryDataType) DataType(com.revolsys.datatype.DataType) List(java.util.List) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 49 with DataType

use of com.revolsys.datatype.DataType 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 50 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class RecordListTableModel method isCellEditable.

@Override
public boolean isCellEditable(final int rowIndex, final int columnIndex) {
    if (isEditable()) {
        final String fieldName = getColumnFieldName(rowIndex, columnIndex);
        if (isReadOnly(fieldName)) {
            return false;
        } else {
            final RecordDefinition recordDefinition = getRecordDefinition();
            final DataType dataType = recordDefinition.getFieldType(fieldName);
            if (dataType == null) {
                return false;
            } else if (Geometry.class.isAssignableFrom(dataType.getJavaClass())) {
                return false;
            } else {
                return true;
            }
        }
    } else {
        return false;
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) DataType(com.revolsys.datatype.DataType) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3