Loading of tree items

204 views
Skip to first unread message

Nicolas Micoud

unread,
Mar 23, 2017, 11:11:34 AM3/23/17
to iDempiere
Hello,

I'm currently migrating our iDempiere 2.1 to the 4.1 and it seems that trees are managed differently.

AFAIK, all nodes were loaded and displayed in 2.1 (no wait time).
Now, in 4.1, they are loaded when needed.

Steps to reproduce
on test.idempiere.org, log in GardenWorld and open Tree maintenance.
Select ElementValue tree and choose an item from the grid (eg : Checking Account (Bank Asset).

I have to wait seconds before the tree item is displayed whereas in 2.1, it is done immediately.

Is there a way to come back to the original version ?
I can't find where the changes were made (or are they done directly in zk library ?)

Thanks,

Nicolas

Nicolas Micoud

unread,
Mar 23, 2017, 11:49:43 AM3/23/17
to iDempiere
If i click on a 'blank' tree item (node without label), it throws a NPE at org.adempiere.webui.apps.form.WTreeMaintenance.onTreeSelection(WTreeMaintenance.java:367)

Treeitem ti = centerTree.getSelectedItem();
DefaultTreeNode<?> stn = (DefaultTreeNode<?>) ti.getValue();
MTreeNode tn = (MTreeNode)stn.getData();

-> stn.getData() is null

Hiep Lq

unread,
Mar 23, 2017, 11:56:37 AM3/23/17
to Mohemmed Bilal Ilyas
I guess new behavior bring by zk library.
try to set "isOpen = true"
i'm not sure it's correct, just recall from my issue http://tracker.zkoss.org/browse/ZK-3022

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/17ea8df8-a7aa-4b74-bfd3-c41c15fe7962%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Lê Quý Hiệp
Email: hie...@hasuvimex.vn
Skype: admin.hasuvimex

Company: Thanh Hoa Fishery Import - Export J.s.c  (HasuvimexDL 47
Add: Lot E, Le Mon Industrial Zone, Thanh Hoa, Vietnam

Nicolas Micoud

unread,
Mar 23, 2017, 12:00:29 PM3/23/17
to iDempiere
Hi Hiep,
I don't understand, what object should be set "isOpen=true" ?
Thanks,

Nicolas



Le jeudi 23 mars 2017 16:56:37 UTC+1, Hiep Lq a écrit :
I guess new behavior bring by zk library.
try to set "isOpen = true"
i'm not sure it's correct, just recall from my issue http://tracker.zkoss.org/browse/ZK-3022
On Thu, Mar 23, 2017 at 10:11 PM, Nicolas Micoud <nicolas...@gmail.com> wrote:
Hello,

I'm currently migrating our iDempiere 2.1 to the 4.1 and it seems that trees are managed differently.

AFAIK, all nodes were loaded and displayed in 2.1 (no wait time).
Now, in 4.1, they are loaded when needed.

Steps to reproduce
on test.idempiere.org, log in GardenWorld and open Tree maintenance.
Select ElementValue tree and choose an item from the grid (eg : Checking Account (Bank Asset).

I have to wait seconds before the tree item is displayed whereas in 2.1, it is done immediately.

Is there a way to come back to the original version ?
I can't find where the changes were made (or are they done directly in zk library ?)

Thanks,

Nicolas

--
You received this message because you are subscribed to the Google Groups "iDempiere" group.
To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+...@googlegroups.com.

Hiep Lq

unread,
Mar 23, 2017, 12:17:22 PM3/23/17
to Mohemmed Bilal Ilyas
sorry. it on Treeitem

To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/d8fb7905-141e-495b-a9a2-05616e709e59%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nicolas Micoud

unread,
Mar 24, 2017, 10:20:06 AM3/24/17
to iDempiere
Hi,

I think i tried it yesterday (i'm not in front of my development machine) and it did not work.
Will have a look again to be sure.

When you were investigating, did you find a way to use same behaviour as zk6 ?

Thanks,

Nicolas
sorry. it on Treeitem

Hiep Lq

unread,
Mar 27, 2017, 4:43:21 AM3/27/17
to Mohemmed Bilal Ilyas
i figure out this behavior when i fix a tree issue (don't remember correct which one)
i see new behavior is good, it save memory.
in case you want to open all tree node, try this function 

Component treeObject is a Tree object

        /**
* travel all node of tree, at selected node, call callback function
* @param tree
* @param nodeModel
* @param isRootNode
* @param processNode
*/
protected void collapseTree (Component treeObject, boolean isOpen){
if (treeObject instanceof Treeitem) {
Treeitem treeitem = (Treeitem) treeObject;
treeitem.setOpen(isOpen);
}
Collection<?> com = treeObject.getChildren();
if (com != null) {
for (Iterator<?> iterator = com.iterator(); iterator.hasNext();) {
collapseTree((Component) iterator.next(), isOpen);

}
}
}

To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/de4d112f-ee08-4559-91a8-e46d825c9ecf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nicolas Micoud

unread,
Mar 27, 2017, 7:50:29 AM3/27/17
to iDempiere
Hi Hiep,
Thanks for the hint, will try to integrate it in my code.

Anyway, could it be an enhancement to add a new checkbox on the tree, in order to force to expand it automatically (could be useful for organizations as there are not lots of records, and should be disabled for account element)

WDYT ?


Thanks,

Nicolas

Nicolas Micoud

unread,
Mar 27, 2017, 10:50:32 AM3/27/17
to iDempiere
Hi again,

I've tried to integrate your method in my code but it doesn't work well.
I've made more tests on standard trees and i find strange behaviour.

I create a real production tree (3 levels) and I notice that when clicking on the next/previous arrow, the grid content is updated but the tree item is not selected.
Then, if i click on the 'Expand Tree' button, then the next/previous button select the correct tree item.
It seems that clicking on that button load the whole tree. Couldn't it be done when the tree is shown for the first time ?

Nicolas

Nicolas Micoud

unread,
Mar 27, 2017, 10:52:19 AM3/27/17
to iDempiere
Here the screenshot done in test.idempiere.org) : i wanted to give a 2Pack but i can't upload any file here :(

Auto Generated Inline Image 1

Hiep Lq

unread,
Mar 27, 2017, 12:56:24 PM3/27/17
to Mohemmed Bilal Ilyas
a good practise with control have model. always use method of model, don't use method of control.
so i update open function flow this rule

to use just call collapseTree (tree, isOpen);

your idea look good.

/**
* travel all node of tree, at selected node, call callback function
* @param tree
* @param nodeModel
* @param isRootNode
* @param processNode
*/
protected void collapseTree (Component treeObject, boolean isOpen){
if (treeObject instanceof Tree) {
Tree tree = (Tree)treeObject;
if (tree.getModel() != null && tree.getModel() instanceof TreeOpenableModel){
collapseTreeModel ((TreeOpenableModel)tree.getModel(), isOpen, null);
return;
}
}
if (treeObject instanceof Treeitem) {// Tree also is Treeitem
Treeitem treeitem = (Treeitem) treeObject;
treeitem.setOpen(isOpen);
}
Collection<?> com = treeObject.getChildren();
if (com != null) {
for (Iterator<?> iterator = com.iterator(); iterator.hasNext();) {
collapseTree((Component) iterator.next(), isOpen);

}
}
}

protected <T> void collapseTreeModel (TreeOpenableModel treeModelOpenable, boolean isOpen, T treeNode){
if (!isOpen){
treeModelOpenable.clearOpen();
return;//done, easy to close all node
}else{
if (!(treeModelOpenable instanceof TreeModel<?>)){
return;//model have to be a instance of TreeModel. because it provide method to add open object
}
if (treeNode != null && !(treeNode instanceof TreeNode<?>)){
return; //don't support, at least it's TreeNode to travel child node
}
@SuppressWarnings("unchecked")
TreeModel<T> treeModel = (TreeModel<T>)treeModelOpenable;
if (treeNode == null){// get from model
Object rootNode = treeModel.getRoot();
if (!(rootNode instanceof TreeNode<?>)){
return;//don't support, at least it's TreeNode to travel child node 
}
@SuppressWarnings("unchecked")
TreeNode<T> node = (TreeNode<T>)rootNode;
collapseTreeModel (treeModelOpenable, isOpen, node);
}else{//child node
TreeNode<?> node = (TreeNode<?>)treeNode;
treeModelOpenable.addOpenPath(treeModel.getPath(treeNode));
for (TreeNode<?> childNode : node.getChildren()){
collapseTreeModel (treeModelOpenable, isOpen, childNode);
}
}
}
}

To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/9214d8d0-7573-40dd-857b-f910114419bd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Hiep Lq

unread,
Mar 27, 2017, 1:00:18 PM3/27/17
to Mohemmed Bilal Ilyas
I not yet read two prev reply before i sent update method, so update isn't solution for your issue.
I just want to follow good practise. but you can let it a chance to test.

I do it and test on a project separate with idempiere, just pure ZK app

Hiep Lq

unread,
Mar 27, 2017, 1:07:52 PM3/27/17
to Mohemmed Bilal Ilyas
"Couldn't it be done when the tree is shown for the first time ?"
yes, you can expand tree at first time. just call function after you set model for tree.

just try redo what you description on menu window and i can redo it.
ever i expand tree, after some time sync tree correct, it loss again.

To unsubscribe from this group and stop receiving emails from it, send an email to idempiere+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/ba83cdab-8caa-4a63-9004-00f06fb8cb84%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nicolas Micoud

unread,
Mar 28, 2017, 9:55:21 AM3/28/17
to iDempiere
Hello Hiep,

I've tested rapidly and it seems to work !
Just add a control to avoid NPE

if (node.getChildren() != null) {

   
for (TreeNode<?> childNode : node.getChildren()){
             collapseTreeModel
(treeModelOpenable, isOpen, childNode);
   
}
}


I will do other tests but it's on the good way !

Thanks,

Nicolas

Nicolas Micoud

unread,
Mar 28, 2017, 11:09:18 AM3/28/17
to iDempiere
Would it be possible to use this new method in trunk ?
A new checkbox on AD_Tree table to force a whole loading of the tree (could be useful for organizations as there are not lots of records, and should be disabled for account element)

WDYT ?

Regards,

Nicolas

Nicolas Micoud

unread,
Mar 31, 2017, 11:02:24 AM3/31/17
to iDempiere
Reply all
Reply to author
Forward
0 new messages