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