use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method isCanMergeRecords.
public boolean isCanMergeRecords() {
if (isCanAddRecords()) {
if (isCanDeleteRecords()) {
final DataType geometryType = getGeometryType();
if (DataTypes.POINT.equals(geometryType)) {
return false;
} else if (DataTypes.MULTI_POINT.equals(geometryType)) {
return false;
} else if (DataTypes.POLYGON.equals(geometryType)) {
return false;
} else if (DataTypes.MULTI_POLYGON.equals(geometryType)) {
return false;
}
final List<LayerRecord> mergeableSelectedRecords = getMergeableSelectedRecords();
if (mergeableSelectedRecords.size() > 1) {
return true;
}
}
}
return false;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method initRecordMenu.
protected LayerRecordMenu initRecordMenu() {
final LayerRecordMenu menu = new LayerRecordMenu(this);
this.recordMenu = menu;
if (this.recordDefinition != null) {
final RecordDefinition recordDefinition = getRecordDefinition();
final boolean hasGeometry = recordDefinition.hasGeometryField();
final Predicate<LayerRecord> modified = LayerRecord::isModified;
final Predicate<LayerRecord> notDeleted = ((Predicate<LayerRecord>) this::isDeleted).negate();
final Predicate<LayerRecord> modifiedOrDeleted = modified.or(LayerRecord::isDeleted);
final EnableCheck editableEnableCheck = this::isEditable;
menu.addGroup(0, "default");
menu.addGroup(1, "record");
menu.addGroup(2, "dnd");
final MenuFactory layerMenuFactory = MenuFactory.findMenu(this);
if (layerMenuFactory != null) {
menu.addComponentFactory("default", 0, new WrappedMenuFactory("Layer", layerMenuFactory));
}
menu.addMenuItem("record", "View/Edit Record", "table_edit", notDeleted, this::showForm);
if (hasGeometry) {
menu.addMenuItem("record", "Zoom to Record", "magnifier_zoom_selected", notDeleted, this::zoomToRecord);
menu.addMenuItem("record", "Pan to Record", "pan_selected", notDeleted, (record) -> {
final MapPanel mapPanel = getMapPanel();
if (mapPanel != null) {
mapPanel.panToRecord(record);
}
});
final MenuFactory editMenu = new MenuFactory("Edit Record Operations");
editMenu.setEnableCheck(LayerRecordMenu.enableCheck(notDeleted));
final DataType geometryDataType = recordDefinition.getGeometryField().getDataType();
if (geometryDataType == DataTypes.LINE_STRING || geometryDataType == DataTypes.MULTI_LINE_STRING) {
if (DirectionalFields.getProperty(recordDefinition).hasDirectionalFields()) {
LayerRecordMenu.addMenuItem(editMenu, "geometry", LayerRecordForm.FLIP_RECORD_NAME, LayerRecordForm.FLIP_RECORD_ICON, editableEnableCheck, this::actionFlipRecordOrientation);
LayerRecordMenu.addMenuItem(editMenu, "geometry", LayerRecordForm.FLIP_LINE_ORIENTATION_NAME, LayerRecordForm.FLIP_LINE_ORIENTATION_ICON, editableEnableCheck, this::actionFlipLineOrientation);
LayerRecordMenu.addMenuItem(editMenu, "geometry", LayerRecordForm.FLIP_FIELDS_NAME, LayerRecordForm.FLIP_FIELDS_ICON, editableEnableCheck, this::actionFlipFields);
} else {
LayerRecordMenu.addMenuItem(editMenu, "geometry", "Flip Line Orientation", "flip_line", editableEnableCheck, this::actionFlipLineOrientation);
}
}
menu.addComponentFactory("record", editMenu);
}
menu.addMenuItem("record", "Delete Record", "table_row_delete", LayerRecord::isDeletable, this::deleteRecord);
menu.addMenuItem("record", "Revert Record", "arrow_revert", modifiedOrDeleted, LayerRecord::revertChanges);
final Predicate<LayerRecord> hasModifiedEmptyFields = LayerRecord::isHasModifiedEmptyFields;
menu.addMenuItem("record", "Revert Empty Fields", "field_empty_revert", hasModifiedEmptyFields, LayerRecord::revertEmptyFields);
menu.addMenuItem("dnd", "Copy Record", "page_copy", this::copyRecordToClipboard);
if (hasGeometry) {
menu.addMenuItem("dnd", "Paste Geometry", "geometry_paste", this::canPasteRecordGeometry, this::pasteRecordGeometry);
}
}
return menu;
}
use of com.revolsys.datatype.DataType 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.datatype.DataType in project com.revolsys.open by revolsys.
the class RecordLog method getLogRecordDefinition.
public RecordDefinition getLogRecordDefinition(final RecordDefinition recordDefinition) {
RecordDefinitionImpl logRecordDefinition = this.logRecordDefinitionMap.get(recordDefinition);
if (logRecordDefinition == null) {
final String path = recordDefinition.getPath();
final String parentPath = PathUtil.getPath(path);
final String tableName = PathUtil.getName(path);
final String logTableName;
if (tableName.toUpperCase().equals(tableName)) {
logTableName = tableName + "_LOG";
} else {
logTableName = tableName + "_log";
}
final PathName logTypeName = PathName.newPathName(PathUtil.toPath(parentPath, logTableName));
logRecordDefinition = new RecordDefinitionImpl(logTypeName);
if (this.usesLocality) {
logRecordDefinition.addField(LOG_LOCALITY, DataTypes.STRING, 255, false);
}
logRecordDefinition.addField(LOG_MESSAGE, DataTypes.STRING, 255, true);
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
final FieldDefinition logFieldDefinition = new FieldDefinition(fieldDefinition);
final DataType dataType = logFieldDefinition.getDataType();
if (recordDefinition.getGeometryField() == fieldDefinition) {
logRecordDefinition.addField("GEOMETRY", dataType);
} else {
logRecordDefinition.addField(new FieldDefinition(fieldDefinition));
}
}
logRecordDefinition.setGeometryFactory(recordDefinition.getGeometryFactory());
this.logRecordDefinitionMap.put(recordDefinition, logRecordDefinition);
}
return logRecordDefinition;
}
use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.
the class QueryWhereConditionField method actionAddBinaryCondition.
private void actionAddBinaryCondition(final String operator) {
final FieldDefinition fieldDefinition = this.fieldNamesList.getSelectedItem();
if (fieldDefinition != null) {
Object fieldValue = ((Field) this.searchField).getFieldValue();
if (fieldValue != null) {
final int position = this.whereTextField.getCaretPosition();
DataType fieldType = fieldDefinition.getDataType();
if (this.codeTable == null) {
try {
fieldValue = fieldDefinition.toFieldValue(fieldValue);
} catch (final Throwable e) {
setInvalidMessage("'" + fieldValue + "' is not a valid " + fieldDefinition.getDataType().getValidationName());
return;
}
} else {
final List<Object> values = this.codeTable.getValues(Identifier.newIdentifier(fieldValue));
if (values.size() == 1) {
fieldValue = values.get(0);
} else {
fieldValue = Strings.toString(":", values);
}
if (fieldValue != null) {
fieldType = DataTypes.STRING;
}
}
if (fieldValue != null) {
final Document document = this.whereTextField.getDocument();
final StringBuilder text = new StringBuilder();
if (position > 0) {
text.append(" ");
}
text.append(fieldDefinition.getName());
text.append(" ");
text.append(operator);
text.append(" ");
appendValue(text, fieldType, fieldValue);
text.append(" ");
try {
document.insertString(position, text.toString(), null);
} catch (final BadLocationException e) {
Logs.error(this, "Error inserting text: " + text, e);
}
}
}
}
}
Aggregations