From 3aaae7d448583c2e78d0487eda9585477a14091a Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 17 Dec 2008 02:27:57 +0000 Subject: [PATCH] [ 2435685 ] FR: Pluggable desktop presentation - Fixed add to favourite support for NavBarDesktop - Fixed NPE during startup --- .../adempiere/webui/component/Accordion.java | 29 ++++--- .../webui/dashboard/DPFavourites.java | 86 +++++++++++-------- .../webui/desktop/AbstractDesktop.java | 9 +- .../webui/desktop/NavBarDesktop.java | 28 +++++- 4 files changed, 98 insertions(+), 54 deletions(-) diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Accordion.java b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Accordion.java index c1d8f825c9..b43b86440c 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/component/Accordion.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/component/Accordion.java @@ -40,7 +40,7 @@ public class Accordion extends Borderlayout implements EventListener { private Vbox northBox; private List labelList = new ArrayList(); - private List buttonList = new ArrayList(); + private List
headerList = new ArrayList
(); private List componentList = new ArrayList(); private int selectedIndex = -1; @@ -83,7 +83,7 @@ public class Accordion extends Borderlayout implements EventListener { northBox.appendChild(div); labelList.add(label); - buttonList.add(button); + headerList.add(div); componentList.add(component); } @@ -94,7 +94,7 @@ public class Accordion extends Borderlayout implements EventListener { */ public void setLabel(int index, String label) { labelList.set(index, label); - buttonList.get(index).setLabel(label); + ((ToolBarButton)headerList.get(index).getFirstChild()).setLabel(label); if (selectedIndex == index) { getCenter().setTitle(label); } @@ -127,22 +127,14 @@ public class Accordion extends Borderlayout implements EventListener { getCenter().getChildren().clear(); for (int i = 0; i < index; i++) { - Div div = new Div(); - div.setClass("z-center-header"); - div.appendChild(buttonList.get(i)); - div.setWidth("100%"); - northBox.appendChild(div); + northBox.appendChild(headerList.get(i)); } getCenter().setTitle(labelList.get(index)); getCenter().appendChild(componentList.get(index)); for (int i = index + 1; i < labelList.size(); i++) { - Div div = new Div(); - div.setClass("z-center-header"); - div.appendChild(buttonList.get(i)); - div.setWidth("100%"); - southBox.appendChild(div); + southBox.appendChild(headerList.get(i)); } this.invalidate(); @@ -153,7 +145,16 @@ public class Accordion extends Borderlayout implements EventListener { * @param tooltiptext */ public void setTooltiptext(int index, String tooltiptext) { - buttonList.get(index).setTooltiptext(tooltiptext); + headerList.get(index).setTooltiptext(tooltiptext); + } + + /** + * Get the header div component + * @param index + * @return Div + */ + public Div getHeader(int index) { + return headerList.get(index); } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPFavourites.java b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPFavourites.java index 1bb3388dae..c6f721e22c 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPFavourites.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/dashboard/DPFavourites.java @@ -43,6 +43,10 @@ import org.zkoss.zul.Vbox; */ public class DPFavourites extends DashboardPanel implements EventListener { + public static final String FAVOURITE_DROPPABLE = "favourite"; + + public static final String DELETE_FAV_DROPPABLE = "deleteFav"; + private static final long serialVersionUID = 1L; private Box bxFav; @@ -69,11 +73,11 @@ public class DPFavourites extends DashboardPanel implements EventListener { Image img = new Image("/images/Delete24.png"); favToolbar.appendChild(img); img.setAlign("right"); - img.setDroppable("deleteFav"); + img.setDroppable(DELETE_FAV_DROPPABLE); img.addEventListener(Events.ON_DROP, this); // - favContent.setDroppable("favourite"); + favContent.setDroppable(FAVOURITE_DROPPABLE); favContent.addEventListener(Events.ON_DROP, this); } @@ -106,7 +110,7 @@ public class DPFavourites extends DashboardPanel implements EventListener { String label = nd.toString().trim(); ToolBarButton btnFavItem = new ToolBarButton(String.valueOf(nd.getNode_ID())); btnFavItem.setLabel(label); - btnFavItem.setDraggable("deleteFav"); + btnFavItem.setDraggable(DELETE_FAV_DROPPABLE); btnFavItem.addEventListener(Events.ON_CLICK, this); btnFavItem.addEventListener(Events.ON_DROP, this); bxFav.appendChild(btnFavItem); @@ -185,23 +189,7 @@ public class DPFavourites extends DashboardPanel implements EventListener { Treerow treerow = (Treerow) dragged; Treeitem treeitem = (Treeitem) treerow.getParent(); - Object value = treeitem.getValue(); - if(value != null) - { - int Node_ID = Integer.valueOf(value.toString()); - if(barDBupdate(true, Node_ID)) - { - String label = treeitem.getLabel().trim(); - ToolBarButton btnFavItem = new ToolBarButton(String.valueOf(Node_ID)); - btnFavItem.setLabel(label); - btnFavItem.setDraggable("deleteFav"); - btnFavItem.addEventListener(Events.ON_CLICK, this); - btnFavItem.addEventListener(Events.ON_DROP, this); - bxFav.appendChild(btnFavItem); - bxFav.removeChild(lblMsg); - bxFav.invalidate(); - } - } + addItem(treeitem); } } else if(comp instanceof Image) @@ -209,24 +197,52 @@ public class DPFavourites extends DashboardPanel implements EventListener { if(dragged instanceof ToolBarButton) { ToolBarButton btn = (ToolBarButton) dragged; - String value = btn.getName(); - - if(value != null) - { - int Node_ID = Integer.valueOf(value.toString()); - if(barDBupdate(false, Node_ID)) - { - bxFav.removeChild(btn); - - if(bxFav.getChildren().isEmpty()) - bxFav.appendChild(lblMsg); - - bxFav.invalidate(); - } - } + removeLink(btn); } } } // } + + private void removeLink(ToolBarButton btn) { + String value = btn.getName(); + + if(value != null) + { + int Node_ID = Integer.valueOf(value.toString()); + if(barDBupdate(false, Node_ID)) + { + bxFav.removeChild(btn); + + if(bxFav.getChildren().isEmpty()) + bxFav.appendChild(lblMsg); + + bxFav.invalidate(); + } + } + } + + /** + * Add menu treeitem into the user favourite panel + * @param treeitem + */ + public void addItem(Treeitem treeitem) { + Object value = treeitem.getValue(); + if(value != null) + { + int Node_ID = Integer.valueOf(value.toString()); + if(barDBupdate(true, Node_ID)) + { + String label = treeitem.getLabel().trim(); + ToolBarButton btnFavItem = new ToolBarButton(String.valueOf(Node_ID)); + btnFavItem.setLabel(label); + btnFavItem.setDraggable(DELETE_FAV_DROPPABLE); + btnFavItem.addEventListener(Events.ON_CLICK, this); + btnFavItem.addEventListener(Events.ON_DROP, this); + bxFav.appendChild(btnFavItem); + bxFav.removeChild(lblMsg); + bxFav.invalidate(); + } + } + } } diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java index 8d0d9b7981..f656324f80 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/AbstractDesktop.java @@ -59,8 +59,7 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop private static final String ZOOM_KEY = "queryZoom"; - public AbstractDesktop() { - m_goals = MGoal.getUserGoals(Env.getCtx(), Env.getAD_User_ID(Env.getCtx())); + public AbstractDesktop() { windows = new ArrayList(); queryZoom = new ArrayList(); } @@ -270,7 +269,11 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop { String output = ""; if (m_goals == null) - return output; + { + m_goals = MGoal.getUserGoals(Env.getCtx(), Env.getAD_User_ID(Env.getCtx())); + if (m_goals == null) + return output; + } for (int i = 0; i < m_goals.length; i++) { diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java index bfa92aaadb..9b1f332759 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/desktop/NavBarDesktop.java @@ -26,6 +26,7 @@ import org.adempiere.webui.component.Accordion; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.dashboard.DPActivities; +import org.adempiere.webui.dashboard.DPFavourites; import org.adempiere.webui.dashboard.DashboardPanel; import org.adempiere.webui.dashboard.DashboardRunnable; import org.adempiere.webui.event.MenuListener; @@ -41,6 +42,7 @@ import org.compiere.util.Msg; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Page; +import org.zkoss.zk.ui.event.DropEvent; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -54,6 +56,8 @@ import org.zkoss.zul.Div; import org.zkoss.zul.Html; import org.zkoss.zul.Panel; import org.zkoss.zul.Panelchildren; +import org.zkoss.zul.Treeitem; +import org.zkoss.zul.Treerow; /** * @author hengsin @@ -82,6 +86,8 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial private Accordion navigationPanel; private West leftRegion; + + private DPFavourites favPanel; public NavBarDesktop() { @@ -129,8 +135,13 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial navigationPanel.add(pnlSide, "Application Menu"); Div div = new Div(); - Executions.createComponents(FAVOURITES_PATH, div, null); - navigationPanel.add(div, "Favourites"); + favPanel = (DPFavourites) Executions.createComponents(FAVOURITES_PATH, div, null); + navigationPanel.add(div, "Favourites"); + + //setup drag and drop for favourites + div = navigationPanel.getHeader(1); + div.setDroppable(DPFavourites.FAVOURITE_DROPPABLE); + div.addEventListener(Events.ON_DROP, this); div = new Div(); Component component = Executions.createComponents(ACTIVITIES_PATH, div, null); @@ -376,6 +387,19 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial if(menuId > 0) onMenuSelected(menuId); } } + else if(eventName.equals(Events.ON_DROP)) + { + DropEvent de = (DropEvent) event; + Component dragged = de.getDragged(); + + if(dragged instanceof Treerow) + { + Treerow treerow = (Treerow) dragged; + Treeitem treeitem = (Treeitem) treerow.getParent(); + + favPanel.addItem(treeitem); + } + } } public void onServerPush()