From e93dee5efc486bb0989e919d82f3ebb9000d2d04 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Fri, 1 Jun 2012 01:53:02 +0800 Subject: [PATCH] IDEMPIERE-286 Zk: When you first open the menu window, current menu record is not visible in the tree. --- .../org/adempiere/webui/panel/ADTabpanel.java | 35 ++++++++++++++----- .../adempiere/webui/panel/ADTreePanel.java | 3 +- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java index 53126fb22a..a5fe304c4e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTabpanel.java @@ -98,6 +98,8 @@ import org.zkoss.zul.impl.XulElement; public class ADTabpanel extends Div implements Evaluatee, EventListener, DataStatusListener, IADTabpanel, VetoableChangeListener { + private static final String ON_DEFER_SET_SELECTED_NODE = "onDeferSetSelectedNode"; + /** * generated serial version ID */ @@ -160,6 +162,7 @@ DataStatusListener, IADTabpanel, VetoableChangeListener private void init() { initComponents(); + addEventListener(ON_DEFER_SET_SELECTED_NODE, this); } private void initComponents() @@ -548,7 +551,7 @@ DataStatusListener, IADTabpanel, VetoableChangeListener } if (!gridTab.isSingleRow() && !isGridView()) - switchRowPresentation(); + switchRowPresentation(); } private Component createSpacer() { @@ -785,6 +788,10 @@ DataStatusListener, IADTabpanel, VetoableChangeListener { activateChild(activate, ep); } + + if (gridTab.getRecord_ID() > 0 && gridTab.isTreeTab() && treePanel != null) { + setSelectedNode(gridTab.getRecord_ID()); + } } private void activateChild(boolean activate, EmbeddedPanel panel) { @@ -840,6 +847,11 @@ DataStatusListener, IADTabpanel, VetoableChangeListener Treeitem item = treePanel.getTree().getSelectedItem(); navigateTo((DefaultTreeNode)item.getValue()); } + else if (ON_DEFER_SET_SELECTED_NODE.equals(event.getName())) { + if (gridTab.getRecord_ID() > 0 && gridTab.isTreeTab() && treePanel != null) { + setSelectedNode(gridTab.getRecord_ID()); + } + } } private void navigateTo(DefaultTreeNode value) { @@ -991,11 +1003,11 @@ DataStatusListener, IADTabpanel, VetoableChangeListener MTreeNode root = (MTreeNode) treeNode.getData(); MTreeNode node = new MTreeNode (gridTab.getRecord_ID(), 0, name, description, root.getNode_ID(), summary, imageIndicator, false, null); - DefaultTreeNode newNode = new DefaultTreeNode(node, new ArrayList()); - model.addNode(newNode); + DefaultTreeNode newNode = new DefaultTreeNode(node); + model.addNode(newNode); int[] path = model.getPath(newNode); Treeitem ti = treePanel.getTree().renderItemByPath(path); - treePanel.getTree().setSelectedItem(ti); + treePanel.getTree().setSelectedItem(ti); } } @@ -1003,17 +1015,24 @@ DataStatusListener, IADTabpanel, VetoableChangeListener if (recordId <= 0) return; //force on init render - if (TreeUtils.isOnInitRenderPosted(treePanel.getTree())) { + if (TreeUtils.isOnInitRenderPosted(treePanel.getTree()) || treePanel.getTree().getTreechildren() == null) { treePanel.getTree().onInitRender(); } + SimpleTreeModel model = (SimpleTreeModel) treePanel.getTree().getModel(); if (treePanel.getTree().getSelectedItem() != null) { DefaultTreeNode treeNode = (DefaultTreeNode) treePanel.getTree().getSelectedItem().getValue(); MTreeNode data = (MTreeNode) treeNode.getData(); - if (data.getNode_ID() == recordId) return; + if (data.getNode_ID() == recordId) { + int[] path = model.getPath(treeNode); + Treeitem ti = treePanel.getTree().renderItemByPath(path); + if (ti.getPage() == null) { + Events.echoEvent(ON_DEFER_SET_SELECTED_NODE, this, null); + } + return; + } } - - SimpleTreeModel model = (SimpleTreeModel) treePanel.getTree().getModel(); + DefaultTreeNode treeNode = model.find(null, recordId); if (treeNode != null) { int[] path = model.getPath(treeNode); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTreePanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTreePanel.java index 8e1cf2c4e2..cfc44e64d5 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTreePanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/ADTreePanel.java @@ -14,7 +14,6 @@ package org.adempiere.webui.panel; -import org.adempiere.webui.component.Checkbox; import org.adempiere.webui.component.SimpleTreeModel; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.util.TreeUtils; @@ -35,7 +34,7 @@ import org.zkoss.zul.Tree; * @author hengsin * */ -public class ADTreePanel extends Panel implements EventListener +public class ADTreePanel extends Panel implements EventListener { /** *