Search in sources :

Example 1 with BaseDialog

use of com.revolsys.swing.component.BaseDialog 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 2 with BaseDialog

use of com.revolsys.swing.component.BaseDialog in project com.revolsys.open by revolsys.

the class AbstractRecordLayer method showForm.

public void showForm(final LayerRecord record, final String fieldName) {
    Invoke.later(() -> {
        if (record != null && !record.isDeleted()) {
            final LayerRecord proxiedRecord = getRecordProxied(record);
            final int index;
            Window window;
            synchronized (this.formRecords) {
                index = proxiedRecord.indexOf(this.formRecords);
                if (index == -1) {
                    window = null;
                } else {
                    window = this.formWindows.get(index);
                }
            }
            Component form = null;
            if (window == null) {
                form = newForm(record);
                if (form != null) {
                    final String title = LayerRecordForm.getTitle(record);
                    final Window parent = SwingUtil.getActiveWindow();
                    window = new BaseDialog(parent, title);
                    window.add(form);
                    window.pack();
                    if (form instanceof LayerRecordForm) {
                        final LayerRecordForm recordForm = (LayerRecordForm) form;
                        window.addWindowListener(recordForm);
                        if (record.getState() != RecordState.NEW) {
                            if (!isCanEditRecords()) {
                                recordForm.setEditable(false);
                            }
                        }
                    }
                    SwingUtil.autoAdjustPosition(window);
                    synchronized (this.formRecords) {
                        if (proxiedRecord.isDeleted()) {
                            window.dispose();
                            return;
                        } else {
                            this.formRecords.add(proxiedRecord);
                            this.formComponents.add(form);
                            this.formWindows.add(window);
                        }
                    }
                    window.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosed(final WindowEvent e) {
                            removeForm(record);
                        }

                        @Override
                        public void windowClosing(final WindowEvent e) {
                            removeForm(record);
                        }
                    });
                    SwingUtil.setVisible(window, true);
                    window.requestFocus();
                    if (proxiedRecord.isDeleted()) {
                        window.setVisible(false);
                    }
                }
            } else {
                SwingUtil.setVisible(window, true);
                window.requestFocus();
                final Component component = window.getComponent(0);
                if (component instanceof JScrollPane) {
                    final JScrollPane scrollPane = (JScrollPane) component;
                    form = scrollPane.getComponent(0);
                }
            }
            if (form instanceof LayerRecordForm) {
                final LayerRecordForm recordForm = (LayerRecordForm) form;
                recordForm.setFieldFocussed(fieldName);
            }
        }
    });
}
Also used : Window(java.awt.Window) JScrollPane(javax.swing.JScrollPane) BaseDialog(com.revolsys.swing.component.BaseDialog) LayerRecordForm(com.revolsys.swing.map.form.LayerRecordForm) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) LineString(com.revolsys.geometry.model.LineString) Component(java.awt.Component) JComponent(javax.swing.JComponent) Point(com.revolsys.geometry.model.Point)

Aggregations

BaseDialog (com.revolsys.swing.component.BaseDialog)2 Window (java.awt.Window)2 LineString (com.revolsys.geometry.model.LineString)1 Point (com.revolsys.geometry.model.Point)1 Record (com.revolsys.record.Record)1 RecordState (com.revolsys.record.RecordState)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 Field (com.revolsys.swing.field.Field)1 NumberTextField (com.revolsys.swing.field.NumberTextField)1 ObjectLabelField (com.revolsys.swing.field.ObjectLabelField)1 LayerRecordForm (com.revolsys.swing.map.form.LayerRecordForm)1 AbstractRecordLayer (com.revolsys.swing.map.layer.record.AbstractRecordLayer)1 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)1 Component (java.awt.Component)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 List (java.util.List)1 JComponent (javax.swing.JComponent)1 JScrollPane (javax.swing.JScrollPane)1