Package org.zkoss.zk.ui.event

## Class OpenEvent

- java.lang.Object
- - org.zkoss.zk.ui.event.Event
  - - org.zkoss.zk.ui.event.OpenEvent

- All Implemented Interfaces:
    `java.io.Serializable`

      public class OpenEvent
      extends Event

  Represents an event cause by user's opening or closing something at the client.

  Note: it is a bit confusing but `Events.ON_CLOSE` is sent when user clicks a close button. It is a request to ask the server to close a window, a tab or others. If the server ignores the event, nothing will happen at the client. By default, the component is detached when receiving this event.

  On the other hand, `Events.ON_OPEN` (with `OpenEvent`) is a notification. It is sent to notify the server that the client has opened or closed something. And, the server can not prevent the client from opening or closing.

  Author:
    tomyeh
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `OpenEvent​(java.lang.String name, Component target, boolean open)` | Constructs an onOpen event.
    `OpenEvent​(java.lang.String name, Component target, boolean open, Component ref)` | Constructs an onOpen event for a context menu, a tooltip or a popup.
    `OpenEvent​(java.lang.String name, Component target, boolean open, Component ref, java.lang.Object value)` | Constructs an onOpen event.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static OpenEvent` | `getOpenEvent​(AuRequest request)` | Converts an AU request to an open event.
    `Component` | `getReference()` | Returns the reference that causes `Event.getTarget()` to be opened.
    `java.lang.Object` | `getValue()` | Returns the value of the target component, when the onOpen event is sent, or null if not applicable.
    `boolean` | `isOpen()` | Returns whether it causes open.

    - ### Methods inherited from class org.zkoss.zk.ui.event.Event

      `getData, getEvent, getName, getPage, getTarget, isPropagatable, stopPropagation, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### OpenEvent

          public OpenEvent​(java.lang.String name,
                           Component target,
                           boolean open)

      Constructs an onOpen event.
      Parameters:
        `open` - whether the new status is open

    - #### OpenEvent

          public OpenEvent​(java.lang.String name,
                           Component target,
                           boolean open,
                           Component ref)

      Constructs an onOpen event for a context menu, a tooltip or a popup.
      Parameters:
        `target` - the component being opened
        `ref` - the component that causes target to be opened.

    - #### OpenEvent

          public OpenEvent​(java.lang.String name,
                           Component target,
                           boolean open,
                           Component ref,
                           java.lang.Object value)

      Constructs an onOpen event.
      Parameters:
        `open` - whether the new status is open
        `value` - the current value of the target component if applicable.
      Since:
        3.5.0
      See Also:
        `getValue()`

  - ### Method Detail

    - #### getOpenEvent

          public static final OpenEvent getOpenEvent​(AuRequest request)

      Converts an AU request to an open event.
      Since:
        5.0.0

    - #### getReference

          public Component getReference()

      Returns the reference that causes `Event.getTarget()` to be opened.

      It is null, if the open event is not caused by opening a context menu, a tooltip or a popup. Note: the onOpen event is also sent when closing the context menu (tooltip and popup), and this method returns null in this case. Thus, it is better to test `isOpen()` or `getReference()` before accessing the returned value. `if (event.isOpen()) doSome(event.getReference());`

    - #### isOpen

          public boolean isOpen()

      Returns whether it causes open.

    - #### getValue

          public java.lang.Object getValue()

      Returns the value of the target component, when the onOpen event is sent, or null if not applicable.

      Note: combobox, bandbox and other combo-type input don't send the onChange event when the dropdown is opened (onOpen). Thus, if you want to do something depends on the value, use the value returned by this method. Furthermore, for combobox and bandbox, the return value is a non-null String instance.

      Since:
        3.5.0