Search in sources :

Example 1 with RecordState

use of com.revolsys.record.RecordState in project com.revolsys.open by revolsys.

the class AbstractJdbcRecordStore method deleteRecord.

@Override
public boolean deleteRecord(final Record record) {
    final RecordState state = RecordState.DELETED;
    write(record, state);
    return true;
}
Also used : RecordState(com.revolsys.record.RecordState)

Example 2 with RecordState

use of com.revolsys.record.RecordState in project com.revolsys.open by revolsys.

the class LayerRecordForm method propertyChange.

@Override
public void propertyChange(final PropertyChangeEvent event) {
    final String propertyName = event.getPropertyName();
    final AbstractRecordLayer layer = getLayer();
    if (layer != null) {
        final LayerRecord record = getRecord();
        if (record != null) {
            final RecordState state = record.getState();
            if (!state.equals(RecordState.DELETED)) {
                final Object source = event.getSource();
                if (this.geometryCoordinatesPanel != null && source == this.geometryCoordinatesPanel.getTable().getModel()) {
                    if (propertyName.equals("geometry")) {
                        record.setGeometryValue((Geometry) event.getNewValue());
                    }
                } else if (source == layer) {
                    if (AbstractRecordLayer.RECORDS_CHANGED.equals(propertyName)) {
                        setRecord(record);
                    } else if (AbstractRecordLayer.RECORDS_DELETED.equals(propertyName)) {
                        @SuppressWarnings("unchecked") final List<Record> deletedRecords = (List<Record>) event.getNewValue();
                        if (layer.isDeleted(record) || record.contains(deletedRecords)) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                            setRecord(record);
                            return;
                        }
                    } else if (AbstractRecordLayer.RECORD_UPDATED.equals(propertyName)) {
                        if (record.isDeleted()) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                            setRecord(record);
                        }
                    } else if ("editable".equals(propertyName)) {
                        setEditable(layer.isEditable());
                    }
                } else if (source instanceof Field) {
                    final Field field = (Field) source;
                    final String fieldName = field.getFieldName();
                    final Object fieldValue = field.getFieldValue();
                    final Object recordValue = this.record.getValue(fieldName);
                    if (!DataType.equal(recordValue, fieldValue)) {
                        boolean equal = false;
                        if (fieldValue instanceof String) {
                            final String string = (String) fieldValue;
                            if (!Property.hasValue(string) && recordValue == null) {
                                equal = true;
                            }
                        }
                        if (!equal && layer.isEditable() && (state == RecordState.NEW && layer.isCanAddRecords() || layer.isCanEditRecords())) {
                            record.setValueByPath(fieldName, fieldValue);
                        }
                    }
                } else {
                    if (isSame(source)) {
                        if (getRecordDefinition().getIdFieldNames().contains(propertyName)) {
                            Invoke.later(() -> {
                                final String title = getTitle(record);
                                final BaseDialog dialog = (BaseDialog) SwingUtil.getWindowAncestor(this);
                                if (dialog != null) {
                                    dialog.setTitle(title);
                                }
                            });
                        }
                        if (record.isDeleted()) {
                            final Window window = SwingUtilities.getWindowAncestor(this);
                            SwingUtil.setVisible(window, false);
                        } else if (Record.EVENT_RECORD_CHANGED.equals(propertyName)) {
                            setValues(record);
                            return;
                        }
                        final Object value = event.getNewValue();
                        final RecordDefinition recordDefinition = getRecordDefinition();
                        if ("qaMessagesUpdated".equals(propertyName)) {
                            updateErrors();
                        } else if (recordDefinition.hasField(propertyName)) {
                            setFieldValue(propertyName, value, isFieldValidationEnabled());
                        }
                        fireButtonPropertyChanges();
                        repaint();
                    }
                }
            }
        }
    }
}
Also used : Window(java.awt.Window) BaseDialog(com.revolsys.swing.component.BaseDialog) RecordState(com.revolsys.record.RecordState) RecordDefinition(com.revolsys.record.schema.RecordDefinition) NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) AbstractRecordLayer(com.revolsys.swing.map.layer.record.AbstractRecordLayer) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) Record(com.revolsys.record.Record) List(java.util.List) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord)

Example 3 with RecordState

use of com.revolsys.record.RecordState in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method internalSaveChanges.

protected boolean internalSaveChanges(final RecordLayerErrors errors, final LayerRecord record) {
    final RecordState originalState = record.getState();
    final LayerRecord layerRecord = getProxiedRecord(record);
    final boolean saved = saveChangesDo(errors, layerRecord);
    if (saved) {
        postSaveChanges(originalState, layerRecord);
    }
    return saved;
}
Also used : RecordState(com.revolsys.record.RecordState)

Example 4 with RecordState

use of com.revolsys.record.RecordState in project com.revolsys.open by revolsys.

the class RecordStoreLayerTest method assertRecordState.

public void assertRecordState(final Record record, final RecordState expectedState) {
    final RecordState actualState = record.getState();
    Assert.assertEquals("Record State", expectedState, actualState);
}
Also used : RecordState(com.revolsys.record.RecordState)

Example 5 with RecordState

use of com.revolsys.record.RecordState in project com.revolsys.open by revolsys.

the class RecordRowTableModel method isCellEditable.

protected boolean isCellEditable(final int rowIndex, final int columnIndex, final Record record) {
    final RecordState state = record.getState();
    if (state != RecordState.INITIALIZING && state != RecordState.DELETED) {
        final String fieldName = getColumnFieldName(rowIndex, columnIndex);
        if (fieldName != null) {
            if (!isReadOnly(fieldName)) {
                final RecordDefinition recordDefinition = getRecordDefinition();
                final Class<?> fieldClass = recordDefinition.getFieldClass(fieldName);
                if (!Geometry.class.isAssignableFrom(fieldClass)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) RecordState(com.revolsys.record.RecordState) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

RecordState (com.revolsys.record.RecordState)10 RecordDefinition (com.revolsys.record.schema.RecordDefinition)2 Geometry (com.revolsys.geometry.model.Geometry)1 BaseCloseable (com.revolsys.io.BaseCloseable)1 Record (com.revolsys.record.Record)1 RecordStore (com.revolsys.record.schema.RecordStore)1 BaseDialog (com.revolsys.swing.component.BaseDialog)1 Field (com.revolsys.swing.field.Field)1 NumberTextField (com.revolsys.swing.field.NumberTextField)1 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 Window (java.awt.Window)1 BatchUpdateException (java.sql.BatchUpdateException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 DataAccessException (org.springframework.dao.DataAccessException)1