Search in sources :

Example 6 with Field

use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.

the class Form method setField.

public void setField(final Field field) {
    if (field != null) {
        Invoke.later(() -> {
            final String fieldName = field.getFieldName();
            final Field oldField = this.fieldByName.put(fieldName, field);
            if (oldField != null) {
                Property.removeListener(oldField, fieldName, this.propertyChangeSetValue);
            }
            if (isDisplayable()) {
                Property.addListener(field, fieldName, this.propertyChangeSetValue);
            }
        });
    }
}
Also used : Field(com.revolsys.swing.field.Field)

Example 7 with Field

use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.

the class LayerRecordForm method validateFieldInternalDo.

protected boolean validateFieldInternalDo(final String fieldName) {
    final boolean oldValid = isFieldValid(fieldName);
    final Field field = getField(fieldName);
    boolean valid = true;
    if (!field.isFieldValid()) {
        final String message = field.getFieldValidationMessage();
        setFieldInvalid(fieldName, message);
        valid = false;
    }
    if (valid) {
        final Set<String> requiredFieldNames = getRequiredFieldNames();
        if (requiredFieldNames.contains(fieldName)) {
            boolean run = true;
            if (this.record.getState() == RecordState.NEW) {
                final RecordDefinition recordDefinition2 = getRecordDefinition();
                if (this.recordDefinition.isIdField(fieldName)) {
                    run = false;
                }
            }
            if (run) {
                final Object value = getFieldValue(fieldName);
                if (!Property.hasValue(value)) {
                    valid = addFieldError(fieldName, "Required");
                }
            }
        }
    }
    if (oldValid != valid) {
        final int tabIndex = getTabIndex(fieldName);
        updateTabValid(tabIndex);
    }
    return valid;
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 8 with Field

use of com.revolsys.swing.field.Field 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 9 with Field

use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.

the class LayerRecordForm method focusLost.

@Override
public void focusLost(final FocusEvent e) {
    Component component = e.getComponent();
    while (component != null) {
        if (component instanceof Field) {
            final Field field = (Field) component;
            this.lastFocussedFieldName = field.getFieldName();
            return;
        } else {
            component = component.getParent();
        }
    }
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 10 with Field

use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.

the class LayerRecordForm method updateReadOnlyFields.

protected void updateReadOnlyFields() {
    for (final Entry<String, Field> entry : this.fields.entrySet()) {
        final String name = entry.getKey();
        final Field field = entry.getValue();
        if (this.readOnlyFieldNames.contains(name)) {
            field.setEditable(false);
        } else {
            field.setEditable(true);
        }
    }
    if (this.fieldsTableModel != null) {
        this.fieldsTableModel.setReadOnlyFieldNames(this.readOnlyFieldNames);
    }
}
Also used : NumberTextField(com.revolsys.swing.field.NumberTextField) Field(com.revolsys.swing.field.Field) ObjectLabelField(com.revolsys.swing.field.ObjectLabelField)

Aggregations

Field (com.revolsys.swing.field.Field)43 NumberTextField (com.revolsys.swing.field.NumberTextField)15 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)15 Component (java.awt.Component)13 TextField (com.revolsys.swing.field.TextField)12 JComponent (javax.swing.JComponent)9 JTextField (javax.swing.JTextField)8 AbstractRecordQueryField (com.revolsys.swing.field.AbstractRecordQueryField)7 DateField (com.revolsys.swing.field.DateField)7 ColorChooserField (com.revolsys.swing.field.ColorChooserField)5 QueryWhereConditionField (com.revolsys.swing.field.QueryWhereConditionField)5 JXSearchField (org.jdesktop.swingx.JXSearchField)5 Container (java.awt.Container)4 JComboBox (javax.swing.JComboBox)4 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 FontChooserField (com.revolsys.swing.field.FontChooserField)3 LengthMeasureTextField (com.revolsys.swing.field.LengthMeasureTextField)3 MarkerField (com.revolsys.swing.map.component.MarkerField)3 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)3 BaseCloseable (com.revolsys.io.BaseCloseable)2