use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.
the class AddConditionHelper method _addCondition.
protected void _addCondition(AbstractConditionDescriptor descriptor, ConditionsTree conditionsTree) {
final AbstractCondition condition = descriptor.createCondition();
if (descriptor instanceof CustomConditionCreator) {
WindowInfo windowInfo = windowConfig.getWindowInfo("customConditionEditor");
Map<String, Object> params = new HashMap<>();
params.put("condition", condition);
params.put("conditionsTree", conditionsTree);
params.put("filter", filter);
final CustomConditionEditor window = (CustomConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
handler.handle(condition);
}
});
} else if (descriptor instanceof DynamicAttributesConditionCreator) {
WindowInfo windowInfo = windowConfig.getWindowInfo("dynamicAttributesConditionEditor");
Map<String, Object> params = new HashMap<>();
params.put("condition", condition);
params.put("filter", filter);
DynamicAttributesConditionEditor window = (DynamicAttributesConditionEditor) windowManager.openWindow(windowInfo, OpenType.DIALOG, params);
window.addCloseListener(actionId -> {
if (Window.COMMIT_ACTION_ID.equals(actionId)) {
handler.handle(condition);
}
});
} else {
handler.handle(condition);
}
}
use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.
the class AppliedFilter method recursivelyCreateConditionCaption.
protected void recursivelyCreateConditionCaption(Node<AbstractCondition> node, StringBuilder sb) {
AbstractCondition condition = node.getData();
if (condition.getHidden())
return;
if (condition.isGroup()) {
GroupType groupType = ((GroupCondition) condition).getGroupType();
sb.append(groupType.getLocCaption()).append("(");
List<Node<AbstractCondition>> visibleChildNodes = new ArrayList<>();
for (Node<AbstractCondition> childNode : node.getChildren()) {
AbstractCondition childCondition = childNode.getData();
if (!childCondition.getHidden() && (childCondition.isGroup() || childCondition.getParam() != null && childCondition.getParam().getValue() != null))
visibleChildNodes.add(childNode);
}
Iterator<Node<AbstractCondition>> iterator = visibleChildNodes.iterator();
while (iterator.hasNext()) {
Node<AbstractCondition> childNode = iterator.next();
recursivelyCreateConditionCaption(childNode, sb);
if (iterator.hasNext())
sb.append(", ");
}
sb.append(")");
} else {
Param param = condition.getParam();
sb.append(condition.getLocCaption()).append(" ");
if (condition.getOperator() == Op.NOT_EMPTY) {
if (BooleanUtils.isTrue((Boolean) param.getValue())) {
sb.append(messages.getMainMessage("Op.NOT_EMPTY"));
} else {
sb.append(messages.getMainMessage("Op.EMPTY"));
}
} else {
sb.append(condition.getOperationCaption()).append(" ").append(formatParamValue(param));
}
}
}
use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.
the class AppliedFilter method getText.
public String getText() {
String name = filterEntity.getName();
if (StringUtils.isBlank(name)) {
name = messages.getMainMessage(filterEntity.getCode());
}
StringBuilder sb = new StringBuilder(name);
List<Node<AbstractCondition>> visibleRootNodesWithValues = new ArrayList<>();
for (Node<AbstractCondition> rootNode : conditions.getRootNodes()) {
AbstractCondition condition = rootNode.getData();
if (!condition.getHidden() && (condition.isGroup() || condition.getParam() != null && condition.getParam().getValue() != null))
visibleRootNodesWithValues.add(rootNode);
}
Iterator<Node<AbstractCondition>> iterator = visibleRootNodesWithValues.iterator();
if (iterator.hasNext())
sb.append(": ");
while (iterator.hasNext()) {
Node<AbstractCondition> rootNode = iterator.next();
recursivelyCreateConditionCaption(rootNode, sb);
if (iterator.hasNext())
sb.append(", ");
}
return sb.toString();
}
use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.
the class ConditionsTree method recursivelyCopyNode.
protected void recursivelyCopyNode(Node<AbstractCondition> srcNode, Node<AbstractCondition> dstNode) {
AbstractCondition srcCondition = srcNode.getData();
AbstractCondition dstCondition = srcCondition.createCopy();
dstNode.setData(dstCondition);
for (Node<AbstractCondition> srcChild : srcNode.getChildren()) {
Node<AbstractCondition> dstChild = new Node<>();
dstNode.addChild(dstChild);
recursivelyCopyNode(srcChild, dstChild);
}
}
use of com.haulmont.cuba.gui.components.filter.condition.AbstractCondition in project cuba by cuba-platform.
the class RelatedEntitiesBean method getRelatedEntitiesFilterXml.
protected String getRelatedEntitiesFilterXml(MetaClass relatedMetaCLass, Collection<? extends Entity> selectedEntities, Filter component, MetaDataDescriptor descriptor) {
ConditionsTree tree = new ConditionsTree();
String filterComponentPath = ComponentsHelper.getFilterComponentPath(component);
String[] strings = ValuePathHelper.parse(filterComponentPath);
String filterComponentName = ValuePathHelper.pathSuffix(strings);
MetaClass metaClass = getFilterMetaClass(component);
String relatedPrimaryKey = metadataTools.getPrimaryKeyName(relatedMetaCLass);
AbstractCondition condition = getOptimizedCondition(getParentIds(selectedEntities), metaClass, filterComponentName, relatedPrimaryKey, descriptor);
if (condition == null) {
condition = getNonOptimizedCondition(relatedMetaCLass, getRelatedIds(selectedEntities, descriptor), component, filterComponentName, relatedPrimaryKey);
}
tree.setRootNodes(Collections.singletonList(new Node<>(condition)));
return filterParser.getXml(tree, Param.ValueProperty.VALUE);
}
Aggregations