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