0

Popupmenu in tree. [closed]

asked 2014-01-21 07:33:57 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

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.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by chillworld
close date 2014-02-10 13:37:26

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-21 10:39:56 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

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);
            }
    } );
link publish delete flag offensive edit

Question tools

Follow
2 followers

RSS

Stats

Asked: 2014-01-21 07:33:57 +0800

Seen: 15 times

Last updated: Jan 21 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More