mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
Operation 'is not set' removed from generic filter. Operator 'is set' with values Yes and No is used instead #PL-4488
This commit is contained in:
parent
f9083e48b2
commit
f425d5a6d2
@ -28,7 +28,6 @@ public enum Op {
|
||||
LESSER_OR_EQUAL("<=", false),
|
||||
CONTAINS("like", false),
|
||||
DOES_NOT_CONTAIN("not like", false),
|
||||
EMPTY("is null", true),
|
||||
NOT_EMPTY("is not null", true),
|
||||
STARTS_WITH("like", false),
|
||||
ENDS_WITH("like", false);
|
||||
@ -59,19 +58,19 @@ public enum Op {
|
||||
|
||||
public static EnumSet<Op> availableOps(Class javaClass) {
|
||||
if (String.class.equals(javaClass))
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, CONTAINS, DOES_NOT_CONTAIN, EMPTY, NOT_EMPTY, STARTS_WITH, ENDS_WITH);
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, CONTAINS, DOES_NOT_CONTAIN, NOT_EMPTY, STARTS_WITH, ENDS_WITH);
|
||||
|
||||
else if (Date.class.isAssignableFrom(javaClass)
|
||||
|| Number.class.isAssignableFrom(javaClass))
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, GREATER, GREATER_OR_EQUAL, LESSER, LESSER_OR_EQUAL, EMPTY, NOT_EMPTY);
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, GREATER, GREATER_OR_EQUAL, LESSER, LESSER_OR_EQUAL, NOT_EMPTY);
|
||||
|
||||
else if (Boolean.class.equals(javaClass))
|
||||
return EnumSet.of(EQUAL, NOT_EQUAL, EMPTY, NOT_EMPTY);
|
||||
return EnumSet.of(EQUAL, NOT_EQUAL, NOT_EMPTY);
|
||||
|
||||
else if (UUID.class.equals(javaClass)
|
||||
|| Enum.class.isAssignableFrom(javaClass)
|
||||
|| Entity.class.isAssignableFrom(javaClass))
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, EMPTY, NOT_EMPTY);
|
||||
return EnumSet.of(EQUAL, IN, NOT_IN, NOT_EQUAL, NOT_EMPTY);
|
||||
|
||||
else
|
||||
throw new UnsupportedOperationException("Unsupported java class: " + javaClass);
|
||||
|
@ -126,11 +126,6 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
|
||||
if (!isBlank(aclass))
|
||||
javaClass = scripting.loadClass(aclass);
|
||||
|
||||
String operatorName = element.attributeValue("operatorType", null);
|
||||
if (operatorName != null) {
|
||||
operator = Op.valueOf(operatorName);
|
||||
}
|
||||
|
||||
List<Element> paramElements = Dom4j.elements(element, "param");
|
||||
if (!paramElements.isEmpty()) {
|
||||
Element paramElem = paramElements.iterator().next();
|
||||
@ -147,16 +142,23 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
|
||||
}
|
||||
}
|
||||
|
||||
if (unary) {
|
||||
param = new Param(paramName, null, null, null, null, false, required);
|
||||
|
||||
} else {
|
||||
param = createParam();
|
||||
}
|
||||
|
||||
param = createParam();
|
||||
param.parseValue(paramElem.getText());
|
||||
param.setDefaultValue(param.getValue());
|
||||
}
|
||||
|
||||
String operatorName = element.attributeValue("operatorType", null);
|
||||
if (operatorName != null) {
|
||||
//for backward compatibility with old filters that still use EMPTY operator
|
||||
if ("EMPTY".equals(operatorName)) {
|
||||
operatorName = "NOT_EMPTY";
|
||||
if (BooleanUtils.isTrue((Boolean) param.getValue()))
|
||||
param.setValue(false);
|
||||
param.setDefaultValue(false);
|
||||
}
|
||||
|
||||
operator = Op.valueOf(operatorName);
|
||||
}
|
||||
}
|
||||
|
||||
protected AbstractCondition(AbstractConditionDescriptor descriptor) {
|
||||
@ -177,6 +179,9 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
|
||||
}
|
||||
|
||||
protected Param createParam() {
|
||||
if (unary)
|
||||
return new Param(paramName, null, null, null, null, false, required);
|
||||
|
||||
if (Strings.isNullOrEmpty(paramName)) {
|
||||
paramName = createParamName();
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.haulmont.cuba.gui.components.filter.Param;
|
||||
import com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor;
|
||||
import com.haulmont.cuba.gui.components.filter.operationedit.PropertyOperationEditor;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
@ -44,7 +45,6 @@ public class PropertyCondition extends AbstractCondition {
|
||||
public PropertyCondition(Element element, String messagesPack, String filterComponentName, Datasource datasource) {
|
||||
super(element, messagesPack, filterComponentName, datasource);
|
||||
|
||||
// this.locCaption = FilterConditionUtils.getPropertyLocCaption(datasource.getMetaClass(), name);
|
||||
String text = element.getText();
|
||||
Matcher matcher = PATTERN_NULL.matcher(text);
|
||||
if (!matcher.matches()) {
|
||||
@ -56,10 +56,8 @@ public class PropertyCondition extends AbstractCondition {
|
||||
throw new IllegalStateException("Unable to build condition from: " + text);
|
||||
}
|
||||
}
|
||||
String operatorName = element.attributeValue("operatorType", null);
|
||||
if (operatorName != null) {
|
||||
operator = Op.valueOf(operatorName);
|
||||
} else {
|
||||
|
||||
if (operator == null) {
|
||||
operator = Op.fromString(matcher.group(2));
|
||||
}
|
||||
|
||||
@ -75,6 +73,9 @@ public class PropertyCondition extends AbstractCondition {
|
||||
|
||||
@Override
|
||||
protected Param createParam() {
|
||||
if (unary)
|
||||
return new Param(paramName, Boolean.class, null, null, null, false, required);
|
||||
|
||||
if (Strings.isNullOrEmpty(paramName)) {
|
||||
paramName = createParamName();
|
||||
}
|
||||
@ -96,7 +97,8 @@ public class PropertyCondition extends AbstractCondition {
|
||||
sb.append(".id");
|
||||
}
|
||||
|
||||
sb.append(" ").append(operator.getText());
|
||||
if (operator != Op.NOT_EMPTY)
|
||||
sb.append(" ").append(operator.getText());
|
||||
|
||||
if (!operator.isUnary()) {
|
||||
if (inExpr) {
|
||||
@ -114,6 +116,10 @@ public class PropertyCondition extends AbstractCondition {
|
||||
}
|
||||
}
|
||||
|
||||
if (operator == Op.NOT_EMPTY) {
|
||||
sb.append(BooleanUtils.isTrue((Boolean) param.getValue()) ? " is not null" : " is null");
|
||||
}
|
||||
|
||||
text = sb.toString();
|
||||
}
|
||||
|
||||
@ -137,7 +143,7 @@ public class PropertyCondition extends AbstractCondition {
|
||||
if (operator.isUnary()) {
|
||||
unary = true;
|
||||
inExpr = false;
|
||||
setParam(new Param(paramName, null, null, null, null, false, required));
|
||||
setParam(new Param(paramName, Boolean.class, null, null, null, false, required));
|
||||
} else {
|
||||
unary = false;
|
||||
inExpr = operator.equals(Op.IN) || operator.equals(Op.NOT_IN);
|
||||
|
@ -126,7 +126,7 @@ public class RuntimePropCondition extends AbstractCondition {
|
||||
if (operator.isUnary()) {
|
||||
unary = true;
|
||||
inExpr = false;
|
||||
setParam(new Param(paramName, null, null, null, null, false, required));
|
||||
setParam(new Param(paramName, Boolean.class, null, null, null, false, required));
|
||||
} else {
|
||||
unary = false;
|
||||
inExpr = operator.equals(Op.IN) || operator.equals(Op.NOT_IN);
|
||||
@ -148,6 +148,25 @@ public class RuntimePropCondition extends AbstractCondition {
|
||||
return operationEditor;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Param createParam() {
|
||||
if (unary)
|
||||
return new Param(paramName, Boolean.class, null, null, null, false, required);
|
||||
|
||||
return super.createParam();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateText() {
|
||||
if (operator == Op.NOT_EMPTY) {
|
||||
if (BooleanUtils.isTrue((Boolean) param.getValue())) {
|
||||
text = text.replace(" is null ", " is not null ");
|
||||
} else if (BooleanUtils.isFalse((Boolean) param.getValue())) {
|
||||
text = text.replace(" is not null ", " is null ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getJoin() {
|
||||
return join;
|
||||
}
|
||||
@ -157,6 +176,7 @@ public class RuntimePropCondition extends AbstractCondition {
|
||||
}
|
||||
|
||||
public String getWhere() {
|
||||
updateText();
|
||||
return text;
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ public class RuntimePropConditionFrame extends ConditionFrame<RuntimePropConditi
|
||||
condition.setInExpr(Op.IN.equals(op) || Op.NOT_IN.equals(op));
|
||||
condition.setOperator(operationLookup.<Op>getValue());
|
||||
Param param;
|
||||
Class paramJavaClass = op.isUnary() ? null : javaClass;
|
||||
Class paramJavaClass = op.isUnary() ? Boolean.class : javaClass;
|
||||
if (SetValueEntity.class.isAssignableFrom(javaClass)) {
|
||||
condition.setJavaClass(String.class);
|
||||
param = new Param(paramName, paramJavaClass, null, null, condition.getDatasource(),
|
||||
|
Loading…
Reference in New Issue
Block a user