Class LightList<T>

  • Type Parameters:
    T - - class of data in list items.
    All Implemented Interfaces:
    ILightControl

    public class LightList<T>
    extends AbstractScrollableControl

    Instance of this class represents list. List contains collection of items. Each list item has text and image. (text can be empty and image can be null)

    List can have no scrolls, horizontal scroll, vertical scroll, or horizontal and vertical scrolls.
    List can have single or multi selection style.
    List can be drawn with or without border.

    • Constructor Detail

      • LightList

        public LightList()
        Constructs light list with SWT.MULTI selection style, SWT.VERTICAL scroll bars style and border.
      • LightList

        public LightList​(int style)
        Constructor.
        Parameters:
        style - - list style (selection can be SWT.SINGLE or SWT.MULTI, scrolls style can be SWT.VERTICAL and SWT.HORIZONTAL, one of them or none, to draw border pass SWT.BORDER.
        See Also:
        SWT.SINGLE, SWT.MULTI, SWT.VERTICAL, SWT.HORIZONTAL, SWT.BORDER
    • Method Detail

      • addSelectionListener

        public void addSelectionListener​(ISelectionChangedListener<T> selectionListener)
        Adds light list selection listener.
        Parameters:
        selectionListener - - listener to add. Cannot be null.
      • removeSelectionListener

        public void removeSelectionListener​(ISelectionChangedListener<T> selectionListener)
        Removes light list selection listener.
        Parameters:
        selectionListener - - listener to remove. Cannot be null.
      • addItem

        public void addItem​(LightListItem<T> item)
        Adds item to list.
        Parameters:
        item - - item to add. Cannot be null.
      • addItem

        public void addItem​(LightListItem<T> item,
                            int position)
        Inserts item to list at given position.
        Parameters:
        item - - item to insert. Cannot be null.
        position - - position to insert to. Should be non negative and less then items count.
      • addItems

        public void addItems​(Collection<LightListItem<T>> items)
        Adds items to list.
        Parameters:
        items - - items to add. Cannot be null.
      • addItems

        public void addItems​(Collection<LightListItem<T>> items,
                             int position)
        Adds items to list.
        Parameters:
        items - - items to add. Cannot be null.
        position - - position to insert to. Should be non negative and less then items count.
      • setItem

        public void setItem​(int index,
                            LightListItem<T> item)
        Replaces item with given index.
        Parameters:
        index - - index of item to replace. Should be non negative and less then items count.
        item - - item to set. Cannot be null.
      • setItems

        public void setItems​(List<LightListItem<T>> items)
        Sets list items.
        Parameters:
        items - - items to set. Cannot be null.
      • removeItem

        public void removeItem​(LightListItem<T> item)
        Removes item from list.
        Parameters:
        item - - item to remove. Cannot be null.
      • removeItems

        public void removeItems​(Collection<LightListItem<T>> items)
        Removes given items from list.
        Parameters:
        items - - items to remove. Cannot be null.
      • removeItem

        public void removeItem​(int index)
        Removes item with given index from list.
        Parameters:
        index - - index of item to remove. Should be non negative and less then items count.
      • removeItemsByIndexes

        public void removeItemsByIndexes​(Collection<Integer> indexes)
        Removes items with given indexes from list.
        Parameters:
        indexes - - indexes of items to remove. Cannot be null.
      • clearItems

        public void clearItems()
        Removes all items from list.
      • getItems

        public List<LightListItem<T>> getItems()
        Returns list items.
        Returns:
        list items. Cannot return null.
      • getItemsCount

        public int getItemsCount()
        Return list items count.
        Returns:
        list items count.
      • getSelectedItems

        public Collection<LightListItem<T>> getSelectedItems()
        Returns selected items.
        Returns:
        selected items. Cannot return null.
      • getSelection

        public Collection<Integer> getSelection()
        Returns indexes of selected items.
        Returns:
        indexes of selected items. Cannot return null.
      • setBackgroundColor

        public void setBackgroundColor​(org.eclipse.swt.graphics.Color backgroundColor)
        Sets list background color.
        Parameters:
        backgroundColor - - background color. Cannot be null.
      • getBackgroundColor

        public org.eclipse.swt.graphics.Color getBackgroundColor()
        Returns list background color.
        Returns:
        list background color. Cannot return null.
      • selectItem

        public void selectItem​(LightListItem<T> item)
        Selects given item.
        Parameters:
        item - - item to select. Cannot be null.
      • selectItem

        public void selectItem​(int index)
        Select item with given index.
        Parameters:
        index - - index of item to select. Index should be non negative and less then items count.
      • selectItems

        public void selectItems​(Collection<LightListItem<T>> items)
        Selects given items. Selects only first item if style is SWT.SINGLE.
        Parameters:
        items - - items to select. Cannot be null.
      • selectItemsByIndexes

        public void selectItemsByIndexes​(Collection<Integer> indexes)
        Selects items with given indexes. Selects only first item if style is SWT.SINGLE.
        Parameters:
        indexes - - indexes of items to select. Each index should be non negative and less then items count. Cannot be null.
      • deselectItem

        public void deselectItem​(LightListItem<T> item)
        Deselects given item.
        Parameters:
        item - - item to deselect. Cannot be null.
      • deselectItem

        public void deselectItem​(int index)
        Deselects item with given index.
        Parameters:
        index - - index of item to deselect. Index should be non negative and less then items count.
      • deselectItems

        public void deselectItems​(Collection<LightListItem<T>> items)
        Deselects given items.
        Parameters:
        items - - items to deselect. Cannot be null.
      • deselectItemsByIndexes

        public void deselectItemsByIndexes​(Collection<Integer> indexes)
        Deselects items with given indexes.
        Parameters:
        indexes - - indexes of items to deselect. Each index should be non negative and less then items count. Cannot be null.
      • deselectAll

        public void deselectAll()
        Deselects all list items.
      • isSelected

        public boolean isSelected​(LightListItem<T> item)
        Returns true if given item is selected.
        Parameters:
        item - - item to check. Cannot be null.
        Returns:
        true if given item is selected.
      • isSelected

        public boolean isSelected​(int index)
        Returns true if item with given index is selected.
        Parameters:
        index - - index to check.
        Returns:
        true if item with given index is selected.
      • scrollToSelection

        public void scrollToSelection()
        Scrolls to first selected item. If there is no selected item does nothing.
      • invalidate

        public void invalidate​(LightListItem<T> item)
        Invalidates given list item.
        Parameters:
        item - - item to invalidate. Cannot be null.
      • getLineHeight

        public int getLineHeight()
        Returns line height.
        Returns:
        line height.
      • setMenu

        public void setMenu​(org.eclipse.swt.widgets.Menu menu)
        Sets list menu.
        Parameters:
        menu - - menu to set. Can be null.
      • getMenu

        public org.eclipse.swt.widgets.Menu getMenu()
        Returns list menu.
        Returns:
        menu. Can return null.
      • setFocusedItem

        public void setFocusedItem​(int index)
        Sets focused item index. Index should be non negative and less then items count.
        Parameters:
        index - - index of item to set focused.
      • setFocusedItem

        public void setFocusedItem​(LightListItem<T> item)
        Sets focused item.
        Parameters:
        item - - item to set focused. Can be null.
      • getFocusedItem

        public LightListItem<T> getFocusedItem()
        Returns focused item.
        Returns:
        focused item. Can return null.
      • computeSize

        public org.eclipse.swt.graphics.Point computeSize​(org.eclipse.swt.graphics.GC gc,
                                                          int width,
                                                          int height,
                                                          boolean flushCache)
        Description copied from interface: ILightControl
        Computes the size of this control.
        Specified by:
        computeSize in interface ILightControl
        Overrides:
        computeSize in class AbstractLightControl
        Parameters:
        gc - the GC to do measurements with.
        width - the width hint, SWT.DEFAULT to compute the preferred width.
        height - the height hint, SWT.DEFAULT to compute the preferred height.
        flushCache - the flush cache flag, instructs the associated layout to reset all its caches, if any.
        Returns:
        the computed size.
      • paint

        public void paint​(org.eclipse.swt.graphics.GC gc,
                          org.eclipse.swt.graphics.Rectangle rectangle)
        Description copied from interface: ILightControl
        Paints the given rectangle of this control.
        Specified by:
        paint in interface ILightControl
        Overrides:
        paint in class AbstractScrollableControl
        Parameters:
        gc - the GC to paint on.
        rectangle - the rectangle to paint.