use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class GeoreferencedImageLayer method cancelChanges.
public void cancelChanges() {
if (this.image == null && this.resource != null) {
GeoreferencedImage image = null;
final Resource imageResource = Resource.getResource(this.url);
if (imageResource.exists()) {
try {
image = GeoreferencedImageReadFactory.loadGeoreferencedImage(imageResource);
if (image == null) {
Logs.error(GeoreferencedImageLayer.class, "Cannot load image: " + this.url);
}
} catch (final RuntimeException e) {
Logs.error(GeoreferencedImageLayer.class, "Unable to load image: " + this.url, e);
}
} else {
Logs.error(GeoreferencedImageLayer.class, "Image does not exist: " + this.url);
}
setImage(image);
} else {
this.image.cancelChanges();
}
firePropertyChange("hasChanges", true, false);
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class ArcGisRestAbstractLayerService method addLayer.
public LayerDescription addLayer(final CatalogElement parent, final Map<String, LayerDescription> layersByName, MapEx layerProperties) {
final int id = layerProperties.getInteger("id");
final Resource resource = getResource(Integer.toString(id), ArcGisResponse.FORMAT_PARAMETER);
try {
layerProperties = Json.toMap(resource);
final String layerType = layerProperties.getString("type");
final Function3<ArcGisRestAbstractLayerService, CatalogElement, MapEx, LayerDescription> factory = LAYER_FACTORY_BY_TYPE.get(layerType);
LayerDescription layer;
if (factory == null) {
layer = new LayerDescription(this, parent, layerProperties);
} else {
layer = factory.apply(this, parent, layerProperties);
}
final String name = layer.getName();
if (Property.hasValue(name)) {
layersByName.put(name.toLowerCase(), layer);
return layer;
} else {
return null;
}
} catch (final Throwable e) {
e.printStackTrace();
Logs.debug(this, "Unable to initialize layer: " + resource, e);
return null;
}
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class FeatureLayer method getRecordCount.
protected int getRecordCount(final Map<String, Object> parameters, final Object errorText) {
parameters.put("returnCountOnly", "true");
final Resource resource = getResource("query", parameters);
try {
final MapEx response = Json.toMap(resource);
return response.getInteger("count", 0);
} catch (final Throwable e) {
Logs.debug(this, "Unable to get count for: " + errorText + "\n" + resource.getUriString());
}
return 0;
}
use of com.revolsys.spring.resource.Resource in project com.revolsys.open by revolsys.
the class CsvRecordWriter method pause.
public void pause() {
final Resource resource = getResource();
if (resource == null) {
throw new IllegalStateException("Cannot pause without a resource");
}
if (!this.paused) {
final Writer out = this.out;
if (out != null) {
this.paused = true;
flush();
try {
out.flush();
} catch (final IOException e) {
}
try {
out.close();
} catch (final IOException e) {
}
this.out = null;
}
}
}
use of com.revolsys.spring.resource.Resource 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);
});
}
Aggregations