0

BorderLayout, setOpen by code not fire onopen event?

asked 2012-08-21 10:51:37 +0800

tizios gravatar image tizios
3

updated 2012-08-21 13:13:14 +0800

I would like to face the pressure of a combination of keys (es: CTRL+M), open the BorderLayout (West) and give the focus to the first content control.

In my code i have:

mainLayout.addEventListener(Events.ON_CTRL_KEY, new EventListener<KeyEvent>() {
    @Override
    public void onEvent(KeyEvent event) throws Exception {
				
        if (event.getKeyCode() == (byte)'M' && event.isCtrlKey()) 
  	    layoutWest.setOpen(!layoutWest.isOpen());
				
	event.stopPropagation();
    }
}); 

i have also:
@Listen(Events.ON_OPEN+"=#layoutWest")
    public void onOpenMenuLeft() {
	    if (layoutWest.isOpen())
		    treeMain.focus();  //  first  content control of the BorderLayout West component.
    }

If i open the BorderLayout West using the mouse, everything works perfectly. If you instead use the layoutwest.setopen(True) from the code, the onopen event of component LayoutWest, is not raised.

What one can help me understand?

Thanks

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2013-07-22 02:49:44 +0800

paowang gravatar image paowang
140 6

Can you provide your ZUL for reproducing ? and what version of ZK do you use?

link publish delete flag offensive edit

answered 2013-08-19 11:04:15 +0800

tizios gravatar image tizios
3

Thanks for your concern, I am currently using zk CE ver. 6.5.2

This is my .zul :

<?page title="Auto Generated index.zul"?>
<zk>
<div id="mainLayout" apply="code.IndexController" hflex="1" vflex="1">
    <borderlayout>
        <north style="background-color:#ababab">
            <div>TITLE</div>
        </north>
        <west id="layoutWest" collapsible="true" width="300px">
            <tree id="treeMain">
                <treecols>
                    <treecol label="Items" />
                </treecols>
                <treechildren>
                    <treeitem label="itm 1" />
                    <treeitem label="itm 2" />
                    <treeitem label="itm 3" />
                </treechildren>
            </tree>
        </west>
        <center style="border:0">
            <div style="padding:30px">
                Press CTRL+M to open/close the West zone.
                <separator/>
                After the onOpen if you press the Arrow-Down (for move down on the next row)
                The selected row will not change, it seems that the focus is not on the tree ... 
            </div>
        </center>
    </borderlayout>
</div>
</zk>

And this is my class code.IndexController :

package code;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Div;
import org.zkoss.zul.Tree;
import org.zkoss.zul.West;

public class IndexController extends SelectorComposer<Component> {
    private static final long serialVersionUID = -4800231356684164268L;

    @Wire Div mainLayout;
    @Wire West layoutWest;
    @Wire Tree treeMain;

    @Override
    public void doAfterCompose(Component comp) throws Exception {
        super.doAfterCompose(comp);

        mainLayout.setCtrlKeys("^M");
        mainLayout.addEventListener(Events.ON_CTRL_KEY, new EventListener<KeyEvent>() {
            @Override
            public void onEvent(KeyEvent event) throws Exception {

                if (event.getKeyCode() == (byte)'M' && event.isCtrlKey()) 
                layoutWest.setOpen(!layoutWest.isOpen());

            event.stopPropagation();
            }
        });
    }

    @Listen(Events.ON_OPEN+"=#layoutWest")
    public void onOpenMenuLeft() {
        if (layoutWest.isOpen())
            treeMain.focus();  //  first  content control of the BorderLayout West component.
    }

}

Basically I would like after the opening of the West, the focus went to the tree so that pressing the arrow keys up / down I can move using the keyboard, not to force the user to use the mouse.

Thanks

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-08-21 10:51:37 +0800

Seen: 100 times

Last updated: Aug 19 '13

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