Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3164,6 +3164,12 @@ interface StudioComponents {
"STARTS_WITH", "ENDS_WITH", "IS_SET", "IN_LIST", "NOT_IN_LIST", "IN_INTERVAL",
"DATE_EQUALS", "IS_COLLECTION_EMPTY", "MEMBER_OF_COLLECTION",
"NOT_MEMBER_OF_COLLECTION"}, required = true),
@StudioProperty(xmlAttribute = "operationsList", category = StudioProperty.Category.GENERAL, type = StudioPropertyType.VALUES_LIST,
options = {"EQUAL", "NOT_EQUAL", "GREATER",
"GREATER_OR_EQUAL", "LESS", "LESS_OR_EQUAL", "CONTAINS", "NOT_CONTAINS",
"STARTS_WITH", "ENDS_WITH", "IS_SET", "IN_LIST", "NOT_IN_LIST", "IN_INTERVAL",
"DATE_EQUALS", "IS_COLLECTION_EMPTY", "MEMBER_OF_COLLECTION",
"NOT_MEMBER_OF_COLLECTION"}),
@StudioProperty(xmlAttribute = "operationEditable", category = StudioProperty.Category.GENERAL, type = StudioPropertyType.BOOLEAN,
defaultValue = "false"),
@StudioProperty(xmlAttribute = "operationTextVisible", category = StudioProperty.Category.LOOK_AND_FEEL, type = StudioPropertyType.BOOLEAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,19 @@ interface StudioElements {
@StudioProperty(xmlAttribute = "label", category = StudioProperty.Category.GENERAL, type = StudioPropertyType.LOCALIZED_STRING),
@StudioProperty(xmlAttribute = "labelVisible", category = StudioProperty.Category.LOOK_AND_FEEL, type = StudioPropertyType.BOOLEAN,
defaultValue = "true"),
@StudioProperty(xmlAttribute = "operation", type = StudioPropertyType.ENUMERATION,
@StudioProperty(xmlAttribute = "operation", category = StudioProperty.Category.GENERAL, type = StudioPropertyType.ENUMERATION,
classFqn = "io.jmix.flowui.component.propertyfilter.PropertyFilter$Operation",
options = {"EQUAL", "NOT_EQUAL", "GREATER",
"GREATER_OR_EQUAL", "LESS", "LESS_OR_EQUAL", "CONTAINS", "NOT_CONTAINS",
"STARTS_WITH", "ENDS_WITH", "IS_SET", "IN_LIST", "NOT_IN_LIST", "IN_INTERVAL",
"IS_COLLECTION_EMPTY", "MEMBER_OF_COLLECTION",
"DATE_EQUALS", "IS_COLLECTION_EMPTY", "MEMBER_OF_COLLECTION",
"NOT_MEMBER_OF_COLLECTION"}, required = true),
@StudioProperty(xmlAttribute = "operationsList", category = StudioProperty.Category.GENERAL, type = StudioPropertyType.VALUES_LIST,
options = {"EQUAL", "NOT_EQUAL", "GREATER",
"GREATER_OR_EQUAL", "LESS", "LESS_OR_EQUAL", "CONTAINS", "NOT_CONTAINS",
"STARTS_WITH", "ENDS_WITH", "IS_SET", "IN_LIST", "NOT_IN_LIST", "IN_INTERVAL",
"DATE_EQUALS", "IS_COLLECTION_EMPTY", "MEMBER_OF_COLLECTION",
"NOT_MEMBER_OF_COLLECTION"}),
@StudioProperty(xmlAttribute = "operationEditable", type = StudioPropertyType.BOOLEAN,
defaultValue = "false"),
@StudioProperty(xmlAttribute = "operationTextVisible", type = StudioPropertyType.BOOLEAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@
import io.micrometer.observation.Observation;
import org.springframework.lang.Nullable;

import java.util.EnumSet;
import java.util.List;
import java.util.Objects;
import java.util.function.BiConsumer;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static io.jmix.core.common.util.Preconditions.checkNotNullArgument;

Expand All @@ -61,6 +64,7 @@ public class PropertyFilter<V> extends SingleFilterComponentBase<V> {
protected DropdownButton operationSelector;

protected Operation operation;
protected List<Operation> operationsList;
protected boolean operationEditable = false;
protected boolean operationTextVisible = true;

Expand Down Expand Up @@ -103,6 +107,10 @@ && getProperty() != null) {
MetaClass metaClass = dataLoader.getContainer().getEntityMetaClass();

for (Operation operation : propertyFilterSupport.getAvailableOperations(metaClass, getProperty())) {
if (operationsList != null && !operationsList.contains(operation)) {
continue;
}

OperationChangeAction action = new OperationChangeAction(operation, this::setOperationInternal);
action.setText(getOperationText(operation));
operationSelector.addItem(operation.name(), action);
Expand Down Expand Up @@ -160,6 +168,28 @@ public Operation getOperation() {
return operation;
}

/**
* @return a list of available operations
*/
@Nullable
public List<Operation> getOperationsList() {
return operationsList;
}

/**
* Sets a list of available operations.
*
* @param operationsList a list of available operations
*/
public void setOperationsList(@Nullable List<Operation> operationsList) {
this.operationsList = operationsList;

if (operationSelector != null) {
operationSelector.removeAll();
initOperationSelectorActions(operationSelector);
}
}

/**
* Sets a filtering operation.
*
Expand All @@ -176,6 +206,18 @@ protected void setOperationInternal(Operation operation, boolean fromClient) {
return;
}

if (dataLoader != null && getProperty() != null) {
MetaClass metaClass = dataLoader.getContainer().getEntityMetaClass();
EnumSet<Operation> availableOperations = propertyFilterSupport.getAvailableOperations(metaClass, getProperty());
checkArgument(availableOperations.contains(operation),
"Operation '%s' is not available for property '%s'", operation.name(), getProperty());

if (operationsList != null) {
checkArgument(operationsList.contains(operation),
"Operation '%s' is not in operationsList", operation.name());
}
}

getQueryCondition().setOperation(propertyFilterSupport.toPropertyConditionOperation(operation));

if (operationSelector != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.jmix.flowui.xml.layout.loader.component;

import com.google.common.base.Strings;
import com.vaadin.flow.component.Component;
import io.jmix.core.MetadataTools;
import io.jmix.core.metamodel.model.MetaClass;
Expand All @@ -26,6 +27,7 @@
import io.jmix.flowui.exception.GuiDevelopmentException;
import org.dom4j.Element;

import java.util.Arrays;
import java.util.List;

import static io.jmix.core.querycondition.PropertyConditionUtils.generateParameterName;
Expand All @@ -49,6 +51,7 @@ protected void loadAttributesBeforeValueComponent() {
super.loadAttributesBeforeValueComponent();

loadString(element, "property", resultComponent::setProperty);
loadOperationsList(resultComponent, element);
loadEnum(element, Operation.class, "operation", resultComponent::setOperation);
loadBoolean(element, "operationEditable", resultComponent::setOperationEditable);
loadBoolean(element, "operationTextVisible", resultComponent::setOperationTextVisible);
Expand All @@ -73,6 +76,17 @@ protected Component generateValueComponent() {
resultComponent.getProperty(), resultComponent.getOperation()));
}

protected void loadOperationsList(PropertyFilter<?> resultComponent, Element element) {
loadString(element, "operationsList")
.map(list ->
split(list)
.stream()
.map(Operation::valueOf)
.toList()
)
.ifPresent(resultComponent::setOperationsList);
}

@SuppressWarnings({"unchecked", "rawtypes"})
protected void loadDefaultValue(PropertyFilter component, Element element) {
loadString(element, "defaultValue")
Expand Down Expand Up @@ -119,4 +133,10 @@ protected MetadataTools getMetadataTools() {
protected boolean isValueComponent(Element subElement) {
return !"tooltip".equals(subElement.getName());
}

protected List<String> split(String names) {
return Arrays.stream(names.split("[\\s,]+"))
.filter(split -> !Strings.isNullOrEmpty(split))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,36 @@
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="propertyFilterOperationsList">
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="EQUAL"/>
<xs:enumeration value="NOT_EQUAL"/>
<xs:enumeration value="GREATER"/>
<xs:enumeration value="GREATER_OR_EQUAL"/>
<xs:enumeration value="LESS"/>
<xs:enumeration value="LESS_OR_EQUAL"/>
<xs:enumeration value="CONTAINS"/>
<xs:enumeration value="NOT_CONTAINS"/>
<xs:enumeration value="STARTS_WITH"/>
<xs:enumeration value="ENDS_WITH"/>
<xs:enumeration value="IS_SET"/>
<xs:enumeration value="IN_LIST"/>
<xs:enumeration value="NOT_IN_LIST"/>
<xs:enumeration value="IN_INTERVAL"/>
<xs:enumeration value="DATE_EQUALS"/>
<xs:enumeration value="IS_COLLECTION_EMPTY"/>
<xs:enumeration value="MEMBER_OF_COLLECTION"/>
<xs:enumeration value="NOT_MEMBER_OF_COLLECTION"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>

<!-- ThemeNames-->
<xs:simpleType name="progressBarThemeNames">
<xs:union>
Expand Down Expand Up @@ -5241,6 +5271,7 @@
<xs:attribute name="property" type="xs:string" use="required"/>

<xs:attribute name="operation" type="propertyFilterOperation" use="required"/>
<xs:attribute name="operationsList" type="propertyFilterOperationsList"/>
<xs:attribute name="operationEditable" type="xs:boolean"/>
<xs:attribute name="operationTextVisible" type="xs:boolean"/>
</xs:extension>
Expand Down