From 52f4416416f3b5aea5da5962fd69b0bb2997494e Mon Sep 17 00:00:00 2001 From: hieplq Date: Sat, 15 Jul 2017 04:17:35 +0700 Subject: [PATCH] IDEMPIERE-3426:improve tab behavior active prev tab when close current active tab --- .../org/adempiere/webui/component/Tab.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Tab.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Tab.java index e736c76d67..b9335bb5ef 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Tab.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Tab.java @@ -17,11 +17,18 @@ package org.adempiere.webui.component; +import java.util.HashSet; +import java.util.Set; + import org.adempiere.webui.adwindow.ADWindow; import org.adempiere.webui.util.ManageImageCache; import org.compiere.model.MImage; import org.compiere.model.MInfoWindow; import org.zkoss.image.Image; +import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.SelectEvent; +import org.zkoss.zul.Include; import org.zkoss.zul.impl.LabelImageElement; /** @@ -121,4 +128,58 @@ public class Tab extends org.zkoss.zul.Tab return mInfo==null?null:new DecorateInfo(mInfo.getImageURL()); } } + + /** + * copy from {@link org.zkoss.zul.Tab#close()} to work-around for http://tracker.zkoss.org/browse/ZK-3705 + */ + @Override + public void close() { + if (isSelected()) { + final org.zkoss.zul.Tab tab = selectNextTabWR(); + if (tab != null) { + final Set selItems = new HashSet<>(2); + selItems.add(tab); + Events.postEvent(new SelectEvent(Events.ON_SELECT, tab, selItems)); + } + } + org.zkoss.zul.Tabbox tabbox = getTabbox(); + + // Nothing to do according to ZK-2027 issue, let application developer to do so. + if (tabbox != null && tabbox.getModel() != null) + return; + + //Cache panel before detach , or we couldn't get it after tab is detached. + final org.zkoss.zul.Tabpanel panel = getLinkedPanel(); + + detach(); + + if (panel != null) { + // B60-ZK-1160: Exception when closing tab with included content + // Must clean up included content before detaching tab panel + Component include = panel.getFirstChild(); + if (include instanceof Include) { + include.detach(); + } + panel.detach(); + } + } + + /** + * http://tracker.zkoss.org/browse/ZK-3705 + * change default behavior to get prev tab is new active tab + * @return + */ + protected org.zkoss.zul.Tab selectNextTabWR() { + for (org.zkoss.zul.Tab tab = (org.zkoss.zul.Tab) getPreviousSibling(); tab != null; tab = (org.zkoss.zul.Tab) tab.getPreviousSibling()) + if (!tab.isDisabled()) { + tab.setSelected(true); + return tab; + } + for (org.zkoss.zul.Tab tab = (org.zkoss.zul.Tab) getNextSibling(); tab != null; tab = (org.zkoss.zul.Tab) tab.getNextSibling()) + if (!tab.isDisabled()) { + tab.setSelected(true); + return tab; + } + return null; + } }