Search in sources :

Example 16 with Field

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

the class FieldFilterPanel method addListeners.

private void addListeners(final JComponent component) {
    if (component instanceof AbstractRecordQueryField) {
        final AbstractRecordQueryField queryField = (AbstractRecordQueryField) component;
        queryField.addPropertyChangeListener("selectedRecord", this);
    } else if (component instanceof JXSearchField) {
        final JXSearchField searchTextField = (JXSearchField) component;
        searchTextField.addActionListener(this);
    } else if (component instanceof JTextComponent) {
        final JTextComponent searchTextField = (JTextComponent) component;
        searchTextField.getDocument().addDocumentListener(this);
    } else if (component instanceof DateField) {
        final DateField dateField = (DateField) component;
        dateField.addActionListener(this);
    }
    if (component instanceof Field) {
        final Field field = (Field) component;
        final String fieldName = field.getFieldName();
        Property.addListener(field, fieldName, this);
    }
}
Also used : JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField) JXSearchField(org.jdesktop.swingx.JXSearchField) JTextComponent(javax.swing.text.JTextComponent) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) DateField(com.revolsys.swing.field.DateField)

Example 17 with Field

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

the class FieldFilterPanel method updateCondition.

public void updateCondition() {
    if (!(this.searchField instanceof Field) || ((Field) this.searchField).isFieldValid()) {
        final Object searchValue = getSearchValue();
        this.lastValue = searchValue;
        Condition condition = null;
        final String searchOperator = getSearchOperator();
        if ("IS NULL".equalsIgnoreCase(searchOperator)) {
            condition = Q.isNull(this.field);
        } else if ("IS NOT NULL".equalsIgnoreCase(searchOperator)) {
            condition = Q.isNotNull(this.field);
        } else if (this.field != null) {
            if (Property.hasValue(DataTypes.toString(searchValue))) {
                if ("Like".equalsIgnoreCase(searchOperator)) {
                    final String searchText = DataTypes.toString(searchValue);
                    if (Property.hasValue(searchText)) {
                        condition = Q.iLike(this.field, "%" + searchText + "%");
                    }
                } else {
                    Object value = null;
                    if (this.codeTable == null) {
                        value = this.layer.getValidSearchValue(this.field, searchValue);
                    } else {
                        value = this.codeTable.getIdentifier(searchValue);
                    }
                    if (value != null) {
                        condition = Q.binary(this.field, searchOperator, value);
                    }
                }
            }
        }
        setSearchFilter(condition);
    }
}
Also used : Condition(com.revolsys.record.query.Condition) BinaryCondition(com.revolsys.record.query.BinaryCondition) RightUnaryCondition(com.revolsys.record.query.RightUnaryCondition) JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField)

Example 18 with Field

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

the class FieldFilterPanel method setFilter.

public void setFilter(final Condition filter) {
    if (!this.fieldNames.isEmpty()) {
        Invoke.later(() -> {
            try (BaseCloseable settingFilter = this.settingFilter.closeable(true)) {
                setSearchFilter(filter);
                boolean simple = false;
                if (Property.isEmpty(filter)) {
                    final Field searchField = (Field) this.searchField;
                    if (searchField != null) {
                        searchField.setFieldValue(null);
                    }
                    setSearchOperator("=");
                    simple = true;
                } else if (filter instanceof Not) {
                    final Not not = (Not) filter;
                    final QueryValue condition = not.getValue();
                    if (condition instanceof IsNull) {
                        final IsNull isNull = (IsNull) condition;
                        final IsNotNull isNotNull = new IsNotNull(isNull.getValue());
                        setFilter(isNotNull);
                        return;
                    }
                } else if (filter instanceof ILike) {
                    final ILike equal = (ILike) filter;
                    final QueryValue leftCondition = equal.getLeft();
                    final QueryValue rightCondition = equal.getRight();
                    if (leftCondition instanceof Column && rightCondition instanceof Value) {
                        final Column column = (Column) leftCondition;
                        final String searchFieldName = column.getName();
                        setSearchFieldName(searchFieldName);
                        if (setSearchOperator("Like")) {
                            final Value value = (Value) rightCondition;
                            final Object searchValue = value.getValue();
                            String searchText = DataTypes.toString(searchValue);
                            if (Property.hasValue(searchText)) {
                                setSearchField(this.searchTextField);
                                searchText = searchText.replaceAll("%", "");
                                final String previousSearchText = this.searchTextField.getText();
                                if (!DataType.equal(searchText, previousSearchText)) {
                                    this.searchTextField.setFieldValue(searchText);
                                }
                                simple = true;
                            } else {
                                setSearchFilter(null);
                            }
                        }
                    }
                } else if (filter instanceof BinaryCondition) {
                    final BinaryCondition condition = (BinaryCondition) filter;
                    final QueryValue leftCondition = condition.getLeft();
                    final QueryValue rightCondition = condition.getRight();
                    if (leftCondition instanceof Column && rightCondition instanceof Value) {
                        final Column column = (Column) leftCondition;
                        final String searchFieldName = column.getName();
                        setSearchFieldName(searchFieldName);
                        final String searchOperator = condition.getOperator();
                        if (setSearchOperator(searchOperator)) {
                            final Value value = (Value) rightCondition;
                            final Object searchValue = value.getValue();
                            final String searchText = DataTypes.toString(searchValue);
                            final Field searchField = (Field) this.searchField;
                            final Object oldValue = searchField.getFieldValue();
                            if (!searchText.equalsIgnoreCase(DataTypes.toString(oldValue))) {
                                searchField.setFieldValue(searchText);
                            }
                            simple = true;
                        }
                    }
                } else if (filter instanceof RightUnaryCondition) {
                    final RightUnaryCondition condition = (RightUnaryCondition) filter;
                    final String operator = condition.getOperator();
                    if (filter instanceof IsNull || filter instanceof IsNotNull) {
                        final QueryValue leftValue = condition.getValue();
                        if (leftValue instanceof Column) {
                            final Column column = (Column) leftValue;
                            final String searchFieldName = column.getName();
                            setSearchFieldName(searchFieldName);
                            if (setSearchOperator(operator)) {
                                simple = true;
                            }
                        }
                    }
                }
                if (simple) {
                    this.whereLabel.setVisible(false);
                    if (this.nameField != null) {
                        this.nameField.setVisible(true);
                    }
                    if (this.operatorField != null) {
                        this.operatorField.setVisible(true);
                    }
                    this.searchFieldPanel.setVisible(true);
                } else {
                    String filterText = filter.toString();
                    if (filterText.length() > 40) {
                        filterText = filterText.substring(0, 40) + "...";
                    }
                    this.whereLabel.setText(filterText);
                    this.whereLabel.setToolTipText(filterText);
                    this.whereLabel.setVisible(true);
                    if (this.nameField != null) {
                        this.nameField.setVisible(false);
                    }
                    this.operatorField.setVisible(false);
                    this.searchFieldPanel.setVisible(false);
                }
            }
        });
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) ILike(com.revolsys.record.query.ILike) QueryValue(com.revolsys.record.query.QueryValue) JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField) RightUnaryCondition(com.revolsys.record.query.RightUnaryCondition) Not(com.revolsys.record.query.Not) IsNotNull(com.revolsys.record.query.IsNotNull) Column(com.revolsys.record.query.Column) BinaryCondition(com.revolsys.record.query.BinaryCondition) QueryValue(com.revolsys.record.query.QueryValue) GlobalBooleanValue(com.revolsys.value.GlobalBooleanValue) Value(com.revolsys.record.query.Value) IsNull(com.revolsys.record.query.IsNull)

Example 19 with Field

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

the class RecordLayerFields method getFactory.

@SuppressWarnings("unchecked")
private static Supplier<Field> getFactory(final ObjectWithProperties properties, final String propertyName, final String fieldName) {
    final Map<String, Object> factories = getFieldFactoryMap(properties, propertyName);
    final Object factoryDef = factories.get(fieldName);
    if (factoryDef == null) {
        return null;
    } else if (factoryDef instanceof Supplier) {
        return (Supplier<Field>) factoryDef;
    } else {
        final ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        final String script = factoryDef.toString();
        try {
            final SimpleBindings bindings = new SimpleBindings();
            bindings.put("object", properties);
            bindings.put("fieldName", fieldName);
            return (Supplier<Field>) engine.eval(script, bindings);
        } catch (final ScriptException e) {
            throw Exceptions.wrap(e);
        }
    }
}
Also used : Field(com.revolsys.swing.field.Field) ScriptException(javax.script.ScriptException) SimpleBindings(javax.script.SimpleBindings) ScriptEngineManager(javax.script.ScriptEngineManager) Supplier(java.util.function.Supplier) ScriptEngine(javax.script.ScriptEngine)

Example 20 with Field

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

the class BaseStylePanel method addField.

protected Field addField(final JPanel container, final Object object, final String fieldName) {
    final Class<?> fieldClass = Property.getClass(object, fieldName);
    if (fieldClass == null) {
        return null;
    } else {
        final Object value = Property.get(object, fieldName);
        SwingUtil.addLabel(container, fieldName);
        final Field field = newField(fieldName, fieldClass, value);
        setField(field);
        if (this.readOnlyFieldNames.contains(fieldName)) {
            field.setEditable(false);
        }
        if (field instanceof JTextArea) {
            container.add(new JScrollPane((Component) field));
        } else {
            container.add((Component) field);
        }
        Property.addListener(field, "fieldValue", this);
        Property.addListener(field, fieldName, this);
        if (object instanceof LayerRenderer) {
            this.rendererFieldNames.add(fieldName);
        }
        return field;
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) LengthMeasureTextField(com.revolsys.swing.field.LengthMeasureTextField) FontChooserField(com.revolsys.swing.field.FontChooserField) MarkerField(com.revolsys.swing.map.component.MarkerField) JTextField(javax.swing.JTextField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) ColorChooserField(com.revolsys.swing.field.ColorChooserField) JTextArea(javax.swing.JTextArea) LayerRenderer(com.revolsys.swing.map.layer.LayerRenderer) Component(java.awt.Component)

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