Search in sources :

Example 41 with DataType

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

the class LayerRecordForm method addDoubleField.

protected void addDoubleField(final String fieldName, final int length, final int scale, final Double minimumValie, final Double maximumValue) {
    final DataType dataType = DataTypes.DOUBLE;
    final NumberTextField field = new NumberTextField(fieldName, dataType, length, scale, minimumValie, maximumValue);
    addField(fieldName, field);
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) DataType(com.revolsys.datatype.DataType)

Example 42 with DataType

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

the class LayerRecordForm method addToolBar.

protected ToolBar addToolBar(final AbstractRecordLayer layer) {
    this.toolBar = new ToolBar();
    add(this.toolBar, BorderLayout.NORTH);
    final RecordDefinition recordDefinition = getRecordDefinition();
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    final boolean hasGeometry = geometryField != null;
    final EnableCheck editable = new ObjectPropertyEnableCheck(this, "editable");
    if (layer != null) {
        final MenuFactory menuFactory = MenuFactory.findMenu(layer);
        if (menuFactory != null) {
            this.toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> menuFactory.showMenu(layer, this, 10, 10));
        }
    }
    final EnableCheck deletableEnableCheck = editable.and(new ObjectPropertyEnableCheck(this, "deletable"));
    this.toolBar.addButton("record", "Delete Record", "table_row_delete", deletableEnableCheck, this::deleteRecord);
    // Cut, Copy Paste
    this.toolBar.addButton("dnd", "Copy Record", "page_copy", (EnableCheck) null, this::dataTransferCopy);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Copy Geometry", "geometry_copy", (EnableCheck) null, this::copyGeometry);
    }
    this.toolBar.addButton("dnd", "Paste Record", "paste_plain", editable, this::dataTransferPaste);
    if (hasGeometry) {
        this.toolBar.addButton("dnd", "Paste Geometry", "geometry_paste", editable, this::pasteGeometry);
    }
    final EnableCheck canUndo = new ObjectPropertyEnableCheck(this.undoManager, "canUndo");
    final EnableCheck canRedo = new ObjectPropertyEnableCheck(this.undoManager, "canRedo");
    final EnableCheck modifiedOrDeleted = new ObjectPropertyEnableCheck(this, "modifiedOrDeleted");
    this.toolBar.addButton("changes", "Revert Record", "arrow_revert", modifiedOrDeleted, this::revertChanges);
    this.toolBar.addButton("changes", "Revert Empty Fields", "field_empty_revert", new ObjectPropertyEnableCheck(this, "hasModifiedEmptyFields"), this::revertEmptyFields);
    this.toolBar.addButton("changes", "Undo", "arrow_undo", canUndo, this.undoManager::undo);
    this.toolBar.addButton("changes", "Redo", "arrow_redo", canRedo, this.undoManager::redo);
    if (hasGeometry) {
        this.toolBar.addButtonTitleIcon("zoom", "Zoom to Record", "magnifier_zoom_selected", () -> {
            final LayerRecord record = getRecord();
            layer.zoomToRecord(record);
        });
        this.toolBar.addButtonTitleIcon("zoom", "Pan to Record", "pan_selected", () -> {
            final LayerRecord record = getRecord();
            final MapPanel mapPanel = layer.getMapPanel();
            if (mapPanel != null) {
                mapPanel.panToRecord(record);
            }
        });
    }
    // Geometry manipulation
    if (hasGeometry) {
        final DataType geometryDataType = geometryField.getDataType();
        if (geometryDataType == DataTypes.LINE_STRING || geometryDataType == DataTypes.MULTI_LINE_STRING) {
            if (DirectionalFields.getProperty(recordDefinition).hasDirectionalFields()) {
                this.toolBar.addButton("geometry", FLIP_RECORD_NAME, FLIP_RECORD_ICON, editable, this::flipRecordOrientation);
                this.toolBar.addButton("geometry", FLIP_LINE_ORIENTATION_NAME, FLIP_LINE_ORIENTATION_ICON, editable, this::flipLineOrientation);
                this.toolBar.addButton("geometry", FLIP_FIELDS_NAME, FLIP_FIELDS_ICON, editable, this::flipFields);
            } else {
                this.toolBar.addButton("geometry", "Flip Line Orientation", "flip_line", editable, this::flipLineOrientation);
            }
        }
    }
    return this.toolBar;
}
Also used : ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) MapPanel(com.revolsys.swing.map.MapPanel) MenuFactory(com.revolsys.swing.menu.MenuFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ToolBar(com.revolsys.swing.toolbar.ToolBar) DataType(com.revolsys.datatype.DataType) EnableCheck(com.revolsys.swing.action.enablecheck.EnableCheck) ObjectPropertyEnableCheck(com.revolsys.swing.action.enablecheck.ObjectPropertyEnableCheck) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 43 with DataType

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

the class GeometryStyleRenderer method newIcon.

@Override
public Icon newIcon() {
    final AbstractRecordLayer layer = getLayer();
    if (layer == null) {
        return ICON;
    } else {
        final GeometryStyle geometryStyle = getStyle();
        Shape shape = null;
        final DataType geometryDataType = layer.getGeometryType();
        if (DataTypes.POINT.equals(geometryDataType) || DataTypes.MULTI_POINT.equals(geometryDataType)) {
            return this.style.getMarker().newIcon(geometryStyle);
        } else if (DataTypes.LINE_STRING.equals(geometryDataType) || DataTypes.MULTI_LINE_STRING.equals(geometryDataType)) {
            shape = GeometryStylePreview.getLineShape(16);
        } else if (DataTypes.POLYGON.equals(geometryDataType) || DataTypes.MULTI_POLYGON.equals(geometryDataType)) {
            shape = getPolygonShape();
        } else {
            return ICON;
        }
        final BufferedImage image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D graphics = image.createGraphics();
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        if (DataTypes.POLYGON.equals(geometryDataType) || DataTypes.MULTI_POLYGON.equals(geometryDataType)) {
            graphics.setPaint(geometryStyle.getPolygonFill());
            graphics.fill(shape);
        }
        final Color color = geometryStyle.getLineColor();
        graphics.setColor(color);
        graphics.draw(shape);
        graphics.dispose();
        return new ImageIcon(image);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) GeometryStyle(com.revolsys.swing.map.layer.record.style.GeometryStyle) Shape(java.awt.Shape) Color(java.awt.Color) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) DataType(com.revolsys.datatype.DataType) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 44 with DataType

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

the class WebMethodHandler method requestParameter.

public static WebParameterHandler requestParameter(final WebAnnotationMethodHandlerAdapter adapter, final Parameter parameter, final Annotation annotation) {
    final RequestParam requestParam = (RequestParam) annotation;
    final String name = getName(parameter, requestParam.value());
    final boolean required = requestParam.required();
    final String defaultValueString = requestParam.defaultValue();
    final Class<?> parameterClass = parameter.getType();
    final DataType dataType = DataTypes.getDataType(parameterClass);
    BiFunction<HttpServletRequest, HttpServletResponse, Object> function;
    Object defaultValue = null;
    if (List.class.equals(parameterClass)) {
        if (ValueConstants.DEFAULT_NONE.equals(defaultValueString)) {
            final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType();
            final Type[] typeParameters = parameterizedType.getActualTypeArguments();
            final Type elementType = typeParameters[0];
            if (MultipartFile.class.equals(elementType)) {
                function = (request, response) -> {
                    if (request instanceof MultipartRequest) {
                        final MultipartRequest multipartRequest = (MultipartRequest) request;
                        return multipartRequest.getFiles(name);
                    } else {
                        return Collections.emptyList();
                    }
                };
            } else {
                final DataType elementDataType = DataTypes.getDataType(elementType);
                function = (request, response) -> {
                    final List<Object> list = new ArrayList<>();
                    final String[] parameterValues = request.getParameterValues(name);
                    if (parameterValues != null) {
                        for (final String stringValue : parameterValues) {
                            final Object value = elementDataType.toObject(stringValue);
                            list.add(value);
                        }
                    }
                    return list;
                };
            }
        } else {
            throw new IllegalArgumentException("RequestParam.defaultValue not allowed for " + name);
        }
    } else if (parameterClass.isArray()) {
        if (ValueConstants.DEFAULT_NONE.equals(defaultValueString)) {
            final Class<?> elementClass = parameterClass.getComponentType();
            if (MultipartFile.class.equals(elementClass)) {
                function = (request, response) -> {
                    if (request instanceof MultipartRequest) {
                        final MultipartRequest multipartRequest = (MultipartRequest) request;
                        final List<MultipartFile> files = multipartRequest.getFiles(name);
                        return files.toArray();
                    } else {
                        return new MultipartFile[0];
                    }
                };
            } else {
                final DataType elementDataType = DataTypes.getDataType(elementClass);
                function = (request, response) -> {
                    final String[] parameterValues = request.getParameterValues(name);
                    int length;
                    if (parameterValues == null) {
                        length = 0;
                    } else {
                        length = parameterValues.length;
                    }
                    final Object array = Array.newInstance(elementClass, length);
                    for (int i = 0; i < length; i++) {
                        final String stringValue = parameterValues[i];
                        final Object value = elementDataType.toObject(stringValue);
                        Array.set(array, i, value);
                    }
                    return array;
                };
            }
        } else {
            throw new IllegalArgumentException("RequestParam.defaultValue not allowed for " + name);
        }
    } else {
        defaultValue = parseDefaultValueAttribute(dataType, defaultValueString);
        if (MultipartFile.class.equals(parameterClass)) {
            function = (request, response) -> {
                if (request instanceof MultipartRequest) {
                    final MultipartRequest multipartRequest = (MultipartRequest) request;
                    return multipartRequest.getFile(name);
                } else {
                    return null;
                }
            };
        } else {
            function = (request, response) -> {
                return request.getParameter(name);
            };
        }
    }
    return // 
    WebParameterHandler.function(// 
    name, // 
    function, // 
    dataType, // 
    required, // 
    defaultValue);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) WrappedException(com.revolsys.util.WrappedException) RequestParam(org.springframework.web.bind.annotation.RequestParam) Array(java.lang.reflect.Array) URLDecoder(java.net.URLDecoder) BiFunction(java.util.function.BiFunction) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) Property(com.revolsys.util.Property) CookieValue(org.springframework.web.bind.annotation.CookieValue) RequestContextUtils(org.springframework.web.servlet.support.RequestContextUtils) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) Map(java.util.Map) MultipartRequest(org.springframework.web.multipart.MultipartRequest) Method(java.lang.reflect.Method) HttpSession(javax.servlet.http.HttpSession) WebUtils(org.springframework.web.util.WebUtils) ClassUtils(org.springframework.util.ClassUtils) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) StandardCharsets(java.nio.charset.StandardCharsets) Logs(com.revolsys.logging.Logs) List(java.util.List) Principal(java.security.Principal) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) HandlerMapping(org.springframework.web.servlet.HandlerMapping) Type(java.lang.reflect.Type) ServletResponse(javax.servlet.ServletResponse) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Annotation(java.lang.annotation.Annotation) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) FileCopyUtils(org.springframework.util.FileCopyUtils) Exceptions(com.revolsys.util.Exceptions) HashMap(java.util.HashMap) HttpServletUtils(com.revolsys.ui.web.utils.HttpServletUtils) ArrayList(java.util.ArrayList) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) Charset(java.nio.charset.Charset) Parameter(java.lang.reflect.Parameter) Cookie(javax.servlet.http.Cookie) OutputStream(java.io.OutputStream) ServletRequest(javax.servlet.ServletRequest) RequestAttribute(com.revolsys.ui.web.annotation.RequestAttribute) HttpServletResponse(javax.servlet.http.HttpServletResponse) MultiValueMap(org.springframework.util.MultiValueMap) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) DataTypes(com.revolsys.datatype.DataTypes) Reader(com.revolsys.io.Reader) HttpMediaTypeNotSupportedException(org.springframework.web.HttpMediaTypeNotSupportedException) Function3(com.revolsys.util.function.Function3) HttpInputMessage(org.springframework.http.HttpInputMessage) ParameterizedType(java.lang.reflect.ParameterizedType) MultipartFile(org.springframework.web.multipart.MultipartFile) Writer(com.revolsys.io.Writer) ValueConstants(org.springframework.web.bind.annotation.ValueConstants) DataType(com.revolsys.datatype.DataType) Collections(java.util.Collections) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) InputStream(java.io.InputStream) StringUtils(org.springframework.util.StringUtils) RequestParam(org.springframework.web.bind.annotation.RequestParam) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ParameterizedType(java.lang.reflect.ParameterizedType) MediaType(org.springframework.http.MediaType) Type(java.lang.reflect.Type) ParameterizedType(java.lang.reflect.ParameterizedType) DataType(com.revolsys.datatype.DataType) MultipartFile(org.springframework.web.multipart.MultipartFile) DataType(com.revolsys.datatype.DataType) List(java.util.List) ArrayList(java.util.ArrayList) MultipartRequest(org.springframework.web.multipart.MultipartRequest)

Example 45 with DataType

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

the class WebMethodHandler method requestHeader.

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

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