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);
}
}
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);
}
}
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);
}
}
});
}
}
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);
}
}
}
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;
}
}
Aggregations