[ 2435685 ] FR: Pluggable desktop presentation

- Fixed add to favourite support for NavBarDesktop
- Fixed NPE during startup
This commit is contained in:
Heng Sin Low 2008-12-17 02:27:57 +00:00
parent e835ba8ee5
commit 3aaae7d448
4 changed files with 98 additions and 54 deletions

View File

@ -40,7 +40,7 @@ public class Accordion extends Borderlayout implements EventListener {
private Vbox northBox; private Vbox northBox;
private List<String> labelList = new ArrayList<String>(); private List<String> labelList = new ArrayList<String>();
private List<ToolBarButton> buttonList = new ArrayList<ToolBarButton>(); private List<Div> headerList = new ArrayList<Div>();
private List<Component> componentList = new ArrayList<Component>(); private List<Component> componentList = new ArrayList<Component>();
private int selectedIndex = -1; private int selectedIndex = -1;
@ -83,7 +83,7 @@ public class Accordion extends Borderlayout implements EventListener {
northBox.appendChild(div); northBox.appendChild(div);
labelList.add(label); labelList.add(label);
buttonList.add(button); headerList.add(div);
componentList.add(component); componentList.add(component);
} }
@ -94,7 +94,7 @@ public class Accordion extends Borderlayout implements EventListener {
*/ */
public void setLabel(int index, String label) { public void setLabel(int index, String label) {
labelList.set(index, label); labelList.set(index, label);
buttonList.get(index).setLabel(label); ((ToolBarButton)headerList.get(index).getFirstChild()).setLabel(label);
if (selectedIndex == index) { if (selectedIndex == index) {
getCenter().setTitle(label); getCenter().setTitle(label);
} }
@ -127,22 +127,14 @@ public class Accordion extends Borderlayout implements EventListener {
getCenter().getChildren().clear(); getCenter().getChildren().clear();
for (int i = 0; i < index; i++) { for (int i = 0; i < index; i++) {
Div div = new Div(); northBox.appendChild(headerList.get(i));
div.setClass("z-center-header");
div.appendChild(buttonList.get(i));
div.setWidth("100%");
northBox.appendChild(div);
} }
getCenter().setTitle(labelList.get(index)); getCenter().setTitle(labelList.get(index));
getCenter().appendChild(componentList.get(index)); getCenter().appendChild(componentList.get(index));
for (int i = index + 1; i < labelList.size(); i++) { for (int i = index + 1; i < labelList.size(); i++) {
Div div = new Div(); southBox.appendChild(headerList.get(i));
div.setClass("z-center-header");
div.appendChild(buttonList.get(i));
div.setWidth("100%");
southBox.appendChild(div);
} }
this.invalidate(); this.invalidate();
@ -153,7 +145,16 @@ public class Accordion extends Borderlayout implements EventListener {
* @param tooltiptext * @param tooltiptext
*/ */
public void setTooltiptext(int index, String 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);
} }
} }

View File

@ -43,6 +43,10 @@ import org.zkoss.zul.Vbox;
*/ */
public class DPFavourites extends DashboardPanel implements EventListener { 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 static final long serialVersionUID = 1L;
private Box bxFav; private Box bxFav;
@ -69,11 +73,11 @@ public class DPFavourites extends DashboardPanel implements EventListener {
Image img = new Image("/images/Delete24.png"); Image img = new Image("/images/Delete24.png");
favToolbar.appendChild(img); favToolbar.appendChild(img);
img.setAlign("right"); img.setAlign("right");
img.setDroppable("deleteFav"); img.setDroppable(DELETE_FAV_DROPPABLE);
img.addEventListener(Events.ON_DROP, this); img.addEventListener(Events.ON_DROP, this);
// //
favContent.setDroppable("favourite"); favContent.setDroppable(FAVOURITE_DROPPABLE);
favContent.addEventListener(Events.ON_DROP, this); favContent.addEventListener(Events.ON_DROP, this);
} }
@ -106,7 +110,7 @@ public class DPFavourites extends DashboardPanel implements EventListener {
String label = nd.toString().trim(); String label = nd.toString().trim();
ToolBarButton btnFavItem = new ToolBarButton(String.valueOf(nd.getNode_ID())); ToolBarButton btnFavItem = new ToolBarButton(String.valueOf(nd.getNode_ID()));
btnFavItem.setLabel(label); btnFavItem.setLabel(label);
btnFavItem.setDraggable("deleteFav"); btnFavItem.setDraggable(DELETE_FAV_DROPPABLE);
btnFavItem.addEventListener(Events.ON_CLICK, this); btnFavItem.addEventListener(Events.ON_CLICK, this);
btnFavItem.addEventListener(Events.ON_DROP, this); btnFavItem.addEventListener(Events.ON_DROP, this);
bxFav.appendChild(btnFavItem); bxFav.appendChild(btnFavItem);
@ -185,23 +189,7 @@ public class DPFavourites extends DashboardPanel implements EventListener {
Treerow treerow = (Treerow) dragged; Treerow treerow = (Treerow) dragged;
Treeitem treeitem = (Treeitem) treerow.getParent(); Treeitem treeitem = (Treeitem) treerow.getParent();
Object value = treeitem.getValue(); addItem(treeitem);
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();
}
}
} }
} }
else if(comp instanceof Image) else if(comp instanceof Image)
@ -209,6 +197,14 @@ public class DPFavourites extends DashboardPanel implements EventListener {
if(dragged instanceof ToolBarButton) if(dragged instanceof ToolBarButton)
{ {
ToolBarButton btn = (ToolBarButton) dragged; ToolBarButton btn = (ToolBarButton) dragged;
removeLink(btn);
}
}
}
//
}
private void removeLink(ToolBarButton btn) {
String value = btn.getName(); String value = btn.getName();
if(value != null) if(value != null)
@ -225,8 +221,28 @@ public class DPFavourites extends DashboardPanel implements EventListener {
} }
} }
} }
/**
* 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();
} }
} }
//
} }
} }

View File

@ -60,7 +60,6 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
private static final String ZOOM_KEY = "queryZoom"; private static final String ZOOM_KEY = "queryZoom";
public AbstractDesktop() { public AbstractDesktop() {
m_goals = MGoal.getUserGoals(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()));
windows = new ArrayList<Object>(); windows = new ArrayList<Object>();
queryZoom = new ArrayList<MQuery>(); queryZoom = new ArrayList<MQuery>();
} }
@ -269,8 +268,12 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
protected String renderGoals(int AD_Table_ID, Panelchildren panel) protected String renderGoals(int AD_Table_ID, Panelchildren panel)
{ {
String output = ""; String output = "";
if (m_goals == null)
{
m_goals = MGoal.getUserGoals(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()));
if (m_goals == null) if (m_goals == null)
return output; return output;
}
for (int i = 0; i < m_goals.length; i++) for (int i = 0; i < m_goals.length; i++)
{ {

View File

@ -26,6 +26,7 @@ import org.adempiere.webui.component.Accordion;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.dashboard.DPActivities; import org.adempiere.webui.dashboard.DPActivities;
import org.adempiere.webui.dashboard.DPFavourites;
import org.adempiere.webui.dashboard.DashboardPanel; import org.adempiere.webui.dashboard.DashboardPanel;
import org.adempiere.webui.dashboard.DashboardRunnable; import org.adempiere.webui.dashboard.DashboardRunnable;
import org.adempiere.webui.event.MenuListener; 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.Component;
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;
@ -54,6 +56,8 @@ import org.zkoss.zul.Div;
import org.zkoss.zul.Html; import org.zkoss.zul.Html;
import org.zkoss.zul.Panel; import org.zkoss.zul.Panel;
import org.zkoss.zul.Panelchildren; import org.zkoss.zul.Panelchildren;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.Treerow;
/** /**
* @author hengsin * @author hengsin
@ -83,6 +87,8 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
private West leftRegion; private West leftRegion;
private DPFavourites favPanel;
public NavBarDesktop() public NavBarDesktop()
{ {
super(); super();
@ -129,9 +135,14 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
navigationPanel.add(pnlSide, "Application Menu"); navigationPanel.add(pnlSide, "Application Menu");
Div div = new Div(); Div div = new Div();
Executions.createComponents(FAVOURITES_PATH, div, null); favPanel = (DPFavourites) Executions.createComponents(FAVOURITES_PATH, div, null);
navigationPanel.add(div, "Favourites"); 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(); div = new Div();
Component component = Executions.createComponents(ACTIVITIES_PATH, div, null); Component component = Executions.createComponents(ACTIVITIES_PATH, div, null);
if (component instanceof DashboardPanel) if (component instanceof DashboardPanel)
@ -376,6 +387,19 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
if(menuId > 0) onMenuSelected(menuId); 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() public void onServerPush()