use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class Record method getValueByPath.
@SuppressWarnings("unchecked")
default <T> T getValueByPath(final CharSequence path) {
final int fieldIndex = getFieldIndex(path);
if (fieldIndex == -1) {
final RecordDefinition recordDefinition = getRecordDefinition();
final String[] propertyPath = path.toString().split("\\.");
Object propertyValue = this;
for (int i = 0; i < propertyPath.length && propertyValue != null; i++) {
final String propertyName = propertyPath[i];
if (propertyValue instanceof Record) {
final Record record = (Record) propertyValue;
if (record.hasField(propertyName)) {
propertyValue = record.getValue(propertyName);
if (propertyValue == null) {
return null;
} else if (i + 1 < propertyPath.length) {
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
if (codeTable != null) {
propertyValue = codeTable.getMap(propertyValue);
}
}
} else {
return null;
}
} else if (propertyValue instanceof Map) {
final Map<String, Object> map = (Map<String, Object>) propertyValue;
propertyValue = map.get(propertyName);
if (propertyValue == null) {
return null;
} else if (i + 1 < propertyPath.length) {
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
if (codeTable != null) {
propertyValue = codeTable.getMap(propertyValue);
}
}
} else {
try {
final Object object = propertyValue;
propertyValue = Property.getSimple(object, propertyName);
} catch (final IllegalArgumentException e) {
Logs.debug(this, "Path does not exist " + path, e);
return null;
}
}
}
return (T) propertyValue;
} else {
return getValue(fieldIndex);
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class Record method getCodeValue.
@SuppressWarnings("unchecked")
default <T> T getCodeValue(final int fieldIndex) {
Object value = getValue(fieldIndex);
if (Property.hasValue(value)) {
final FieldDefinition fieldDefinition = getFieldDefinition(fieldIndex);
final CodeTable codeTable = fieldDefinition.getCodeTable();
if (codeTable != null) {
value = codeTable.getValue(value);
}
}
return (T) value;
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class Records method getFieldByPath.
@SuppressWarnings("unchecked")
static <T> T getFieldByPath(final Record record, final String path) {
if (path == null) {
return null;
} else {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String[] propertyPath = path.split("\\.");
Object propertyValue = record;
for (int i = 0; i < propertyPath.length && propertyValue != null; i++) {
final String propertyName = propertyPath[i];
if (propertyValue instanceof Record) {
final Record recordValue = (Record) propertyValue;
if (recordValue.hasField(propertyName)) {
propertyValue = getValue(recordValue, propertyName);
if (propertyValue == null) {
return null;
} else if (i + 1 < propertyPath.length) {
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
if (codeTable != null) {
propertyValue = codeTable.getMap(Identifier.newIdentifier(propertyValue));
}
}
} else {
return null;
}
} else if (propertyValue instanceof Map) {
final Map<String, Object> map = (Map<String, Object>) propertyValue;
propertyValue = map.get(propertyName);
if (propertyValue == null) {
return null;
} else if (i + 1 < propertyPath.length) {
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(propertyName);
if (codeTable != null) {
propertyValue = codeTable.getMap(Identifier.newIdentifier(propertyValue));
}
}
} else {
try {
final Object object = propertyValue;
propertyValue = Property.getSimple(object, propertyName);
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException("Path does not exist " + path, e);
}
}
}
return (T) propertyValue;
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class AbstractRecordTableModel method toDisplayValue.
public String toDisplayValue(final int rowIndex, final int attributeIndex, final Object objectValue) {
String text;
final RecordDefinition recordDefinition = getRecordDefinition();
final String fieldName = getColumnFieldName(attributeIndex);
if (objectValue == null || fieldName == null) {
if (recordDefinition.isIdField(fieldName)) {
return "NEW";
} else {
text = "-";
}
} else {
if (objectValue instanceof Geometry) {
final Geometry geometry = (Geometry) objectValue;
return geometry.getGeometryType();
}
CodeTable codeTable = null;
if (!recordDefinition.isIdField(fieldName)) {
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
if (codeTable == null) {
text = DataTypes.toString(objectValue);
} else {
if (codeTable.isLoaded()) {
final List<Object> values = codeTable.getValues(Identifier.newIdentifier(objectValue));
if (values == null || values.isEmpty()) {
text = DataTypes.toString(objectValue);
} else {
text = Strings.toString(values);
}
} else {
if (!codeTable.isLoading()) {
final CodeTable tableToLoad = codeTable;
Invoke.background("Load " + codeTable, () -> loadCodeTable(tableToLoad));
}
text = "...";
}
}
if (text.length() == 0) {
text = "-";
}
}
return text;
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class RecordRowTableModel method toCopyValue.
@Override
public String toCopyValue(final int rowIndex, int fieldIndex, final Object recordValue) {
if (fieldIndex < this.fieldsOffset) {
return DataTypes.toString(recordValue);
} else {
fieldIndex -= this.fieldsOffset;
String text;
final RecordDefinition recordDefinition = getRecordDefinition();
final String fieldName = getColumnFieldName(fieldIndex);
if (recordValue == null) {
return null;
} else {
if (recordValue instanceof Geometry) {
final Geometry geometry = (Geometry) recordValue;
return geometry.toString();
}
CodeTable codeTable = null;
if (!recordDefinition.isIdField(fieldName)) {
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
if (codeTable == null) {
text = DataTypes.toString(recordValue);
} else {
final List<Object> values = codeTable.getValues(Identifier.newIdentifier(recordValue));
if (values == null || values.isEmpty()) {
return null;
} else {
text = Strings.toString(values);
}
}
if (text.length() == 0) {
return null;
}
}
return text;
}
}
Aggregations