use of com.revolsys.spring.resource.ByteArrayResource 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;
}
}
use of com.revolsys.spring.resource.ByteArrayResource in project com.revolsys.open by revolsys.
the class EsriGdbXmlParser method parse.
@SuppressWarnings("unchecked")
public static <T> T parse(final String text) {
final byte[] bytes = text.getBytes();
final ByteArrayResource resource = new ByteArrayResource(bytes);
return (T) parse(resource);
}
use of com.revolsys.spring.resource.ByteArrayResource 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