Class ListViewer

  • All Implemented Interfaces:
    IInputProvider, IInputSelectionProvider, IPostSelectionProvider, ISelectionProvider

    public class ListViewer
    extends AbstractListViewer
    A concrete viewer based on an SWT List control.

    This class is not intended to be subclassed. It is designed to be instantiated with a pre-existing SWT List control and configured with a domain-specific content provider, label provider, element filter (optional), and element sorter (optional).

    Note that the SWT List control only supports the display of strings, not icons. If you need to show icons for items, use TableViewer instead.

    See Also:
    TableViewer
    Restriction:
    This class is not intended to be subclassed by clients.
    • Constructor Detail

      • ListViewer

        public ListViewer​(Composite parent)
        Creates a list viewer on a newly-created list control under the given parent. The list control is created using the SWT style bits MULTI, H_SCROLL, V_SCROLL, and BORDER. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.
        Parameters:
        parent - the parent control
      • ListViewer

        public ListViewer​(Composite parent,
                          int style)
        Creates a list viewer on a newly-created list control under the given parent. The list control is created using the given SWT style bits. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.
        Parameters:
        parent - the parent control
        style - the SWT style bits
      • ListViewer

        public ListViewer​(List list)
        Creates a list viewer on the given list control. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.
        Parameters:
        list - the list control
    • Method Detail

      • getControl

        public Control getControl()
        Description copied from class: Viewer
        Returns the primary control associated with this viewer.
        Specified by:
        getControl in class Viewer
        Returns:
        the SWT control which displays this viewer's content
      • getList

        public List getList()
        Returns this list viewer's list control.
        Returns:
        the list control
      • reveal

        public void reveal​(Object element)
        Description copied from class: StructuredViewer
        Ensures that the given element is visible, scrolling the viewer if necessary. The selection is unchanged.
        Specified by:
        reveal in class StructuredViewer
        Parameters:
        element - the element to reveal
      • listAdd

        protected void listAdd​(String string,
                               int index)
        Description copied from class: AbstractListViewer
        Adds the given string to the underlying widget at the given index
        Specified by:
        listAdd in class AbstractListViewer
        Parameters:
        string - the string to add
        index - position to insert the string into
      • listSetItem

        protected void listSetItem​(int index,
                                   String string)
        Description copied from class: AbstractListViewer
        Sets the text of the item at the given index in the underlying widget.
        Specified by:
        listSetItem in class AbstractListViewer
        Parameters:
        index - index to modify
        string - new text
      • listGetSelectionIndices

        protected int[] listGetSelectionIndices()
        Description copied from class: AbstractListViewer
        Returns the zero-relative indices of the items which are currently selected in the underlying widget. The array is empty if no items are selected.

        Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.

        Specified by:
        listGetSelectionIndices in class AbstractListViewer
        Returns:
        the array of indices of the selected items
      • listSetItems

        protected void listSetItems​(String[] labels)
        Description copied from class: AbstractListViewer
        Sets the underlying widget's items to be the given array of items.
        Specified by:
        listSetItems in class AbstractListViewer
        Parameters:
        labels - the array of label text
      • listRemove

        protected void listRemove​(int index)
        Description copied from class: AbstractListViewer
        Removes the item from the underlying widget at the given zero-relative index.
        Specified by:
        listRemove in class AbstractListViewer
        Parameters:
        index - the index for the item
      • listSetSelection

        protected void listSetSelection​(int[] ixs)
        Description copied from class: AbstractListViewer
        Selects the items at the given zero-relative indices in the underlying widget. The current selection is cleared before the new items are selected.

        Indices that are out of range and duplicate indices are ignored. If the receiver is single-select and multiple indices are specified, then all indices are ignored.

        Specified by:
        listSetSelection in class AbstractListViewer
        Parameters:
        ixs - the indices of the items to select
      • listShowSelection

        protected void listShowSelection()
        Description copied from class: AbstractListViewer
        Shows the selection. If the selection is already showing in the receiver, this method simply returns. Otherwise, the items are scrolled until the selection is visible.
        Specified by:
        listShowSelection in class AbstractListViewer
      • listGetTopIndex

        protected int listGetTopIndex()
        Description copied from class: AbstractListViewer
        Returns the index of the item currently at the top of the viewable area.

        Default implementation returns -1.

        Overrides:
        listGetTopIndex in class AbstractListViewer
        Returns:
        index, -1 for none
      • listSetTopIndex

        protected void listSetTopIndex​(int index)
        Description copied from class: AbstractListViewer
        Sets the index of the item to be at the top of the viewable area.

        Default implementation does nothing.

        Overrides:
        listSetTopIndex in class AbstractListViewer
        Parameters:
        index - the given index. -1 for none. index will always refer to a valid index.
      • setSelectionToWidget

        protected void setSelectionToWidget​(List in,
                                            boolean reveal)
        Description copied from class: StructuredViewer
        Parlays the given list of selected elements into selections on this viewer's control.

        Subclasses should override to set their selection based on the given list of elements.

        Overrides:
        setSelectionToWidget in class AbstractListViewer
        Parameters:
        in - list of selected elements (element type: Object) or null if the selection is to be cleared
        reveal - true if the selection is to be made visible, and false otherwise