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