-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
I have a question about a popup menu. I have the following code in mine renderer :
@Override
public void render(final Treeitem item, Object toRender,final int index) {
final Niveau niv = (Niveau) toRender;
//Always open first niveau
expandIfRoot(item, niv);
item.setLabel("(" + niv.getOrderNr() + ")" + " "
+ niv.getCode() + " - " + niv.getDescription());
item.addEventListener(Events.ON_RIGHT_CLICK, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
if (item.getPopup()==null) {
Popup popup = createMenuPopUp(niv, item);
item.setPopup(popup);
popup.open(item);
}
}
} );
}
Mine problem is about the popup. I don't want to create it directly cause it consumes to much because some of the tree's are really big, and maybe they use a couple of them. The code execute one and only the first right click it will create the popup. Now I never get mine popup, even with the 'popup.open(item)' I never see the popup. When I use setContext I get the same result.
Now the popup menu layout is for all the objects the same but of course he must code the object that is selected.
Any idea's?
Greetz chill.
Oke, I found the way how to do it. I would like to suggest to zk to review the above code and maybe let that work in the future.
The work around for this problem :
@Override
public void render(final Treeitem item, Object toRender, final int index) {
final Niveau niv = (Niveau) toRender;
//Always open first niveau
expandIfRoot(item, niv);
renderCell(item,niv);
}
private void renderCell(final Treeitem item, final Niveau niv) {
final Menupopup popup = new Menupopup();
popup.addEventListener(Events.ON_OPEN, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
popup.getChildren().clear();
for (Menuitem menuItem : createMenuItems(niv, item)) {
popup.appendChild(menuItem);
}
}
});
popup.setParent(createTreeCell(item, niv));
item.setContext(popup);
}
We can remove the listener in the eventlistener itself so its only generated when clicking the first time. I can't do this cause mine menu might change when the data change.
How to remove the listener :
popup.addEventListener(Events.ON_OPEN,new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
Iterator it = popup.getEventListeners(Events.ON_OPEN).iterator();
while (it.hasNext()) {
popup.removeEventListener(Events.ON_OPEN, (EventListener)it.next());
}
popup.getChildren().clear();
for (Menuitem menuItem : createMenuItems(niv, item)) {
popup.appendChild(menuItem);
}
} );
Asked: 2014-01-21 07:33:57 +0800
Seen: 15 times
Last updated: Jan 21 '14
Drag-drop custom image when hoovering
Large Tree with dynamic columns
Tree width lost after changing col width on maximized panel
MVVM tree example to show add/insert/delete/move/drag?
Error writing 'checked' on type org.zkoss.zul.Checkbox [closed]
Problem with changing MVVM tree model
zk framework: how to load zul pages from WEB-INF under directory zul