/** * Removes a node with condition from the tree. Do nothing if condition is not in the tree. * @param condition condition to remove */ public void removeCondition(AbstractCondition condition) { Node<AbstractCondition> node = getNode(condition); if (node != null) { if (node.getParent() == null) { getRootNodes().remove(node); } else { node.getParent().getChildren().remove(node); } } }
protected Boolean findHiddenPropertyValueByConditionName(String propertyName) { return conditionsTree.toConditionsList().stream() .filter(condition -> Objects.nonNull(condition.getName())) .filter(condition -> condition.getName().equals(propertyName)) .map(AbstractCondition::getHidden) .findFirst() .orElse(Boolean.FALSE); } });
/** * Creates a copy of conditionsTree. Each node of new tree contains a copy of source condition. */ public ConditionsTree createCopy() { ConditionsTree copyTree = new ConditionsTree(); List<Node<AbstractCondition>> newRootNodes = new ArrayList<>(); for (Node<AbstractCondition> rootNode : this.getRootNodes()) { Node<AbstractCondition> newRootNode = new Node<>(); newRootNodes.add(newRootNode); recursivelyCopyNode(rootNode, newRootNode); } copyTree.setRootNodes(newRootNodes); return copyTree; }
protected String createFilterXml(Filter filterComponent) { ConditionsTree tree = new ConditionsTree(); CustomCondition condition = createCustomCondition(filterComponent); tree.setRootNodes(Collections.singletonList(new Node<>(condition))); return AppBeans.get(FilterParser.class).getXml(tree, Param.ValueProperty.VALUE); }
/** * Get root conditions. * @return root conditions list */ public List<AbstractCondition> getRoots() { List<AbstractCondition> list = new ArrayList<>(); for (Node<AbstractCondition> node : getRootNodes()) { list.add(node.getData()); } return list; }
conditions = paramConditions.createCopy(); refreshConditionsDs(); conditionsTree.expandTree(); if (item != null && item instanceof GroupCondition) { Node<AbstractCondition> newNode = new Node<>(condition); Node<AbstractCondition> selectedNode = conditions.getNode(item); selectedNode.addChild(newNode); refreshConditionsDs(); conditionsTree.expand(item.getId()); } else { conditions.getRootNodes().add(new Node<>(condition)); refreshConditionsDs();
conditions = new ConditionsTree(); conditions.getRootNodes().add(new Node<>(ftsCondition));
boolean makeDefaultActionEnabled = !isDefault && !isFolder && !isSet && !isAdHocFilter && (!isGlobal || userCanEditGlobalFilter); boolean pinAppliedActionEnabled = lastAppliedFilter != null && !(lastAppliedFilter.getFilterEntity() == adHocFilter && lastAppliedFilter.getConditions().getRoots().size() == 0) && (adapter == null || Stores.isMain(metadata.getTools().getStoreName(adapter.getMetaClass()))); boolean saveAsSearchFolderActionEnabled = folderActionsEnabled && !isFolder && !hasCode; saveWithValuesAction.setEnabled(filterSavingPossible && !conditions.toConditionsList().isEmpty()); saveAsAction.setEnabled(saveAsActionEnabled); editAction.setEnabled(editActionEnabled);
@Override public void actionPerform(Component component) { conditions = new ConditionsTree(); setFilterEntity(adHocFilter); }
@Override public void setFilter(Filter filter) { this.filter = filter; addConditionHelper = new AddConditionHelper(filter, condition -> { try { addCondition(condition); } catch (Exception e) { conditions.removeCondition(condition); throw e; } }); }
/** * Get all conditions as a plain list. * @return conditions list */ public List<AbstractCondition> toConditionsList() { List<AbstractCondition> list = new ArrayList<>(); for (Node<AbstractCondition> node : toList()) { list.add(node.getData()); } return list; }
public AppliedFilter(FilterEntity filterEntity, ConditionsTree conditions) { this.filterEntity = filterEntity; this.conditions = conditions.createCopy(); }
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); } } }
if (filterEntity != null && conditions.getRoots().size() > 0) { boolean haveCorrectCondition = hasCorrectCondition(); if (!haveCorrectCondition) {
protected boolean hasEmptyGroupConditions() { for (Node<AbstractCondition> rootNode : conditions.getRootNodes()) { if (rootNode.getData() instanceof GroupCondition && rootNode.getChildren().isEmpty()) return true; } return false; }
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.format(Arrays.copyOfRange(strings, 1, strings.length)); 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); }
@Override public ConditionsTree getConditions(Filter filter, String xml) { ConditionsTree conditions = new ConditionsTree(); if (!StringUtils.isBlank(xml)) { Element root = Dom4j.readDocument(xml).getRootElement(); Element andElem = root.element("and"); if (andElem == null) throw new IllegalStateException("Root element doesn't contain 'and': " + xml); recursiveFromXml(andElem, null, filter, xml, conditions); } return conditions; }
public void removeCondition() { AbstractCondition item = conditionsDs.getItem(); if (item == null) { return; } conditions.removeCondition(item); refreshConditionsDs(); }
/** * Get node corresponding to the condition. * @param condition condition * @return node or null if not found */ @Nullable public Node<AbstractCondition> getNode(AbstractCondition condition) { for (Node<AbstractCondition> node : toList()) { if (condition.equals(node.getData())) return node; } return null; }
public void moveConditionDown() { AbstractCondition condition = conditionsDs.getItem(); Node<AbstractCondition> node = conditions.getNode(condition); List<Node<AbstractCondition>> siblings = node.getParent() == null ? conditions.getRootNodes() : node.getParent().getChildren(); int idx = siblings.indexOf(node); if (idx < siblings.size() - 1) { Node<AbstractCondition> next = siblings.get(idx + 1); siblings.set(idx + 1, node); siblings.set(idx, next); refreshConditionsDs(); conditionsTree.setSelected(condition); } }