Ticket #1001002: Move the Menu to be a Portlet - support portlet drag and drop
This commit is contained in:
parent
b4131b00ee
commit
a20f6d533c
|
@ -56,6 +56,33 @@ public class MDashboardContent extends X_PA_DashboardContent
|
||||||
.setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line);
|
.setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MDashboardContent[] getForSession(int AD_User_ID)
|
||||||
|
{
|
||||||
|
List<MDashboardContent> 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<Object> parameters = new ArrayList<Object>();
|
||||||
|
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)
|
public MDashboardContent (Properties ctx, int PA_DashboardContent_ID, String trxName)
|
||||||
{
|
{
|
||||||
super (ctx, PA_DashboardContent_ID, trxName);
|
super (ctx, PA_DashboardContent_ID, trxName);
|
||||||
|
|
|
@ -60,6 +60,7 @@ import org.zkoss.zk.ui.Component;
|
||||||
import org.zkoss.zk.ui.Desktop;
|
import org.zkoss.zk.ui.Desktop;
|
||||||
import org.zkoss.zk.ui.Executions;
|
import org.zkoss.zk.ui.Executions;
|
||||||
import org.zkoss.zk.ui.Page;
|
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.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
@ -83,6 +84,9 @@ import org.zkoss.zul.Vlayout;
|
||||||
public class DashboardController implements EventListener<Event> {
|
public class DashboardController implements EventListener<Event> {
|
||||||
|
|
||||||
private final static CLogger logger = CLogger.getCLogger(DashboardController.class);
|
private final static CLogger logger = CLogger.getCLogger(DashboardController.class);
|
||||||
|
|
||||||
|
public static final String PORLET_MOVED_QUEUE = "PORLET_MOVED_QUEUE";
|
||||||
|
|
||||||
private Component prevParent;
|
private Component prevParent;
|
||||||
private Component prevNext;
|
private Component prevNext;
|
||||||
|
|
||||||
|
@ -127,14 +131,11 @@ public class DashboardController implements EventListener<Event> {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
|
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)
|
if (dps.length == 0)
|
||||||
{
|
createUserPreference();
|
||||||
AD_User_ID = 0;
|
|
||||||
dps = MDashboardContent.getForSession(isShowInDashboard, AD_User_ID); // based on client
|
|
||||||
}
|
|
||||||
|
|
||||||
|
dps = MDashboardContent.getForSession(isShowInDashboard, AD_User_ID); // based on user
|
||||||
noOfCols = MDashboardContent.getForSessionColumnCount(isShowInDashboard, AD_User_ID);
|
noOfCols = MDashboardContent.getForSessionColumnCount(isShowInDashboard, AD_User_ID);
|
||||||
|
|
||||||
width = noOfCols <= 0 ? 100 : 100 / noOfCols;
|
width = noOfCols <= 0 ? 100 : 100 / noOfCols;
|
||||||
|
@ -144,8 +145,12 @@ public class DashboardController implements EventListener<Event> {
|
||||||
if(dashboardColumnLayout == null || currentColumnNo != columnNo)
|
if(dashboardColumnLayout == null || currentColumnNo != columnNo)
|
||||||
{
|
{
|
||||||
dashboardColumnLayout = new Vlayout();
|
dashboardColumnLayout = new Vlayout();
|
||||||
|
dashboardColumnLayout.setAttribute("ColumnNo", columnNo);
|
||||||
|
dashboardColumnLayout.setAttribute("IsShowInDashboard", isShowInDashboard);
|
||||||
Anchorchildren dashboardColumn = new Anchorchildren();
|
Anchorchildren dashboardColumn = new Anchorchildren();
|
||||||
dashboardColumn.setAnchor((width-2) + "%" + " 100%");
|
dashboardColumn.setAnchor((width-2) + "%" + " 100%");
|
||||||
|
dashboardColumn.setDroppable("true");
|
||||||
|
dashboardColumn.addEventListener(Events.ON_DROP, this);
|
||||||
dashboardColumn.appendChild(dashboardColumnLayout);
|
dashboardColumn.appendChild(dashboardColumnLayout);
|
||||||
columnList.add(dashboardColumn);
|
columnList.add(dashboardColumn);
|
||||||
dashboardLayout.appendChild(dashboardColumn);
|
dashboardLayout.appendChild(dashboardColumn);
|
||||||
|
@ -155,6 +160,7 @@ public class DashboardController implements EventListener<Event> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Panel panel = new Panel();
|
Panel panel = new Panel();
|
||||||
|
panel.setAttribute("PA_DashboardContent_ID", dp.getPA_DashboardContent_ID());
|
||||||
panelList.add(panel);
|
panelList.add(panel);
|
||||||
panel.addEventListener(Events.ON_MAXIMIZE, this);
|
panel.addEventListener(Events.ON_MAXIMIZE, this);
|
||||||
panel.setStyle("margin: 2px; position: relative;");
|
panel.setStyle("margin: 2px; position: relative;");
|
||||||
|
@ -167,6 +173,11 @@ public class DashboardController implements EventListener<Event> {
|
||||||
|
|
||||||
panel.setCollapsible(dp.isCollapsible());
|
panel.setCollapsible(dp.isCollapsible());
|
||||||
panel.setOpen(!dp.isCollapsedByDefault());
|
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");
|
panel.setBorder("normal");
|
||||||
dashboardColumnLayout.appendChild(panel);
|
dashboardColumnLayout.appendChild(panel);
|
||||||
|
@ -340,6 +351,21 @@ public class DashboardController implements EventListener<Event> {
|
||||||
if (panelEmpty)
|
if (panelEmpty)
|
||||||
panel.detach();
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
@ -406,6 +432,126 @@ public class DashboardController implements EventListener<Event> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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<Component> 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class HeaderPanel extends Panel implements EventListener<Event>
|
||||||
popMenu.setId("menuTreePopup");
|
popMenu.setId("menuTreePopup");
|
||||||
popMenu.appendChild(new MenuTreePanel(popMenu));
|
popMenu.appendChild(new MenuTreePanel(popMenu));
|
||||||
popMenu.setWidth("600px");
|
popMenu.setWidth("600px");
|
||||||
popMenu.setHeight("500px");
|
popMenu.setHeight("90%");
|
||||||
popMenu.setParent(hbox);
|
popMenu.setParent(hbox);
|
||||||
|
|
||||||
btnMenu = new ToolBarButton();
|
btnMenu = new ToolBarButton();
|
||||||
|
@ -126,7 +126,7 @@ public class HeaderPanel extends Panel implements EventListener<Event>
|
||||||
}
|
}
|
||||||
else if(event.getTarget() == btnMenu)
|
else if(event.getTarget() == btnMenu)
|
||||||
{
|
{
|
||||||
popMenu.open(btnMenu, "end_before");
|
popMenu.open(btnMenu, "after_start");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class MenuTreePanel extends AbstractMenuPanel
|
||||||
|
|
||||||
// Elaine 2009/02/27 - expand tree
|
// Elaine 2009/02/27 - expand tree
|
||||||
Toolbar toolbar = new Toolbar();
|
Toolbar toolbar = new Toolbar();
|
||||||
toolbar.setStyle("verticle-align: middle; padding: 2px");
|
toolbar.setStyle("background-color: #ffffff; verticle-align: middle; padding: 2px");
|
||||||
this.appendChild(toolbar);
|
this.appendChild(toolbar);
|
||||||
|
|
||||||
expandToggle = new ToolBarButton();
|
expandToggle = new ToolBarButton();
|
||||||
|
|
Loading…
Reference in New Issue