01: /* Menupopup.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Thu Sep 22 10:58:18 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import java.io.IOException;
22:
23: import org.zkoss.lang.Objects;
24:
25: import org.zkoss.zk.ui.Component;
26: import org.zkoss.zk.ui.Execution;
27: import org.zkoss.zk.ui.UiException;
28: import org.zkoss.zk.ui.event.Events;
29:
30: /**
31: * A container used to display menus. It should be placed inside a
32: * {@link Menu}.
33: *
34: * <p>Supported event: onOpen.<br/>
35: * Note: to have better performance, onOpen is sent only if
36: * non-deferrable event listener is registered
37: * (see {@link org.zkoss.zk.ui.event.Deferrable}).
38: *
39: * <p>To load the content dynamically, you can listen to the onOpen event,
40: * and then create menuitem when {@link org.zkoss.zk.ui.event.OpenEvent#isOpen}
41: * is true.
42: *
43: * <p>Default {@link #getSclass}: menupopup.
44: *
45: * @author tomyeh
46: */
47: public class Menupopup extends Popup {
48: public Menupopup() {
49: setSclass("menupopup");
50: }
51:
52: //-- super --//
53: public String getOuterAttrs() {
54: final StringBuffer sb = new StringBuffer(64).append(super
55: .getOuterAttrs());
56:
57: appendAsapAttr(sb, Events.ON_OPEN);
58: if (typeRequired())
59: sb.append(" z.type=\"zul.menu.Mpop\"");
60: //to minimize HTML's size, generate z.type only if necessary
61: return sb.toString();
62: }
63:
64: private boolean typeRequired() {
65: return !(getParent() instanceof Menu);
66: }
67:
68: //-- Component --//
69: public boolean insertBefore(Component child, Component insertBefore) {
70: if (!(child instanceof Menuitem)
71: && !(child instanceof Menuseparator)
72: && !(child instanceof Menu))
73: throw new UiException("Unsupported child for menupopup: "
74: + child);
75: return super.insertBefore(child, insertBefore);
76: }
77: }
|