Package org.zkoss.zul

Class Listheader

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Scope, ComponentCtrl

    public class Listheader
    extends HeaderElement
    The list header which defines the attributes and header of a column of a list box. Its parent must be Listhead.

    Difference from XUL:

    1. There is no listcol in ZUL because it is merged into Listheader. Reason: easier to write Listbox.

    Default getZclass(): z-listheader.(since 5.0.0)

    Author:
    tomyeh
    See Also:
    Serialized Form
    • Constructor Detail

      • Listheader

        public Listheader()
      • Listheader

        public Listheader​(java.lang.String label)
      • Listheader

        public Listheader​(java.lang.String label,
                          java.lang.String src)
      • Listheader

        public Listheader​(java.lang.String label,
                          java.lang.String src,
                          java.lang.String width)
    • Method Detail

      • getListbox

        public Listbox getListbox()
        Returns the listbox that this belongs to.
      • getValue

        public <T> T getValue()
        Returns the value.

        Default: null.

        Note: the value is application dependent, you can place whatever value you want.

        Since:
        3.6.0
      • setValue

        public <T> void setValue​(T value)
        Sets the value.
        Parameters:
        value - the value.

        Note: the value is application dependent, you can place whatever value you want.

        Since:
        3.6.0
      • getSortDirection

        public java.lang.String getSortDirection()
        Returns the sort direction.

        Default: "natural".

      • setSortDirection

        public void setSortDirection​(java.lang.String sortDir)
                              throws WrongValueException
        Sets the sort direction. This does not sort the data, it only serves as an indicator as to how the list is sorted. (unless the listbox has "autosort" attribute)

        If you use sort(boolean) to sort list items, the sort direction is maintained automatically. If you want to sort it in customized way, you have to set the sort direction manually.

        Parameters:
        sortDir - one of "ascending", "descending" and "natural"
        Throws:
        WrongValueException
      • getSortAscending

        public java.util.Comparator getSortAscending()
        Returns the ascending sorter, or null if not available.
      • setSortAscending

        public void setSortAscending​(java.util.Comparator sorter)
        Sets the ascending sorter, or null for no sorter for the ascending order.
        Parameters:
        sorter - the comparator used to sort the ascending order. If you are using the group feature, you can pass an instance of GroupComparator to have a better control. If an instance of GroupComparator is passed, GroupComparator.compareGroup(D, D) is used to group elements, and Comparator.compare(T, T) is used to sort elements with a group. Otherwise, Comparator.compare(T, T) is used to group elements and sort elements within a group.
      • setSortAscending

        public void setSortAscending​(java.lang.String clsnm)
                              throws java.lang.ClassNotFoundException,
                                     java.lang.InstantiationException,
                                     java.lang.IllegalAccessException
        Sets the ascending sorter with the class name, or null for no sorter for the ascending order.
        Throws:
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • getSortDescending

        public java.util.Comparator getSortDescending()
        Returns the descending sorter, or null if not available.
      • setSortDescending

        public void setSortDescending​(java.util.Comparator sorter)
        Sets the descending sorter, or null for no sorter for the descending order.
        Parameters:
        sorter - the comparator used to sort the ascending order. If you are using the group feature, you can pass an instance of GroupComparator to have a better control. If an instance of GroupComparator is passed, GroupComparator.compareGroup(D, D) is used to group elements, and Comparator.compare(T, T) is used to sort elements with a group. Otherwise, Comparator.compare(T, T) is used to group elements and sort elements within a group.
      • setSortDescending

        public void setSortDescending​(java.lang.String clsnm)
                               throws java.lang.ClassNotFoundException,
                                      java.lang.InstantiationException,
                                      java.lang.IllegalAccessException
        Sets the descending sorter with the class name, or null for no sorter for the descending order.
        Throws:
        java.lang.ClassNotFoundException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • getMaxlength

        public int getMaxlength()
        Returns the maximal length of each item's label.

        Default: 0 (no limit).

      • setMaxlength

        public void setMaxlength​(int maxlength)
        Sets the maximal length of each item's label.

        Default: 0 (no limit).

        Notice that maxlength will be applied to this header and all listcell of the same column.

      • getColumnIndex

        public int getColumnIndex()
        Returns the column index, starting from 0.
      • sort

        public boolean sort​(boolean ascending,
                            boolean force)
        Sorts the list items based on getSortAscending() and getSortDescending().
        Parameters:
        ascending - whether to use getSortAscending(). If the corresponding comparator is not set, it returns false and does nothing.
        force - whether to enforce the sorting no matter what the sort direction (getSortDirection()) is. If false, this method is the same as sort(boolean).
        Returns:
        whether the rows are sorted.
      • group

        public boolean group​(boolean ascending)
        Groups and sorts the items (Listitem) based on getSortAscending(). If the corresponding comparator is not set, it returns false and does nothing.
        Parameters:
        ascending - whether to use getSortAscending(). If the corresponding comparator is not set, it returns false and does nothing.
        Returns:
        whether the rows are grouped.
        Since:
        6.5.0
      • onGroupLater

        public void onGroupLater​(SortEvent event)
        Internal use only.
        Since:
        6.5.0
      • ungroup

        public void ungroup​(boolean ascending)
        Ungroups and sorts the items (Listitem) based on the ascending. If the corresponding comparator is not set, it returns false and does nothing.
        Parameters:
        ascending - whether to use getSortAscending(). If the corresponding comparator is not set, it returns false and does nothing.
        Since:
        6.5.0
      • clone

        public java.lang.Object clone()
        Description copied from interface: Component
        Clones the component. All of its children and descendants are cloned. Also, ID are preserved.
        Specified by:
        clone in interface Component
        Overrides:
        clone in class LabelImageElement
        Returns:
        the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
      • updateByClient

        protected void updateByClient​(java.lang.String name,
                                      java.lang.Object value)
        Description copied from class: AbstractComponent
        Called when the widget running at the client asks the server to update a value. The update is caused by an AU request named setAttr (by invoking zk.Widget's smartUpdate at client).

        By default, it does nothing but log a warning message, since it is not safe to allow the client to update a field arbitrary.

        However, if you'd like to allow the update for a particular component you could do one of the following

        1. For component developers: override this method to update the field directly. For example,
          protected void updateByClient(String name, Object value) {
                  if ("disabled".equals(name))
                          setDisabled(name, ((Boolean)value).booleanValue());
                  else
                          super.updateByClient(name, value);
        2. For application developers: set an attribute called org.zkoss.zk.ui.updateByClient to be true. Then, this method will use reflection to find out the setter to update the value. Nothing happens if the method is not found.
        3. Notice: this method will invoke AbstractComponent.disableClientUpdate(boolean) to disable any update to the client, when calling the setter.

          If you want to enable the client update for all instances of a given component (though not recommended for the security reason), you could refer to here.

          See also zk.Widget.smartUpdate().

        Overrides:
        updateByClient in class AbstractComponent