Search in sources :

Example 66 with FieldDefinition

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

Example 67 with FieldDefinition

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);
                }
            }
        }
    }
}
Also used : CodeTable(com.revolsys.record.code.CodeTable) Identifier(com.revolsys.identifier.Identifier) Query(com.revolsys.record.query.Query) In(com.revolsys.record.query.In) RecordStore(com.revolsys.record.schema.RecordStore) FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) PathName(com.revolsys.io.PathName) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 68 with FieldDefinition

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TextArea(com.revolsys.swing.field.TextArea) JTextArea(javax.swing.JTextArea) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Dimension(java.awt.Dimension) ToolBar(com.revolsys.swing.toolbar.ToolBar) VerticalLayout(org.jdesktop.swingx.VerticalLayout) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer)

Example 69 with FieldDefinition

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) LineString(com.revolsys.geometry.model.LineString) RecordDefinition(com.revolsys.record.schema.RecordDefinition) LinkedHashMap(java.util.LinkedHashMap)

Example 70 with FieldDefinition

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) LineString(com.revolsys.geometry.model.LineString)

Aggregations

FieldDefinition (com.revolsys.record.schema.FieldDefinition)133 RecordDefinition (com.revolsys.record.schema.RecordDefinition)38 DataType (com.revolsys.datatype.DataType)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 JdbcFieldDefinition (com.revolsys.jdbc.field.JdbcFieldDefinition)19 PathName (com.revolsys.io.PathName)15 Record (com.revolsys.record.Record)15 ArrayList (java.util.ArrayList)15 Geometry (com.revolsys.geometry.model.Geometry)13 CodeTable (com.revolsys.record.code.CodeTable)9 Query (com.revolsys.record.query.Query)8 LineString (com.revolsys.geometry.model.LineString)7 ArrayRecord (com.revolsys.record.ArrayRecord)7 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)7 SQLException (java.sql.SQLException)7 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 IOException (java.io.IOException)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 BadLocationException (javax.swing.text.BadLocationException)4