IDEMPIERE-950 Tree from detail tab not updated when master record change

This commit is contained in:
Richard Morales 2013-06-12 18:34:03 -05:00
parent b90a6bfef1
commit 256c4f5cc4
2 changed files with 77 additions and 16 deletions

View File

@ -601,9 +601,19 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
//create tree
if (gridTab.isTreeTab() && treePanel != null) {
int AD_Tree_ID = MTree.getDefaultAD_Tree_ID (
Env.getAD_Client_ID(Env.getCtx()), gridTab.getKeyColumnName());
treePanel.initTree(AD_Tree_ID, windowNo);
int AD_Tree_ID = Env.getContextAsInt (Env.getCtx(), getWindowNo(), "AD_Tree_ID", true);
int AD_Tree_ID_Default = MTree.getDefaultAD_Tree_ID (Env.getAD_Client_ID(Env.getCtx()), gridTab.getKeyColumnName());
if (gridTab.getRecord_ID() >= 0) {
if (AD_Tree_ID != 0) {
treePanel.initTree(AD_Tree_ID, windowNo);
setSelectedNode(gridTab.getRecord_ID());
} else if (AD_Tree_ID_Default != 0) {
treePanel.initTree(AD_Tree_ID_Default, windowNo);
setSelectedNode(gridTab.getRecord_ID());
}
} else {
treePanel.getTree().clear();
}
}
if (!gridTab.isSingleRow() && !isGridView())
@ -1155,19 +1165,65 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
createUI();
dynamicDisplay(col);
//sync tree
if (treePanel != null) {
//sync tree
if (treePanel != null)
{
if ("Deleted".equalsIgnoreCase(e.getAD_Message()))
if (e.Record_ID != null
&& e.Record_ID instanceof Integer
&& ((Integer)e.Record_ID != gridTab.getRecord_ID()))
{
if (e.Record_ID != null && e.Record_ID instanceof Integer && ((Integer)e.Record_ID != gridTab.getRecord_ID()))
deleteNode((Integer)e.Record_ID);
else
setSelectedNode(gridTab.getRecord_ID());
else
setSelectedNode(gridTab.getRecord_ID());
}
else if (!e.isInserting())
{
boolean refresh=true;
Treeitem item = treePanel.getTree().getSelectedItem();
if (item != null)
{
@SuppressWarnings("unchecked")
MTreeNode treeNode = ((DefaultTreeNode<MTreeNode>) item.getValue()).getData();
if (treeNode.getNode_ID() == gridTab.getRecord_ID()){
setSelectedNode(gridTab.getRecord_ID());
refresh = false;
}
}
if (refresh)
{
int AD_Tree_ID = Env.getContextAsInt (Env.getCtx(), getWindowNo(), "AD_Tree_ID", true);
if (gridTab.getRecord_ID()>=0)
{
if (AD_Tree_ID != 0)
{
treePanel.initTree(AD_Tree_ID, windowNo);
setSelectedNode(gridTab.getRecord_ID());
}
else
{
AD_Tree_ID = MTree.getDefaultAD_Tree_ID (Env.getAD_Client_ID(Env.getCtx()), gridTab.getKeyColumnName());
treePanel.initTree(AD_Tree_ID, windowNo);
}
}
else
{
treePanel.getTree().clear();
}
}
}else if(e.isInserting() && gridTab.getRecord_ID() < 0 && gridTab.getTabLevel() > 0 )
{
int AD_Tree_ID = Integer.parseInt(gridTab.getParentTab().getValue("AD_Tree_ID").toString());
MTreeNode root = new MTree (Env.getCtx(), AD_Tree_ID, true, true, null).getRoot();
SimpleTreeModel treeModel = SimpleTreeModel.createFrom(root);
try {
treePanel.getTree().setItemRenderer(treeModel);
treePanel.getTree().setModel(treeModel);
} catch (Exception treeExc) {
logger.log(Level.SEVERE, "Failed to setup tree");
}
}
}
if (listPanel.isVisible()) {
listPanel.updateListIndex();
listPanel.dynamicDisplay(col);

View File

@ -81,11 +81,16 @@ public class SimpleTreeModel extends org.zkoss.zul.DefaultTreeModel<Object> impl
SimpleTreeModel treeModel = SimpleTreeModel.createFrom(root);
treeModel.setItemDraggable(true);
treeModel.addOnDropEventListener(new ADTreeOnDropListener(tree, treeModel, vTree, windowNo));
Treecols treeCols = new Treecols();
tree.appendChild(treeCols);
Treecol treeCol = new Treecol();
treeCols.appendChild(treeCol);
if (tree.getTreecols() == null)
{
Treecols treeCols = new Treecols();
tree.getTreecols();
tree.appendChild(treeCols);
Treecol treeCol = new Treecol();
treeCols.appendChild(treeCol);
}
tree.setPageSize(-1);
try {
tree.setItemRenderer(treeModel);