use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class SetCodeTableId method process.
@Override
public void process(final Record source, final Record target) {
final Map<String, Object> codeTableValues = new HashMap<>();
for (final Entry<String, Converter<Record, Object>> entry : this.codeTableValueConverters.entrySet()) {
String codeTableFieldName = entry.getKey();
final Converter<Record, Object> sourceAttributeConverter = entry.getValue();
Object sourceValue = sourceAttributeConverter.convert(source);
if (sourceValue != null) {
final RecordDefinition targetRecordDefinition = target.getRecordDefinition();
String codeTableValueName = null;
final int dotIndex = codeTableFieldName.indexOf(".");
if (dotIndex != -1) {
codeTableValueName = codeTableFieldName.substring(dotIndex + 1);
codeTableFieldName = codeTableFieldName.substring(0, dotIndex);
}
final CodeTable targetCodeTable = targetRecordDefinition.getCodeTableByFieldName(codeTableFieldName);
if (targetCodeTable != null) {
if (codeTableValueName == null) {
sourceValue = targetCodeTable.getIdentifier(sourceValue);
} else {
sourceValue = targetCodeTable.getIdentifier(Collections.singletonMap(codeTableValueName, sourceValue));
}
}
}
codeTableValues.put(codeTableFieldName, sourceValue);
}
final Object codeId = this.codeTable.getIdentifier(codeTableValues);
target.setValue(this.targetFieldName, codeId);
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class MapValues method process.
@Override
public void process(final Record source, final Record target) {
final Object sourceValue = Records.getFieldByPath(source, this.sourceFieldName);
if (sourceValue != null) {
final Object targetValue = this.valueMap.get(sourceValue);
if (targetValue != null) {
final RecordDefinition targetRecordDefinition = target.getRecordDefinition();
final CodeTable codeTable = targetRecordDefinition.getCodeTableByFieldName(this.targetFieldName);
if (codeTable == null) {
target.setValue(this.targetFieldName, targetValue);
} else {
final Object codeId = codeTable.getIdentifier(targetValue);
target.setValue(this.targetFieldName, codeId);
}
}
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class Record method equalValue.
default boolean equalValue(final CharSequence fieldName, Object value) {
final FieldDefinition fieldDefinition = getFieldDefinition(fieldName);
if (fieldDefinition == null) {
return false;
} else {
final int fieldIndex = fieldDefinition.getIndex();
final Object fieldValue = getValue(fieldIndex);
final CodeTable codeTable = fieldDefinition.getCodeTable();
if (codeTable != null) {
value = codeTable.getIdentifier(value);
}
return fieldDefinition.equals(fieldValue, value);
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class FileGdbRecordStore method newTableRecordDefinition.
private RecordDefinitionImpl newTableRecordDefinition(final DETable deTable) {
synchronized (this.apiSync) {
synchronized (API_SYNC) {
final Geodatabase geodatabase = getGeodatabase();
if (geodatabase == null) {
return null;
} else {
try {
String schemaCatalogPath = deTable.getParentCatalogPath();
SpatialReference spatialReference;
if (deTable instanceof DEFeatureClass) {
final DEFeatureClass featureClass = (DEFeatureClass) deTable;
spatialReference = featureClass.getSpatialReference();
} else {
spatialReference = null;
}
PathName schemaPath = toPath(schemaCatalogPath);
final RecordStoreSchema schema = newSchema(schemaPath, spatialReference);
if (schemaPath.equals(this.defaultSchemaPath)) {
if (!(deTable instanceof DEFeatureClass)) {
schemaCatalogPath = "\\";
deTable.setCatalogPath("\\" + deTable.getName());
}
} else if (schemaPath.equals("")) {
schemaPath = this.defaultSchemaPath;
}
for (final Field field : deTable.getFields()) {
final String fieldName = field.getName();
final CodeTable codeTable = getCodeTableByFieldName(fieldName);
if (codeTable instanceof FileGdbDomainCodeTable) {
final FileGdbDomainCodeTable domainCodeTable = (FileGdbDomainCodeTable) codeTable;
field.setDomain(domainCodeTable.getDomain());
}
}
final String tableDefinition = EsriGdbXmlSerializer.toString(deTable);
try {
final Table table = geodatabase.createTable(tableDefinition, schemaCatalogPath);
geodatabase.closeTable(table);
table.delete();
final RecordDefinitionImpl recordDefinition = getRecordDefinition(PathName.newPathName(schemaPath), schemaCatalogPath, tableDefinition);
initRecordDefinition(recordDefinition);
schema.addElement(recordDefinition);
return recordDefinition;
} catch (final Throwable t) {
throw new RuntimeException("Unable to create table " + deTable.getCatalogPath(), t);
}
} finally {
releaseGeodatabase();
}
}
}
}
}
use of com.revolsys.record.code.CodeTable in project com.revolsys.open by revolsys.
the class SwingUtil method newField.
@SuppressWarnings("unchecked")
static <T extends Field> T newField(final RecordDefinition recordDefinition, final String fieldName, final boolean editable) {
Field field;
final FieldDefinition fieldDefinition = recordDefinition.getField(fieldName);
if (fieldDefinition == null) {
throw new IllegalArgumentException("Cannot find field " + fieldName);
} else {
final boolean required = fieldDefinition.isRequired();
final int length = fieldDefinition.getLength();
CodeTable codeTable;
if (recordDefinition.getIdFieldNames().contains(fieldName)) {
codeTable = null;
} else {
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
final DataType type = fieldDefinition.getDataType();
int columns = length;
if (columns <= 0) {
columns = 10;
} else if (columns > 50) {
columns = 50;
}
final Class<?> javaClass = type.getJavaClass();
if (codeTable != null) {
if (editable) {
final JComponent component = codeTable.getSwingEditor();
if (component == null) {
field = newComboBox(fieldName, codeTable, required, -1, false);
} else {
field = ((Field) component).clone();
}
} else {
field = new ObjectLabelField(fieldName, columns, codeTable);
}
} else if (!editable) {
final TextField textField = newTextField(fieldName, columns);
textField.setEditable(false);
field = textField;
} else if (Number.class.isAssignableFrom(javaClass)) {
final int scale = fieldDefinition.getScale();
final Number minValue = fieldDefinition.getMinValue();
final Number maxValue = fieldDefinition.getMaxValue();
final NumberTextField numberTextField = new NumberTextField(fieldName, type, length, scale, minValue, maxValue);
field = numberTextField;
} else if (Date.class.isAssignableFrom(javaClass)) {
field = newDateField(fieldName);
} else if (Geometry.class.isAssignableFrom(javaClass)) {
field = new ObjectLabelField(fieldName);
} else {
field = newTextField(fieldName, columns);
}
}
if (field instanceof JTextField) {
final JTextField textField = (JTextField) field;
final int preferedWidth = textField.getPreferredSize().width;
textField.setMinimumSize(new Dimension(preferedWidth, 0));
textField.setMaximumSize(new Dimension(preferedWidth, Integer.MAX_VALUE));
}
((JComponent) field).setFont(FONT);
return (T) field;
}
Aggregations