use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class MergeRecordsDialog method run.
public void run() {
try {
final List<LayerRecord> originalRecords = this.layer.getMergeableSelectedRecords();
String errorMessage = "";
final DataType geometryType = this.layer.getGeometryType();
this.mergedRecords = new HashMap<>();
if (originalRecords.size() < 2) {
errorMessage = " at least two records must be selected to merge.";
} else if (!DataTypes.LINE_STRING.equals(geometryType) && !DataTypes.MULTI_LINE_STRING.equals(geometryType)) {
errorMessage = "Merging " + geometryType + " not currently supported";
} else {
final RecordGraph graph = new RecordGraph();
for (final LayerRecord originalRecord : originalRecords) {
Geometry geometry = originalRecord.getGeometry();
if (geometry != null && !geometry.isEmpty()) {
geometry = this.layer.getGeometryFactory().geometry(LineString.class, geometry);
if (geometry instanceof LineString) {
final Record mergeableRecord = new ArrayRecord(originalRecord);
mergeableRecord.setGeometryValue(geometry);
this.mergeableToOiginalRecordMap.put(mergeableRecord, originalRecord);
graph.addEdge(mergeableRecord);
}
}
}
for (final Node<Record> node : graph.nodes()) {
if (node != null) {
final List<Edge<Record>> edges = node.getEdges();
if (edges.size() == 2) {
final Edge<Record> edge1 = edges.get(0);
final Record record1 = edge1.getObject();
final Edge<Record> edge2 = edges.get(1);
final Record record2 = edge2.getObject();
if (record1 != record2) {
final Record mergedRecord = this.layer.getMergedRecord(node, record1, record2);
graph.addEdge(mergedRecord);
edge1.remove();
edge2.remove();
final Set<LayerRecord> sourceRecords = new LinkedHashSet<>();
// TODO verify orientation to ensure they are in the correct
// order
// and see if they are reversed
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record1));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record1));
CollectionUtil.addIfNotNull(sourceRecords, this.mergeableToOiginalRecordMap.get(record2));
CollectionUtil.addAllIfNotNull(sourceRecords, this.mergedRecords.remove(record2));
this.mergedRecords.put(mergedRecord, sourceRecords);
replaceRecord(mergedRecord, record1);
replaceRecord(mergedRecord, record2);
}
}
}
}
}
final String message = errorMessage;
Invoke.later(() -> setMergedRecords(message, this.mergedRecords));
} catch (final Throwable e) {
Logs.error(this, "Error " + this, e);
}
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class MergeRecordsDialog method finish.
public void finish() {
final MultipleUndo multipleUndo = new MultipleUndo();
for (final Record mergedRecord : this.mergedRecords.keySet()) {
final CreateRecordUndo createRecordUndo = new CreateRecordUndo(this.layer, mergedRecord);
multipleUndo.addEdit(createRecordUndo);
}
for (final LayerRecord record : this.replacedOriginalRecords) {
final DeleteLayerRecordUndo deleteRecordUndo = new DeleteLayerRecordUndo(record);
multipleUndo.addEdit(deleteRecordUndo);
}
if (this.undoManager == null) {
multipleUndo.redo();
} else {
this.undoManager.addEdit(multipleUndo);
}
setVisible(false);
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class ModeAbstractCached method forEachRecord.
@Override
public void forEachRecord(final Query query, final Consumer<? super LayerRecord> action) {
final Condition filter = query.getWhereCondition();
final Map<? extends CharSequence, Boolean> orderBy = query.getOrderBy();
final AbstractRecordLayer layer = getLayer();
final Iterable<LayerRecord> records = new ListByIndexIterator<>(this.records);
layer.forEachRecord(records, filter, orderBy, action);
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class ModeAllPaged method getRecordDo.
@Override
protected LayerRecord getRecordDo(final int row) {
final int recordCountChanges = super.getRecordCount();
if (row >= 0) {
if (row < recordCountChanges) {
return super.getRecordDo(row);
} else {
final int persistedRow = row - recordCountChanges;
final int recordCount = getRecordCount();
if (row < recordCount) {
final int pageNumber = persistedRow / this.pageSize;
final int recordNumber = persistedRow % this.pageSize;
final LayerRecord record = getRecordPagePersisted(pageNumber, recordNumber);
return record;
}
}
}
return null;
}
use of com.revolsys.swing.map.layer.record.LayerRecord in project com.revolsys.open by revolsys.
the class EditRecordGeometryOverlay method addRecords.
private void addRecords(final List<LayerRecord> results, final LayerGroup group, final Geometry boundingBox) {
final double scale = getViewportScale();
final List<Layer> layers = group.getLayers();
Collections.reverse(layers);
for (final Layer layer : layers) {
if (layer instanceof LayerGroup) {
final LayerGroup childGroup = (LayerGroup) layer;
addRecords(results, childGroup, boundingBox);
} else if (layer instanceof AbstractRecordLayer) {
final AbstractRecordLayer recordLayer = (AbstractRecordLayer) layer;
if (recordLayer.isSelectable(scale)) {
final List<LayerRecord> selectedRecords = recordLayer.getSelectedRecords();
for (final LayerRecord selectedRecord : selectedRecords) {
final Geometry geometry = selectedRecord.getGeometry();
if (boundingBox.intersects(geometry)) {
results.add(selectedRecord);
}
}
}
}
}
}
Aggregations