From a20f6d533c67343560d6b43d327af0a4b82b23c4 Mon Sep 17 00:00:00 2001 From: Elaine Tan Date: Fri, 10 Aug 2012 16:12:38 +0800 Subject: [PATCH] Ticket #1001002: Move the Menu to be a Portlet - support portlet drag and drop --- .../org/compiere/model/MDashboardContent.java | 27 +++ .../webui/desktop/DashboardController.java | 158 +++++++++++++++++- .../adempiere/webui/panel/HeaderPanel.java | 4 +- .../adempiere/webui/panel/MenuTreePanel.java | 2 +- 4 files changed, 182 insertions(+), 9 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MDashboardContent.java b/org.adempiere.base/src/org/compiere/model/MDashboardContent.java index c8f9b9ed2e..c88c859586 100644 --- a/org.adempiere.base/src/org/compiere/model/MDashboardContent.java +++ b/org.adempiere.base/src/org/compiere/model/MDashboardContent.java @@ -56,6 +56,33 @@ public class MDashboardContent extends X_PA_DashboardContent .setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line); } + public static MDashboardContent[] getForSession(int AD_User_ID) + { + List list = getForSessionQuery(AD_User_ID).list(); + return list.toArray(new MDashboardContent[list.size()]); + } + + public static Query getForSessionQuery(int AD_User_ID) + { + Properties ctx = Env.getCtx(); + + String whereClause = "("+COLUMNNAME_AD_Role_ID+" IS NULL OR "+COLUMNNAME_AD_Role_ID+" IN (0,?))"; + if (AD_User_ID == 0) + whereClause += " AND ("+COLUMNNAME_AD_User_ID+" IS NULL OR "+COLUMNNAME_AD_User_ID+"=?)"; + else + whereClause += " AND "+COLUMNNAME_AD_User_ID+"=?"; + + List parameters = new ArrayList(); + parameters.add(Env.getAD_Role_ID(ctx)); + parameters.add(AD_User_ID); + + return new Query(ctx, Table_Name, whereClause, null) + .setParameters(parameters) + .setOnlyActiveRecords(true) + .setApplyAccessFilter(true, false) + .setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line); + } + public MDashboardContent (Properties ctx, int PA_DashboardContent_ID, String trxName) { super (ctx, PA_DashboardContent_ID, trxName); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index 4593dadef7..44589da08a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -60,6 +60,7 @@ import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Desktop; 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; @@ -83,6 +84,9 @@ import org.zkoss.zul.Vlayout; public class DashboardController implements EventListener { private final static CLogger logger = CLogger.getCLogger(DashboardController.class); + + public static final String PORLET_MOVED_QUEUE = "PORLET_MOVED_QUEUE"; + private Component prevParent; private Component prevNext; @@ -127,14 +131,11 @@ public class DashboardController implements EventListener { try { int AD_User_ID = Env.getAD_User_ID(Env.getCtx()); - MDashboardContent[] dps = MDashboardContent.getForSession(isShowInDashboard, AD_User_ID); // based on user - + MDashboardContent[] dps = MDashboardContent.getForSession(AD_User_ID); if (dps.length == 0) - { - AD_User_ID = 0; - dps = MDashboardContent.getForSession(isShowInDashboard, AD_User_ID); // based on client - } + createUserPreference(); + dps = MDashboardContent.getForSession(isShowInDashboard, AD_User_ID); // based on user noOfCols = MDashboardContent.getForSessionColumnCount(isShowInDashboard, AD_User_ID); width = noOfCols <= 0 ? 100 : 100 / noOfCols; @@ -144,8 +145,12 @@ public class DashboardController implements EventListener { if(dashboardColumnLayout == null || currentColumnNo != columnNo) { dashboardColumnLayout = new Vlayout(); + dashboardColumnLayout.setAttribute("ColumnNo", columnNo); + dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); Anchorchildren dashboardColumn = new Anchorchildren(); dashboardColumn.setAnchor((width-2) + "%" + " 100%"); + dashboardColumn.setDroppable("true"); + dashboardColumn.addEventListener(Events.ON_DROP, this); dashboardColumn.appendChild(dashboardColumnLayout); columnList.add(dashboardColumn); dashboardLayout.appendChild(dashboardColumn); @@ -155,6 +160,7 @@ public class DashboardController implements EventListener { } Panel panel = new Panel(); + panel.setAttribute("PA_DashboardContent_ID", dp.getPA_DashboardContent_ID()); panelList.add(panel); panel.addEventListener(Events.ON_MAXIMIZE, this); panel.setStyle("margin: 2px; position: relative;"); @@ -167,6 +173,11 @@ public class DashboardController implements EventListener { panel.setCollapsible(dp.isCollapsible()); panel.setOpen(!dp.isCollapsedByDefault()); + panel.addEventListener(Events.ON_OPEN, this); + + panel.setDroppable("true"); + panel.setDraggable("true"); + panel.addEventListener(Events.ON_DROP, this); panel.setBorder("normal"); dashboardColumnLayout.appendChild(panel); @@ -340,6 +351,21 @@ public class DashboardController implements EventListener { if (panelEmpty) panel.detach(); } + + if (dps.length == 0) + { + dashboardColumnLayout = new Vlayout(); + dashboardColumnLayout.setAttribute("ColumnNo", "0"); + dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard); + Anchorchildren dashboardColumn = new Anchorchildren(); + dashboardColumn.setAnchor((width-2) + "%" + " 100%"); + dashboardColumn.setDroppable("true"); + dashboardColumn.addEventListener(Events.ON_DROP, this); + dashboardColumn.appendChild(dashboardColumnLayout); + columnList.add(dashboardColumn); + dashboardLayout.appendChild(dashboardColumn); + dashboardColumnLayout.setWidth("100%"); + } } catch (Exception e) { @@ -406,6 +432,126 @@ public class DashboardController implements EventListener { } } } + else if (eventName.equals(Events.ON_DROP)) + { + DropEvent de = (DropEvent) event; + Component dragged = de.getDragged(); + + if(dragged instanceof Panel) + { + Panel panel = (Panel) dragged; + + if(comp instanceof Panel) + { + Panel target = (Panel) comp; + + if (target.getParent() != null && target.getParent() instanceof Vlayout) + { + Vlayout dashboardColumnLayout = (Vlayout) target.getParent(); + dashboardColumnLayout.insertBefore(panel, target); + saveUserPreference(dashboardColumnLayout); + } + } + else if (comp instanceof Anchorchildren) + { + Anchorchildren target = (Anchorchildren) comp; + + if (target.getFirstChild() != null && target.getFirstChild() instanceof Vlayout) + { + Vlayout dashboardColumnLayout = (Vlayout) target.getFirstChild(); + dashboardColumnLayout.appendChild(panel); + saveUserPreference(dashboardColumnLayout); + } + } + } + } + else if (eventName.equals(Events.ON_OPEN)) + { + if(comp instanceof Panel) + { + Panel panel = (Panel) comp; + Object value = panel.getAttribute("PA_DashboardContent_ID"); + if (value != null) + { + int PA_DashboardContent_ID = Integer.parseInt(value.toString()); + MDashboardContent dashboardContent = new MDashboardContent(Env.getCtx(), PA_DashboardContent_ID, null); + dashboardContent.setIsCollapsedByDefault(!panel.isOpen()); + if (!dashboardContent.save()) + logger.log(Level.SEVERE, "Failed to save dashboard content edit " + dashboardContent.toString()); + } + } + } + } + + private void createUserPreference() + { + if (Env.getAD_User_ID(Env.getCtx()) == 0) + return; + + MDashboardContent[] dps = MDashboardContent.getForSession(0); + for (MDashboardContent dp : dps) + { + MDashboardContent dashboardContent = new MDashboardContent(Env.getCtx(), 0, null); + dashboardContent.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx())); + dashboardContent.setAD_Role_ID(Env.getAD_Role_ID(Env.getCtx())); + dashboardContent.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); + + dashboardContent.setAD_Process_ID(dp.getAD_Process_ID()); + dashboardContent.setAD_Window_ID(dp.getAD_Window_ID()); + dashboardContent.setColumnNo(dp.getColumnNo()); + dashboardContent.setDescription(dp.getDescription()); + dashboardContent.setGoalDisplay(dp.getGoalDisplay()); + dashboardContent.setHTML(dp.getHTML()); + dashboardContent.setIsCollapsedByDefault(dp.isCollapsedByDefault()); + dashboardContent.setIsCollapsible(dp.isCollapsible()); + dashboardContent.setIsEmbedReportContent(dp.isEmbedReportContent()); + dashboardContent.setIsShowInDashboard(dp.isShowInDashboard()); + dashboardContent.setLine(dp.getLine()); + dashboardContent.setName(dp.getName()); + dashboardContent.setPA_Goal_ID(dp.getPA_Goal_ID()); + dashboardContent.setZulFilePath(dp.getZulFilePath()); + + if (!dashboardContent.save()) + logger.log(Level.SEVERE, "Failed to create dashboard content edit " + dashboardContent.toString()); + } + } + + private void saveUserPreference(Vlayout layout) + { + Object value = layout.getAttribute("ColumnNo"); + if (value != null) + { + int columnNo = Integer.parseInt(value.toString()); + + value = layout.getAttribute("IsShowInDashboard"); + if (value != null) + { + boolean isShowInDashboard = Boolean.parseBoolean(value.toString()); + + List children = layout.getChildren(); + int counter = 0; + for (Component child : children) + { + if (child instanceof Panel) + { + Panel panel = (Panel) child; + value = panel.getAttribute("PA_DashboardContent_ID"); + if (value != null) + { + ++counter; + + int PA_DashboardContent_ID = Integer.parseInt(value.toString()); + MDashboardContent dashboardContent = new MDashboardContent(Env.getCtx(), PA_DashboardContent_ID, null); + dashboardContent.setColumnNo(columnNo); + dashboardContent.setLine(new BigDecimal(counter * 10)); + dashboardContent.setIsShowInDashboard(isShowInDashboard); + if (!dashboardContent.save()) + logger.log(Level.SEVERE, "Failed to save dashboard content edit " + dashboardContent.toString()); + } + } + } + } + } } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HeaderPanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HeaderPanel.java index 93aeaed176..93c920b62f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HeaderPanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HeaderPanel.java @@ -89,7 +89,7 @@ public class HeaderPanel extends Panel implements EventListener popMenu.setId("menuTreePopup"); popMenu.appendChild(new MenuTreePanel(popMenu)); popMenu.setWidth("600px"); - popMenu.setHeight("500px"); + popMenu.setHeight("90%"); popMenu.setParent(hbox); btnMenu = new ToolBarButton(); @@ -126,7 +126,7 @@ public class HeaderPanel extends Panel implements EventListener } else if(event.getTarget() == btnMenu) { - popMenu.open(btnMenu, "end_before"); + popMenu.open(btnMenu, "after_start"); } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/MenuTreePanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/MenuTreePanel.java index 5444c5e9d9..3339c35c31 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/MenuTreePanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/MenuTreePanel.java @@ -90,7 +90,7 @@ public class MenuTreePanel extends AbstractMenuPanel // Elaine 2009/02/27 - expand tree Toolbar toolbar = new Toolbar(); - toolbar.setStyle("verticle-align: middle; padding: 2px"); + toolbar.setStyle("background-color: #ffffff; verticle-align: middle; padding: 2px"); this.appendChild(toolbar); expandToggle = new ToolBarButton();