Search in sources :

Example 86 with Record

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

the class AbstractRecordQueryField method queryDo.

protected void queryDo(final int searchIndex, final String queryText) {
    if (searchIndex == this.searchIndex.get()) {
        Record selectedRecord = null;
        final Map<String, Record> allRecords = new TreeMap<>();
        for (Query query : this.queries) {
            if (allRecords.size() < this.maxResults) {
                query = // 
                query.clone().addOrderBy(this.displayField);
                final Condition whereCondition = query.getWhereCondition();
                if (whereCondition instanceof BinaryCondition) {
                    final BinaryCondition binaryCondition = (BinaryCondition) whereCondition;
                    if (binaryCondition.getOperator().equalsIgnoreCase("like")) {
                        final String likeString = "%" + queryText.toUpperCase().replaceAll("[^A-Z0-9 ]", "%") + "%";
                        Q.setValue(0, binaryCondition, likeString);
                    } else {
                        Q.setValue(0, binaryCondition, queryText);
                    }
                }
                query.setLimit(this.maxResults);
                final List<Record> records = getRecords(query);
                for (final Record record : records) {
                    if (allRecords.size() < this.maxResults) {
                        final String key = record.getString(this.displayField);
                        if (!allRecords.containsKey(key)) {
                            if (queryText.equals(key)) {
                                selectedRecord = record;
                            }
                            allRecords.put(key, record);
                        }
                    }
                }
            }
        }
        setSearchResults(searchIndex, allRecords.values(), selectedRecord);
    }
}
Also used : Condition(com.revolsys.record.query.Condition) BinaryCondition(com.revolsys.record.query.BinaryCondition) Query(com.revolsys.record.query.Query) BinaryCondition(com.revolsys.record.query.BinaryCondition) Record(com.revolsys.record.Record) TreeMap(java.util.TreeMap)

Example 87 with Record

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

the class AbstractRecordQueryField method valueChanged.

@Override
public void valueChanged(final ListSelectionEvent e) {
    if (!e.getValueIsAdjusting() && this.eventsEnabled.isTrue()) {
        try (final BaseCloseable eventsEnabled = eventsDisabled()) {
            final Record record = (Record) this.list.getSelectedValue();
            if (record != null) {
                setSelectedRecord(record);
                final Identifier identifier = record.getIdentifier();
                final String label = record.getString(this.displayField);
                this.idToDisplayMap.put(identifier, label);
                if (!DataType.equal(label, this.searchField.getText())) {
                    this.searchField.setFieldValue(label);
                }
                super.setFieldValue(identifier);
            }
            this.menu.setVisible(false);
            this.searchField.requestFocus();
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) Identifier(com.revolsys.identifier.Identifier) Record(com.revolsys.record.Record)

Example 88 with Record

use of com.revolsys.record.Record 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 89 with Record

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

the class AbstractRecordLayerRenderer method setQueryFilter.

public void setQueryFilter(final String query) {
    if (this.filter instanceof RecordDefinitionSqlFilter || this.filter == Predicates.<Record>all()) {
        Predicate<Record> filter;
        if (Property.hasValue(query)) {
            filter = new RecordDefinitionSqlFilter(this, query);
        } else {
            filter = Predicates.all();
        }
        setFilter(filter);
    }
}
Also used : Record(com.revolsys.record.Record) LayerRecord(com.revolsys.swing.map.layer.record.LayerRecord) RecordDefinitionSqlFilter(com.revolsys.swing.map.layer.record.RecordDefinitionSqlFilter)

Example 90 with Record

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

the class MergedNullValuePredicate method isHighlighted.

@Override
public boolean isHighlighted(final Component renderer, final ComponentAdapter adapter) {
    try {
        final int rowIndex = adapter.convertRowIndexToView(adapter.row);
        final int columnIndex = adapter.convertColumnIndexToView(adapter.column);
        final Record object = this.model.getRecord(rowIndex);
        final Record mergedObject = this.model.getMergedRecord();
        if (object != mergedObject) {
            final String fieldName = this.model.getColumnFieldName(columnIndex);
            final Object value = object.getValue(fieldName);
            final Object mergedValue = mergedObject.getValue(fieldName);
            if (value == null && mergedValue != null) {
                return true;
            }
        }
    } catch (final IndexOutOfBoundsException e) {
    }
    return false;
}
Also used : Record(com.revolsys.record.Record)

Aggregations

Record (com.revolsys.record.Record)198 ArrayRecord (com.revolsys.record.ArrayRecord)43 RecordReader (com.revolsys.record.io.RecordReader)34 RecordDefinition (com.revolsys.record.schema.RecordDefinition)34 Geometry (com.revolsys.geometry.model.Geometry)29 LineString (com.revolsys.geometry.model.LineString)21 Point (com.revolsys.geometry.model.Point)20 ChannelWriter (com.revolsys.io.channels.ChannelWriter)19 Identifier (com.revolsys.identifier.Identifier)17 ArrayList (java.util.ArrayList)16 FieldDefinition (com.revolsys.record.schema.FieldDefinition)15 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)13 NoSuchElementException (java.util.NoSuchElementException)13 DataType (com.revolsys.datatype.DataType)10 Query (com.revolsys.record.query.Query)9 HashMap (java.util.HashMap)9 List (java.util.List)8 LinkedHashMap (java.util.LinkedHashMap)7 Edge (com.revolsys.geometry.graph.Edge)6