use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.
the class ConditionDescriptorsTreeBuilder method build.
@Override
public Tree<AbstractConditionDescriptor> build() {
Messages messages = AppBeans.get(Messages.class);
String messagesPack = filter.getFrame().getMessagesPack();
CollectionDatasource datasource = filter.getDatasource();
Tree<AbstractConditionDescriptor> tree = new Tree<>();
List<AbstractConditionDescriptor> propertyDescriptors = new ArrayList<>();
List<AbstractConditionDescriptor> customDescriptors = new ArrayList<>();
boolean propertiesExplicitlyDefined = false;
if (filter.getXmlDescriptor() != null) {
for (Element element : Dom4j.elements(filter.getXmlDescriptor())) {
AbstractConditionDescriptor conditionDescriptor;
if ("properties".equals(element.getName())) {
addMultiplePropertyDescriptors(element, propertyDescriptors, filter);
propertiesExplicitlyDefined = true;
} else if ("property".equals(element.getName())) {
conditionDescriptor = new PropertyConditionDescriptor(element, messagesPack, filterComponentName, datasource);
propertyDescriptors.add(conditionDescriptor);
propertiesExplicitlyDefined = true;
} else if ("custom".equals(element.getName())) {
conditionDescriptor = new CustomConditionDescriptor(element, messagesPack, filterComponentName, datasource);
customDescriptors.add(conditionDescriptor);
propertiesExplicitlyDefined = true;
} else {
throw new UnsupportedOperationException("Element not supported: " + element.getName());
}
}
}
if (!propertiesExplicitlyDefined) {
addMultiplePropertyDescriptors(".*", "", propertyDescriptors, filter);
}
propertyDescriptors.sort(new ConditionDescriptorComparator());
customDescriptors.sort(new ConditionDescriptorComparator());
HeaderConditionDescriptor propertyHeaderDescriptor = new HeaderConditionDescriptor("propertyConditions", messages.getMainMessage("filter.addCondition.propertyConditions"), filterComponentName, datasource);
HeaderConditionDescriptor customHeaderDescriptor = new HeaderConditionDescriptor("customConditions", messages.getMainMessage("filter.addCondition.customConditions"), filterComponentName, datasource);
Node<AbstractConditionDescriptor> propertyHeaderNode = new Node<>(propertyHeaderDescriptor);
Node<AbstractConditionDescriptor> customHeaderNode = new Node<>(customHeaderDescriptor);
int currentDepth = 0;
for (AbstractConditionDescriptor propertyDescriptor : propertyDescriptors) {
MetaClass propertyDsMetaClass = propertyDescriptor.getDatasourceMetaClass();
MetaPropertyPath propertyPath = propertyDsMetaClass.getPropertyPath(propertyDescriptor.getName());
if (propertyPath == null) {
log.error("Property path for {} of metaClass {} not found", propertyDescriptor.getName(), propertyDsMetaClass.getName());
continue;
}
MetaProperty metaProperty = propertyPath.getMetaProperty();
MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(propertyPath);
if (isPropertyAllowed(propertyEnclosingMetaClass, metaProperty) && !excludedProperties.contains(metaProperty.getName())) {
Node<AbstractConditionDescriptor> node = new Node<>(propertyDescriptor);
propertyHeaderNode.addChild(node);
if (currentDepth < hierarchyDepth) {
recursivelyFillPropertyDescriptors(node, currentDepth);
}
}
}
for (AbstractConditionDescriptor customDescriptor : customDescriptors) {
Node<AbstractConditionDescriptor> node = new Node<>(customDescriptor);
customHeaderNode.addChild(node);
}
List<Node<AbstractConditionDescriptor>> rootNodes = new ArrayList<>();
rootNodes.add(propertyHeaderNode);
if (!customDescriptors.isEmpty())
rootNodes.add(customHeaderNode);
if (!hideCustomConditions && security.isSpecificPermitted(CUSTOM_CONDITIONS_PERMISSION)) {
rootNodes.add(new Node<>(new CustomConditionCreator(filterComponentName, datasource)));
}
if (!hideDynamicAttributes && !dynamicAttributes.getAttributesForMetaClass(datasource.getMetaClass()).isEmpty()) {
rootNodes.add(new Node<>(new DynamicAttributesConditionCreator(filterComponentName, datasource, "")));
}
if (FtsConfigHelper.getEnabled()) {
rootNodes.add(new Node<>(new FtsConditionDescriptor(filterComponentName, datasource)));
}
tree.setRootNodes(rootNodes);
return tree;
}
use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.
the class ConditionDescriptorsTreeBuilder method recursivelyFillPropertyDescriptors.
protected void recursivelyFillPropertyDescriptors(Node<AbstractConditionDescriptor> parentNode, int currentDepth) {
currentDepth++;
List<AbstractConditionDescriptor> descriptors = new ArrayList<>();
MetaClass filterMetaClass = filter.getDatasource().getMetaClass();
String propertyId = parentNode.getData().getName();
MetaPropertyPath mpp = filterMetaClass.getPropertyPath(propertyId);
if (mpp == null) {
throw new RuntimeException("Unable to find property " + propertyId);
}
MetaProperty metaProperty = mpp.getMetaProperty();
if (metaProperty.getRange().isClass() && (metadataTools.getCrossDataStoreReferenceIdProperty(storeName, metaProperty) == null)) {
MetaClass childMetaClass = metaProperty.getRange().asClass();
for (MetaProperty property : childMetaClass.getProperties()) {
if (isPropertyAllowed(childMetaClass, property)) {
String propertyPath = mpp.toString() + "." + property.getName();
if (excludedProperties.contains(propertyPath))
continue;
PropertyConditionDescriptor childPropertyConditionDescriptor = new PropertyConditionDescriptor(propertyPath, null, filter.getFrame().getMessagesPack(), filterComponentName, filter.getDatasource());
descriptors.add(childPropertyConditionDescriptor);
}
}
}
descriptors.sort(new ConditionDescriptorComparator());
for (AbstractConditionDescriptor descriptor : descriptors) {
Node<AbstractConditionDescriptor> newNode = new Node<>(descriptor);
parentNode.addChild(newNode);
if (currentDepth < hierarchyDepth) {
recursivelyFillPropertyDescriptors(newNode, currentDepth);
}
}
if (metaProperty.getRange().isClass()) {
MetaClass childMetaClass = metaProperty.getRange().asClass();
if (!dynamicAttributes.getAttributesForMetaClass(childMetaClass).isEmpty()) {
DynamicAttributesConditionCreator descriptor = new DynamicAttributesConditionCreator(filterComponentName, filter.getDatasource(), propertyId);
Node<AbstractConditionDescriptor> newNode = new Node<>(descriptor);
parentNode.addChild(newNode);
}
}
}
use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.
the class FilterEditor method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
if (Boolean.TRUE.equals(useShortConditionForm)) {
setCaption(messages.getMainMessage("filter.editor.captionShortForm"));
}
getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")).setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true);
filterEntity = (FilterEntity) params.get("filterEntity");
if (filterEntity == null) {
throw new RuntimeException("Filter entity was not passed to filter editor");
}
filter = (Filter) params.get("filter");
ConditionsTree paramConditions = (ConditionsTree) params.get("conditions");
conditions = paramConditions.createCopy();
refreshConditionsDs();
conditionsTree.expandTree();
if (!messages.getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) {
filterName.setValue(filterEntity.getName());
}
availableForAllCb.setValue(filterEntity.getUser() == null);
defaultCb.setValue(filterEntity.getIsDefault());
applyDefaultCb.setValue(filterEntity.getApplyDefault());
globalDefaultCb.setValue(filterEntity.getGlobalDefault());
if (filterEntity.getUser() != null) {
globalDefaultCb.setEnabled(false);
}
if (!userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) {
availableForAllCb.setVisible(false);
availableForAllLabel.setVisible(false);
globalDefaultCb.setVisible(false);
globalDefaultLabel.setVisible(false);
}
availableForAllCb.addValueChangeListener(e -> {
Boolean isFilterAvailableForAll = (Boolean) e.getValue();
globalDefaultCb.setEnabled(isFilterAvailableForAll);
if (!isFilterAvailableForAll) {
globalDefaultCb.setValue(null);
}
});
Configuration configuration = AppBeans.get(Configuration.NAME);
boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : configuration.getConfig(ClientConfig.class).getGenericFilterManualApplyRequired();
if (!manualApplyRequired) {
applyDefaultCb.setVisible(manualApplyRequired);
applyDefaultLabel.setVisible(manualApplyRequired);
}
if (filterEntity.getFolder() != null) {
defaultCb.setVisible(false);
defaultLabel.setVisible(false);
}
conditionsDs.addItemChangeListener(e -> {
if (!treeItemChangeListenerEnabled) {
return;
}
// commit previously selected condition
if (activeConditionFrame != null) {
List<Validatable> validatables = new ArrayList<>();
Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame);
for (Component frameComponent : frameComponents) {
if (frameComponent instanceof Validatable) {
validatables.add((Validatable) frameComponent);
}
}
if (validate(validatables)) {
activeConditionFrame.commit();
} else {
treeItemChangeListenerEnabled = false;
conditionsTree.setSelected(e.getPrevItem());
treeItemChangeListenerEnabled = true;
return;
}
}
if (e.getItem() == null) {
activeConditionFrame = null;
} else {
if (e.getItem() instanceof PropertyCondition) {
activeConditionFrame = propertyConditionFrame;
} else if (e.getItem() instanceof DynamicAttributesCondition) {
activeConditionFrame = dynamicAttributesConditionFrame;
} else if (e.getItem() instanceof CustomCondition) {
activeConditionFrame = customConditionFrame;
} else if (e.getItem() instanceof GroupCondition) {
activeConditionFrame = groupConditionFrame;
} else if (e.getItem() instanceof FtsCondition) {
activeConditionFrame = ftsConditionFrame;
} else {
log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found");
}
}
propertyConditionFrame.setVisible(false);
customConditionFrame.setVisible(false);
dynamicAttributesConditionFrame.setVisible(false);
groupConditionFrame.setVisible(false);
ftsConditionFrame.setVisible(false);
if (activeConditionFrame != null) {
activeConditionFrame.setVisible(true);
activeConditionFrame.setCondition(e.getItem());
if (Boolean.TRUE.equals(useShortConditionForm)) {
for (String componentName : componentsToHideInShortForm) {
Component component = activeConditionFrame.getComponent(componentName);
if (component != null) {
if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) {
continue;
}
component.setVisible(false);
}
}
}
}
});
addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> {
AbstractCondition item = conditionsDs.getItem();
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();
}
conditionsTree.setSelected(condition);
});
FilterHelper filterHelper = AppBeans.get(FilterHelper.class);
filterHelper.initConditionsDragAndDrop(conditionsTree, conditions);
if (Boolean.TRUE.equals(useShortConditionForm)) {
filterPropertiesGrid.setVisible(false);
}
}
use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.
the class FilterEditor method addGroup.
protected void addGroup(GroupType groupType) {
GroupConditionDescriptor conditionDescriptor = new GroupConditionDescriptor(groupType, filter.getId(), filter.getDatasource());
AbstractCondition condition = conditionDescriptor.createCondition();
AbstractCondition selectedCondition = conditionsDs.getItem();
Node<AbstractCondition> newNode = new Node<>(condition);
if (selectedCondition != null && selectedCondition instanceof GroupCondition) {
Node<AbstractCondition> node = conditions.getNode(selectedCondition);
if (node != null) {
node.addChild(newNode);
conditionsTree.expand(selectedCondition.getId());
}
} else {
conditions.getRootNodes().add(newNode);
}
refreshConditionsDs();
conditionsTree.setSelected(condition);
}
use of com.haulmont.bali.datastruct.Node in project cuba by cuba-platform.
the class AbstractTreeDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
String tag = getLoggingTag("TDS");
StopWatch sw = new Slf4JStopWatch(tag, LoggerFactory.getLogger(UIPerformanceLogger.class));
clear();
this.tree = loadTree(params);
Map<K, Node<T>> targetNodes = new HashMap<>();
if (tree != null) {
for (Node<T> node : tree.toList()) {
final T entity = node.getData();
final K id = entity.getId();
data.put(id, entity);
attachListener(entity);
targetNodes.put(id, node);
}
}
this.nodes = targetNodes;
sw.stop();
}
Aggregations