use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class RecordStoreLayer method newLayerRecord.
@Override
public LayerRecord newLayerRecord(final Map<String, ? extends Object> values) {
if (!isReadOnly() && isEditable() && isCanAddRecords()) {
final RecordDefinition recordDefinition = getRecordDefinition();
final ArrayLayerRecord newRecord = new RecordStoreLayerRecord(this);
if (values != null) {
newRecord.setState(RecordState.INITIALIZING);
final List<FieldDefinition> idFields = recordDefinition.getIdFields();
for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
if (!idFields.contains(fieldDefinition)) {
final String fieldName = fieldDefinition.getName();
final Object value = values.get(fieldName);
fieldDefinition.setValue(newRecord, value);
}
}
newRecord.setState(RecordState.NEW);
}
addRecordToCache(getCacheIdNew(), newRecord);
if (isEventsEnabled()) {
cleanCachedRecords();
}
final LayerRecord proxyRecord = new NewProxyLayerRecord(this, newRecord);
fireRecordInserted(proxyRecord);
return proxyRecord;
} else {
return null;
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class RecordStoreLayer method refreshDo.
@Override
protected void refreshDo() {
synchronized (getSync()) {
if (this.loadingWorker != null) {
this.loadingWorker.cancel(true);
}
this.loadedBoundingBox = BoundingBox.empty();
this.loadingBoundingBox = this.loadedBoundingBox;
super.refreshDo();
}
final RecordStore recordStore = getRecordStore();
final PathName pathName = getPathName();
final CodeTable codeTable = recordStore.getCodeTable(pathName);
if (codeTable != null) {
codeTable.refresh();
}
if (hasIdField()) {
final List<Identifier> identifiers = new ArrayList<>();
synchronized (getSync()) {
identifiers.addAll(this.recordsByIdentifier.keySet());
}
if (!identifiers.isEmpty()) {
identifiers.sort(Identifier.comparator());
final RecordDefinition recordDefinition = recordStore.getRecordDefinition(pathName);
final List<FieldDefinition> idFields = recordDefinition.getIdFields();
final int idFieldCount = idFields.size();
if (idFieldCount == 1) {
final FieldDefinition idField = idFields.get(0);
final int pageSize = 999;
final int identifierCount = identifiers.size();
for (int i = 0; i < identifiers.size(); i += pageSize) {
final List<Identifier> queryIdentifiers = identifiers.subList(i, Math.min(identifierCount, i + pageSize));
final In in = Q.in(idField, queryIdentifiers);
final Query query = new Query(recordDefinition, in);
updateCachedRecords(recordStore, query);
}
} else if (!idFields.isEmpty()) {
for (final Identifier identifier : identifiers) {
final Query query = new Query(recordDefinition, Q.equalId(idFields, identifier));
updateCachedRecords(recordStore, query);
}
}
}
}
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class FieldCalculator method initFieldPanel.
@Override
protected JPanel initFieldPanel() {
final FieldDefinition fieldDefinition = this.getFieldDefinition();
final String fieldName = fieldDefinition.getName();
final JPanel fieldPanel = new JPanel(new VerticalLayout());
final ToolBar toolBar = new ToolBar();
fieldPanel.add(toolBar);
this.expressionField = new TextArea("script", 8, 1);
fieldPanel.add(new JScrollPane(this.expressionField));
this.expressionField.getDocument().addDocumentListener(this);
final AbstractRecordLayer layer = getLayer();
final List<String> fieldNames = layer.getFieldNames();
final ComboBox<String> fieldNamesField = ComboBox.newComboBox("fieldNames", fieldNames, (final Object name) -> {
return layer.getFieldTitle((String) name);
});
toolBar.addComponent("fieldName", fieldNamesField);
toolBar.add(fieldNamesField);
fieldNamesField.setMaximumSize(new Dimension(250, 30));
final Runnable addFieldAction = () -> {
final String selectedFieldName = fieldNamesField.getFieldValue();
insertText(selectedFieldName);
};
toolBar.addButton("fieldName", "Add field name", "add", addFieldAction);
for (final String text : Arrays.asList("+", "-", "*", "/")) {
addTextButton("operators", toolBar, text, text);
}
addTextButton("condition", toolBar, "if", "if (expression) {\n newValue;\n} else {\n " + fieldName + ";\n}");
addTextButton("codeTable", toolBar, "Code ID", "codeId('codeFieldName', codeValue)");
addTextButton("codeTable", toolBar, "Code Value", "codeValue('codeFieldName', codeValue)");
return fieldPanel;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method getPasteNewValues.
public Map<String, Object> getPasteNewValues(final Record sourceRecord) {
final RecordDefinition recordDefinition = getRecordDefinition();
final Set<String> ignoreFieldNames = getIgnorePasteFieldNames();
final Map<String, Object> newValues = new LinkedHashMap<>();
for (final String fieldName : recordDefinition.getFieldNames()) {
if (!ignoreFieldNames.contains(fieldName)) {
final Object value = sourceRecord.getValue(fieldName);
if (value != null) {
newValues.put(fieldName, value);
}
}
}
final FieldDefinition geometryFieldDefinition = recordDefinition.getGeometryField();
if (geometryFieldDefinition != null) {
final GeometryFactory geometryFactory = getGeometryFactory();
Geometry sourceGeometry = sourceRecord.getGeometry();
final String geometryFieldName = geometryFieldDefinition.getName();
if (sourceGeometry == null) {
final Object value = sourceRecord.getValue(geometryFieldName);
sourceGeometry = geometryFieldDefinition.toFieldValue(value);
}
Geometry geometry = geometryFieldDefinition.toFieldValue(sourceGeometry);
if (geometry == null) {
if (sourceGeometry != null) {
newValues.put(geometryFieldName, sourceGeometry);
}
} else {
geometry = geometry.convertGeometry(geometryFactory);
newValues.put(geometryFieldName, geometry);
}
}
return newValues;
}
use of com.revolsys.record.schema.FieldDefinition in project com.revolsys.open by revolsys.
the class AbstractRecordLayer method setRecordDefinition.
protected void setRecordDefinition(final RecordDefinition recordDefinition) {
this.recordDefinition = recordDefinition;
if (recordDefinition != null) {
final FieldDefinition geometryField = recordDefinition.getGeometryField();
GeometryFactory geometryFactory;
if (geometryField == null) {
geometryFactory = null;
setVisible(false);
setSelectSupported(false);
setRenderer(null);
} else {
geometryFactory = recordDefinition.getGeometryFactory();
}
setGeometryFactory(geometryFactory);
final String iconName = recordDefinition.getIconName();
setIcon(iconName);
this.fieldNames = recordDefinition.getFieldNames();
List<String> allFieldNames = this.fieldNamesSets.get(ALL.toUpperCase());
if (Property.hasValue(allFieldNames)) {
final Set<String> mergedFieldNames = new LinkedHashSet<>(allFieldNames);
mergedFieldNames.addAll(this.fieldNames);
mergedFieldNames.retainAll(this.fieldNames);
allFieldNames = new ArrayList<>(mergedFieldNames);
} else {
allFieldNames = new ArrayList<>(this.fieldNames);
}
this.fieldNamesSets.put(ALL.toUpperCase(), allFieldNames);
setWhere(this.where);
}
}
Aggregations