use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class CollectionValue method getValues.
public List<Object> getValues() {
CodeTable codeTable = null;
if (this.field != null) {
final RecordDefinition recordDefinition = this.field.getRecordDefinition();
final String fieldName = this.field.getName();
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
final List<Object> values = new ArrayList<>();
for (final QueryValue queryValue : getQueryValues()) {
Object value;
if (queryValue instanceof Value) {
final Value valueWrapper = (Value) queryValue;
value = valueWrapper.getValue();
} else {
value = queryValue;
}
if (value != null) {
if (codeTable != null) {
value = codeTable.getIdentifier(value);
}
value = Value.getValue(value);
values.add(value);
}
}
return values;
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class RecordLayerTableRowSorter method getComparator.
@Override
public Comparator<?> getComparator(final int columnIndex) {
final RecordLayerTableModel model = (RecordLayerTableModel) getModel();
final String fieldName = model.getColumnFieldName(columnIndex);
final RecordDefinition recordDefinition = this.layer.getRecordDefinition();
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
if (codeTable == null) {
final Comparator<?> comparator = super.getComparator(columnIndex);
if (comparator == null) {
return this.layer.getComparator(fieldName);
} else {
return comparator;
}
} else {
return codeTable;
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class ModifiedFieldPredicate method isHighlighted.
@Override
public boolean isHighlighted(final Component renderer, final ComponentAdapter adapter) {
String toolTip = null;
boolean highlighted = false;
try {
final int rowIndex = adapter.convertRowIndexToModel(adapter.row);
final Record record = this.model.getRecord(rowIndex);
if (record instanceof LayerRecord) {
final LayerRecord layerRecord = (LayerRecord) record;
final AbstractRecordLayer layer = layerRecord.getLayer();
if (layer.isDeleted(layerRecord)) {
highlighted = false;
} else {
final int columnIndex = adapter.convertColumnIndexToModel(adapter.column);
final String fieldName = this.model.getColumnFieldName(columnIndex);
highlighted = layerRecord.isModified(fieldName);
if (highlighted) {
final RecordDefinition recordDefinition = layerRecord.getRecordDefinition();
final Object originalValue = layerRecord.getOriginalValue(fieldName);
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
String text;
if (originalValue == null) {
text = "-";
} else if (codeTable == null) {
text = DataTypes.toString(originalValue);
} else {
text = codeTable.getValue(Identifier.newIdentifier(originalValue));
if (text == null) {
text = "-";
}
}
toolTip = text;
}
if (columnIndex < this.model.getColumnFieldsOffset()) {
highlighted = false;
}
}
}
} catch (final IndexOutOfBoundsException e) {
highlighted = false;
}
final JComponent component = (JComponent) renderer;
if (toolTip != null && toolTip.length() > 100) {
toolTip = toolTip.substring(0, 100) + "...";
}
component.setToolTipText(toolTip);
return highlighted;
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class Record method setValueByPath.
@SuppressWarnings("rawtypes")
default boolean setValueByPath(final CharSequence path, final Object value) {
boolean updated = false;
final String name = path.toString();
final int dotIndex = name.indexOf(".");
String codeTableFieldName;
String codeTableValueName = null;
final RecordDefinition recordDefinition = getRecordDefinition();
if (dotIndex == -1) {
if (recordDefinition.isIdField(name)) {
codeTableFieldName = null;
} else {
codeTableFieldName = name;
}
} else {
codeTableFieldName = name.substring(0, dotIndex);
codeTableValueName = name.substring(dotIndex + 1);
}
final CodeTable codeTable = recordDefinition.getCodeTableByFieldName(codeTableFieldName);
if (codeTable == null) {
if (dotIndex != -1) {
Logs.debug(this, "Cannot get code table for " + recordDefinition.getPath() + "." + name);
return false;
}
updated = setValue(name, value);
} else if (!Property.hasValue(value)) {
updated = setValue(codeTableFieldName, null);
} else {
Object targetValue;
if (codeTableValueName == null) {
Identifier id;
if (value instanceof List) {
final List list = (List) value;
id = codeTable.getIdentifier(list.toArray());
} else {
id = codeTable.getIdentifier(value);
}
if (id == null) {
targetValue = value;
} else {
targetValue = Value.getValue(id);
}
} else {
targetValue = codeTable.getIdentifier(Collections.singletonMap(codeTableValueName, value));
}
if (targetValue == null) {
targetValue = value;
}
updated = setValue(codeTableFieldName, targetValue);
}
return updated;
}
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 CharSequence fieldName) {
Object value = getValue(fieldName);
if (Property.hasValue(value)) {
final FieldDefinition fieldDefinition = getFieldDefinition(fieldName);
final CodeTable codeTable = fieldDefinition.getCodeTable();
if (codeTable != null) {
value = codeTable.getValue(value);
}
}
return (T) value;
}
Aggregations