Search in sources :

Example 76 with RecordDefinition

use of com.revolsys.record.schema.RecordDefinition 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 77 with RecordDefinition

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

the class AbstractRecordLayer method setWhere.

public void setWhere(final String where) {
    final RecordDefinition recordDefinition = getRecordDefinition();
    this.where = where;
    if (recordDefinition != null) {
        final Object oldValue = this.filter;
        this.filter = QueryValue.parseWhere(recordDefinition, where);
        firePropertyChange("filter", oldValue, this.filter);
    }
}
Also used : RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 78 with RecordDefinition

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

the class RecordValidationDialog method newValidRecordsTablePanel.

private TablePanel newValidRecordsTablePanel() {
    final RecordDefinition recordDefinition = this.layer.getRecordDefinition();
    final List<String> fieldNames = this.layer.getFieldNames();
    final RecordListTableModel model = new RecordListTableModel(recordDefinition, this.validRecords, fieldNames);
    final RecordRowTable table = new RecordRowTable(model);
    table.setVisibleRowCount(Math.min(10, model.getRowCount() + 1));
    table.setSortable(true);
    table.setEditable(false);
    table.resizeColumnsToContent();
    final TablePanel tablePanel = new TablePanel(table);
    tablePanel.setBorder(BorderFactory.createTitledBorder(table.getRowCount() + " valid records"));
    return tablePanel;
}
Also used : RecordListTableModel(com.revolsys.swing.table.record.model.RecordListTableModel) RecordDefinition(com.revolsys.record.schema.RecordDefinition) RecordRowTable(com.revolsys.swing.table.record.RecordRowTable) TablePanel(com.revolsys.swing.table.TablePanel)

Example 79 with RecordDefinition

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

the class RecordHtmlUiBuilder method isPropertyUnique.

protected boolean isPropertyUnique(final Record object, final String fieldName) {
    final String value = object.getValue(fieldName);
    final RecordStore recordStore = getRecordStore();
    final RecordDefinition recordDefinition = recordStore.getRecordDefinition(this.tableName);
    if (recordDefinition == null) {
        return true;
    } else {
        final Query query = Query.equal(recordDefinition, fieldName, value);
        final Reader<Record> results = recordStore.getRecords(query);
        final List<Record> objects = results.toList();
        if (object.getState() == RecordState.NEW) {
            return objects.isEmpty();
        } else {
            final Identifier id = object.getIdentifier();
            for (final Iterator<Record> iterator = objects.iterator(); iterator.hasNext(); ) {
                final Record matchedObject = iterator.next();
                final Identifier matchedId = matchedObject.getIdentifier();
                if (DataType.equal(id, matchedId)) {
                    iterator.remove();
                }
            }
            return objects.isEmpty();
        }
    }
}
Also used : Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) RecordStore(com.revolsys.record.schema.RecordStore) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 80 with RecordDefinition

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

the class MapGuideWebServerRecordLayer method initializeDo.

@Override
protected boolean initializeDo() {
    FeatureLayer webServiceLayer = getWebServiceLayer();
    if (webServiceLayer == null) {
        final String url = getUrl();
        final PathName layerPath = getLayerPath();
        if (url == null) {
            Logs.error(this, Classes.className(this) + " requires a url: " + getPath());
            return false;
        }
        if (layerPath == null) {
            Logs.error(this, Classes.className(this) + " requires a layerPath: " + getPath());
            return false;
        }
        ArcGisRestCatalog server;
        try {
            server = ArcGisRestCatalog.newArcGisRestCatalog(url);
        } catch (final Throwable e) {
            Logs.error(this, "Unable to connect to server: " + url + " for " + getPath(), e);
            return false;
        }
        try {
            webServiceLayer = server.getWebServiceResource(layerPath, FeatureLayer.class);
        } catch (final IllegalArgumentException e) {
            Logs.error(this, "Layer is not valid: " + getPath(), e);
            return false;
        }
        if (webServiceLayer == null) {
            Logs.error(this, "Layer does not exist: " + layerPath + " for " + getPath());
            return false;
        } else {
            setWebServiceLayer(webServiceLayer);
        }
    }
    if (webServiceLayer != null) {
        final RecordDefinition recordDefinition = webServiceLayer.getRecordDefinition();
        if (recordDefinition != null) {
            setRecordDefinition(recordDefinition);
            setBoundingBox(webServiceLayer.getBoundingBox());
            // initRenderer();
            return super.initializeDo();
        }
    }
    return false;
}
Also used : FeatureLayer(com.revolsys.record.io.format.mapguide.FeatureLayer) ArcGisRestCatalog(com.revolsys.record.io.format.esri.rest.ArcGisRestCatalog) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordDefinition (com.revolsys.record.schema.RecordDefinition)189 FieldDefinition (com.revolsys.record.schema.FieldDefinition)38 Record (com.revolsys.record.Record)34 Geometry (com.revolsys.geometry.model.Geometry)20 CodeTable (com.revolsys.record.code.CodeTable)19 Query (com.revolsys.record.query.Query)18 LineString (com.revolsys.geometry.model.LineString)17 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)16 PathName (com.revolsys.io.PathName)13 ArrayList (java.util.ArrayList)12 DataType (com.revolsys.datatype.DataType)11 Identifier (com.revolsys.identifier.Identifier)11 RecordReader (com.revolsys.record.io.RecordReader)11 RecordStore (com.revolsys.record.schema.RecordStore)11 HashMap (java.util.HashMap)9 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)8 ArrayRecord (com.revolsys.record.ArrayRecord)8 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)6 Table (com.revolsys.gis.esri.gdb.file.capi.swig.Table)5 RecordWriter (com.revolsys.record.io.RecordWriter)5