[ 2435685 ] FR: Pluggable desktop presentation
- Fixed add to favourite support for NavBarDesktop - Fixed NPE during startup
This commit is contained in:
parent
e835ba8ee5
commit
3aaae7d448
|
@ -40,7 +40,7 @@ public class Accordion extends Borderlayout implements EventListener {
|
|||
private Vbox northBox;
|
||||
|
||||
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 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ 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()));
|
||||
windows = new ArrayList<Object>();
|
||||
queryZoom = new ArrayList<MQuery>();
|
||||
}
|
||||
|
@ -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++)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
@ -83,6 +87,8 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
|
|||
|
||||
private West leftRegion;
|
||||
|
||||
private DPFavourites favPanel;
|
||||
|
||||
public NavBarDesktop()
|
||||
{
|
||||
super();
|
||||
|
@ -129,9 +135,14 @@ public class NavBarDesktop extends TabbedDesktop implements MenuListener, Serial
|
|||
navigationPanel.add(pnlSide, "Application Menu");
|
||||
|
||||
Div div = new Div();
|
||||
Executions.createComponents(FAVOURITES_PATH, div, null);
|
||||
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);
|
||||
if (component instanceof DashboardPanel)
|
||||
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue