Tree Component

I have the following entities:
Entity: BatchReport
Entity: BatchGroup
Entity: Report

Basically, a BatchReport can contain one or many BatchGroup.
A BatchGroup can contain one or many Reports.
i would like to represent those entities in a tree-like component, very similar to how you represent entities in CUBA studio. A user should be able to click on “New Batch Report” . This will open the screen for the user to create the entity. etc…
Any suggestions on how to go about it? Thanks.

There are two components that are able to display hierarchical structures: Tree and TreeTable.
They require a HierarchicalDatasource, which contains an entity with the link to itself - the “Hierarchy property”.
If you have no such hierarchical entity in your data model, create a synthetic non-persistent entity with the link to itself, and write some code in your screen controller to create instances of this entity and add them to the HierarchicalDatasource.
Please look at the attached project. RootEntity, BranchEntity and LeafEntity are the real entities stored in the database; TreeEntity is a synthetic non-persistent entity to show in the tree. It contains the link to itself (“parent” attribute), and links to real entities.

tree-demo.zip (18.6K)

HI
I tried to use a treetable using some entities. when I run it, i get the following error. Any clue to fix t?


com.haulmont.cuba.core.global.RemoteException:
---
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [
                select e from inteaccgms$PurchaseOrderStatus e
            ]. 
[14, 44] The abstract schema type 'inteaccgms$PurchaseOrderStatus' is unknown.
---
org.eclipse.persistence.exceptions.JPQLException: 
Exception Description: Problem compiling [
                select e from inteaccgms$PurchaseOrderStatus e
            ]. 
[14, 44] The abstract schema type 'inteaccgms$PurchaseOrderStatus' is unknown.
    at com.haulmont.cuba.core.sys.ServiceInterceptor.aroundInvoke(ServiceInterceptor.java:73)
    at sun.reflect.GeneratedMethodAccessor108.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
    at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy133.loadList(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.r

I guess that PurchaseOrderStatus is a non-persistent entity. You cannot query for it. Look at the sample project - the datasource with the non-persistent entity has no query and has refreshMode=“NEVER”.

Ok, have noticed that. What are the ways I can populate the data then?

By creating instance in your code and adding them to the datasource. See TreeWindow.java.

1 Like