Search in sources :

Example 31 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class TriangulatedIrregularNetworkLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final TriangulatedIrregularNetworkLayer layer) {
    final double scaleForVisible = viewport.getScaleForVisible();
    if (layer.isVisible(scaleForVisible)) {
        if (!layer.isEditable()) {
            final TriangulatedIrregularNetwork tin = layer.getTin();
            if (tin != null) {
                try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(true)) {
                    for (final Triangle triangle : cancellable.cancellable(tin.getTriangles(viewport.getBoundingBox()))) {
                        final Geometry convertedTriangle = tin.convertGeometry(triangle);
                        viewport.drawGeometry(convertedTriangle, this.style);
                    }
                }
            }
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) TriangulatedIrregularNetwork(com.revolsys.elevation.tin.TriangulatedIrregularNetwork) BaseCloseable(com.revolsys.io.BaseCloseable) Triangle(com.revolsys.geometry.model.Triangle)

Example 32 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class RecordLayerTableModel method forEachRecord.

public void forEachRecord(final Consumer<? super LayerRecord> action) {
    final TableRecordsMode tableRecordsMode = getTableRecordsMode();
    if (tableRecordsMode != null) {
        final Query query = getFilterQuery();
        try (BaseCloseable eventsDisabled = this.layer.eventsDisabled()) {
            tableRecordsMode.forEachRecord(query, action);
        }
        refresh();
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Query(com.revolsys.record.query.Query)

Example 33 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method saveChanges.

public final boolean saveChanges(final LayerRecord record) {
    // Includes two types of validation of record. The first checks field
    // types before interacting with the record store. The second is any
    // errors on the actual saving of data.
    final Set<Boolean> allSaved = new HashSet<>();
    // 
    RecordValidationDialog.validateRecords(// 
    "Save Changes", // 
    this, record, (validator) -> {
        // Success
        // Save the valid records
        final List<LayerRecord> validRecords = validator.getValidRecords();
        if (!validRecords.isEmpty()) {
            final RecordLayerErrors errors = new RecordLayerErrors("Saving Changes", this);
            try (BaseCloseable eventsEnabled = eventsDisabled()) {
                synchronized (this.getSync()) {
                    try {
                        final boolean saved = internalSaveChanges(errors, record);
                        if (!saved) {
                            errors.addRecord(record, "Unknown error");
                        }
                    } catch (final Throwable t) {
                        errors.addRecord(record, t);
                    }
                }
                cleanCachedRecords();
                record.fireRecordUpdated();
            } finally {
                if (!errors.showErrorDialog()) {
                    allSaved.add(false);
                }
            }
        }
        final List<LayerRecord> invalidRecords = validator.getInvalidRecords();
        if (!invalidRecords.isEmpty()) {
            allSaved.add(false);
        }
    }, (validator) -> {
        allSaved.add(false);
    });
    return allSaved.isEmpty();
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordLayerErrors(com.revolsys.swing.map.layer.record.table.model.RecordLayerErrors) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 34 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method pasteRecords.

public void pasteRecords() {
    final List<LayerRecord> newRecords = new ArrayList<>();
    try (BaseCloseable eventsEnabled = eventsDisabled()) {
        RecordReader reader = ClipboardUtil.getContents(RecordReaderTransferable.DATA_OBJECT_READER_FLAVOR);
        if (reader == null) {
            final String string = ClipboardUtil.getContents(DataFlavor.stringFlavor);
            if (Property.hasValue(string)) {
                if (string.contains("\t")) {
                    final Resource tsvResource = new ByteArrayResource("t.tsv", string);
                    reader = RecordReader.newRecordReader(tsvResource);
                } else {
                    final Resource resource = new ByteArrayResource("t.csv", string);
                    reader = RecordReader.newRecordReader(resource);
                }
            }
        }
        if (reader != null) {
            for (final Record sourceRecord : reader) {
                final Map<String, Object> newValues = getPasteNewValues(sourceRecord);
                if (!newValues.isEmpty()) {
                    final LayerRecord newRecord = newLayerRecord(newValues);
                    if (newRecord != null) {
                        newRecords.add(newRecord);
                    }
                }
            }
        }
    } catch (final Throwable e) {
        LoggingEventPanel.showDialog(getMapPanel(), "Unexpected error pasting records", e);
        return;
    }
    RecordValidationDialog.validateRecords("Pasting Records", this, newRecords, (validator) -> {
        // Success
        // Save the valid records
        final List<LayerRecord> validRecords = validator.getValidRecords();
        if (!validRecords.isEmpty()) {
            saveChanges(validRecords);
            addSelectedRecords(validRecords);
            zoomToRecords(validRecords);
            showRecordsTable(RecordLayerTableModel.MODE_RECORDS_SELECTED);
            firePropertyChange(RECORDS_INSERTED, null, validRecords);
        }
        // Delete any invalid records
        final List<LayerRecord> invalidRecords = validator.getInvalidRecords();
        if (!invalidRecords.isEmpty()) {
            deleteRecords(invalidRecords);
        }
    }, (validator) -> {
        // Cancel, delete all the records
        deleteRecords(newRecords);
    });
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordReader(com.revolsys.record.io.RecordReader) ListRecordReader(com.revolsys.record.io.ListRecordReader) ArrayList(java.util.ArrayList) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource) Resource(com.revolsys.spring.resource.Resource) ArrayRecord(com.revolsys.record.ArrayRecord) Record(com.revolsys.record.Record) LineString(com.revolsys.geometry.model.LineString) ByteArrayResource(com.revolsys.spring.resource.ByteArrayResource)

Example 35 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method saveChanges.

public final boolean saveChanges(final Collection<? extends LayerRecord> records) {
    try {
        if (records.isEmpty()) {
            return true;
        } else {
            // Includes two types of validation of record. The first checks field
            // types before interacting with the record store. The second is any
            // errors on the actual saving of data.
            final Set<Boolean> allSaved = new HashSet<>();
            // 
            RecordValidationDialog.validateRecords(// 
            "Save Changes", // 
            this, records, (validator) -> {
                // Success
                // Save the valid records
                final List<LayerRecord> validRecords = validator.getValidRecords();
                if (!validRecords.isEmpty()) {
                    final RecordLayerErrors errors = new RecordLayerErrors("Saving Changes", this);
                    try (BaseCloseable eventsEnabled = eventsDisabled()) {
                        for (final LayerRecord record : validRecords) {
                            synchronized (this.getSync()) {
                                try {
                                    final boolean saved = internalSaveChanges(errors, record);
                                    if (!saved) {
                                        errors.addRecord(record, "Unknown error");
                                    }
                                } catch (final Throwable t) {
                                    errors.addRecord(record, t);
                                }
                            }
                        }
                        cleanCachedRecords();
                    } finally {
                        if (!errors.showErrorDialog()) {
                            allSaved.add(false);
                        }
                    }
                    fireRecordsChanged();
                }
                final List<LayerRecord> invalidRecords = validator.getInvalidRecords();
                if (!invalidRecords.isEmpty()) {
                    allSaved.add(false);
                }
            }, (validator) -> {
                allSaved.add(false);
            });
            return allSaved.isEmpty();
        }
    } finally {
        fireSelected();
        fireHasChangedRecords();
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) RecordLayerErrors(com.revolsys.swing.map.layer.record.table.model.RecordLayerErrors) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2