Ticket #1001002: Move the Menu to be a Portlet - support portlet drag and drop

This commit is contained in:
Elaine Tan 2012-08-10 16:38:35 +08:00
parent 16c5b8ee92
commit c9d662de0f
4 changed files with 179 additions and 9 deletions

View File

@ -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<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)
{
super (ctx, PA_DashboardContent_ID, trxName);

View File

@ -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;
@ -127,14 +128,11 @@ public class DashboardController implements EventListener<Event> {
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 +142,12 @@ public class DashboardController implements EventListener<Event> {
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 +157,7 @@ public class DashboardController implements EventListener<Event> {
}
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 +170,11 @@ public class DashboardController implements EventListener<Event> {
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 +348,21 @@ public class DashboardController implements EventListener<Event> {
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 +429,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());
}
}
}
}
}
}
/**

View File

@ -89,7 +89,7 @@ public class HeaderPanel extends Panel implements EventListener<Event>
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<Event>
}
else if(event.getTarget() == btnMenu)
{
popMenu.open(btnMenu, "end_before");
popMenu.open(btnMenu, "after_start");
}
}
}

View File

@ -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();