Search in sources :

Example 21 with CodeTable

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;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) ArrayList(java.util.ArrayList) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 22 with CodeTable

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;
    }
}
Also used : RecordLayerTableModel(com.revolsys.swing.map.layer.record.table.model.RecordLayerTableModel) CodeTable(com.revolsys.record.code.CodeTable) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 23 with 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;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) JComponent(javax.swing.JComponent) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) Record(com.revolsys.record.Record) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 24 with CodeTable

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;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) TypedIdentifier(com.revolsys.identifier.TypedIdentifier) Identifier(com.revolsys.identifier.Identifier) ListIdentifier(com.revolsys.identifier.ListIdentifier) ArrayList(java.util.ArrayList) List(java.util.List) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 25 with CodeTable

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;
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) FieldDefinition(com.revolsys.record.schema.FieldDefinition)

Aggregations

CodeTable (com.revolsys.record.code.CodeTable)30 RecordDefinition (com.revolsys.record.schema.RecordDefinition)15 FieldDefinition (com.revolsys.record.schema.FieldDefinition)9 Identifier (com.revolsys.identifier.Identifier)6 ArrayList (java.util.ArrayList)5 Geometry (com.revolsys.geometry.model.Geometry)4 DataType (com.revolsys.datatype.DataType)3 PathName (com.revolsys.io.PathName)3 BetweenOperatorNode (com.akiban.sql.parser.BetweenOperatorNode)2 BinaryArithmeticOperatorNode (com.akiban.sql.parser.BinaryArithmeticOperatorNode)2 BinaryLogicalOperatorNode (com.akiban.sql.parser.BinaryLogicalOperatorNode)2 BinaryOperatorNode (com.akiban.sql.parser.BinaryOperatorNode)2 CastNode (com.akiban.sql.parser.CastNode)2 ColumnReference (com.akiban.sql.parser.ColumnReference)2 ConstantNode (com.akiban.sql.parser.ConstantNode)2 InListOperatorNode (com.akiban.sql.parser.InListOperatorNode)2 IsNullNode (com.akiban.sql.parser.IsNullNode)2 LikeEscapeOperatorNode (com.akiban.sql.parser.LikeEscapeOperatorNode)2 NotNode (com.akiban.sql.parser.NotNode)2 NumericConstantNode (com.akiban.sql.parser.NumericConstantNode)2