Eclipse Platform
2.0

org.eclipse.jface.viewers
Class ListViewer

java.lang.Object
  |
  +--org.eclipse.jface.viewers.Viewer
        |
        +--org.eclipse.jface.viewers.ContentViewer
              |
              +--org.eclipse.jface.viewers.StructuredViewer
                    |
                    +--org.eclipse.jface.viewers.ListViewer
All Implemented Interfaces:
IInputProvider, IInputSelectionProvider, ISelectionProvider

public class ListViewer
extends StructuredViewer

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).


Field Summary
 
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
 
Constructor Summary
ListViewer(Composite parent)
          Creates a list viewer on a newly-created list control under the given parent.
ListViewer(Composite parent, int style)
          Creates a list viewer on a newly-created list control under the given parent.
ListViewer(List list)
          Creates a list viewer on the given list control.
 
Method Summary
 void add(Object element)
          Adds the given element to this list viewer.
 void add(Object[] elements)
          Adds the given elements to this list viewer.
protected  Widget doFindInputItem(Object element)
          Returns the widget in this viewer's control which represents the given element if it is the viewer's input.
protected  Widget doFindItem(Object element)
          Returns the widget in this viewer's control which represent the given element.
protected  void doUpdateItem(Widget data, Object element, boolean fullMap)
          Copies the attributes of the given element into the given SWT item.
 Control getControl()
          Returns the primary control associated with this viewer.
 Object getElementAt(int index)
          Returns the element with the given index from this list viewer.
 IBaseLabelProvider getLabelProvider()
          The list viewer implementation of this Viewer framework method returns the label provider, which in the case of list viewers will be an instance of ILabelProvider.
 List getList()
          Returns this list viewer's list control.
protected  List getSelectionFromWidget()
          Retrieves the selection, as a List, from the underlying widget.
protected  int indexForElement(Object element)
           
protected  void inputChanged(Object input, Object oldInput)
          Internal hook method called when the input to this viewer is initially set or subsequently changed.
protected  void internalRefresh(Object element)
          Refreshes this viewer starting at the given element.
 void remove(Object element)
          Removes the given element from this list viewer.
 void remove(Object[] elements)
          Removes the given elements from this list viewer.
 void reveal(Object element)
          Ensures that the given element is visible, scrolling the viewer if necessary.
 void setLabelProvider(IBaseLabelProvider labelProvider)
          The list viewer implementation of this Viewer framework method ensures that the given label provider is an instance of ILabelProvider.
protected  void setSelectionToWidget(List in, boolean reveal)
          Parlays the given list of selected elements into selections on this viewer's control.
 
Methods inherited from class org.eclipse.jface.viewers.StructuredViewer
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, associate, disassociate, filter, findItem, fireDoubleClick, fireOpen, firePostSelectionChanged, getFilteredChildren, getFilters, getItem, getRawChildren, getRoot, getSelection, getSortedChildren, getSorter, handleDoubleSelect, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, handleSelect, hasFilters, hookControl, internalRefresh, mapElement, needsRefilter, preservingSelection, refresh, refresh, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setContentProvider, setInput, setSelection, setSelectionToWidget, setSorter, setUseHashlookup, testFindItem, unmapAllElements, unmapElement, unmapElement, update, update, updateItem, updateSelection, usingElementMap
 
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, handleDispose, labelProviderChanged
 
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

add

public void add(Object[] elements)
Adds the given elements to this list viewer. If this viewer does not have a sorter, the elements are added at the end in the order given; otherwise the elements are inserted at appropriate positions.

This method should be called (by the content provider) when elements have been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.

Parameters:
elements - the elements to add

add

public void add(Object element)
Adds the given element to this list viewer. If this viewer does not have a sorter, the element is added at the end; otherwise the element is inserted at the appropriate position.

This method should be called (by the content provider) when a single element has been added to the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous addition of multiple elements.

Parameters:
element - the element

doFindInputItem

protected Widget doFindInputItem(Object element)
Description copied from class: StructuredViewer
Returns the widget in this viewer's control which represents the given element if it is the viewer's input.

This method is internal to the framework; subclassers should not call this method.

Specified by:
doFindInputItem in class StructuredViewer
Returns:
the corresponding widget, or null if none

doFindItem

protected Widget doFindItem(Object element)
Description copied from class: StructuredViewer
Returns the widget in this viewer's control which represent the given element. This method searchs all the children of the input element.

This method is internal to the framework; subclassers should not call this method.

Specified by:
doFindItem in class StructuredViewer
Returns:
the corresponding widget, or null if none

doUpdateItem

protected void doUpdateItem(Widget data,
                            Object element,
                            boolean fullMap)
Description copied from class: StructuredViewer
Copies the attributes of the given element into the given SWT item. The element map is updated according to the value of fullMap. If fullMap is true then the current mapping from element to widgets is removed and the new mapping is added. If fullmap is false then only the new map gets installed. Installing only the new map is necessary in cases where only the order of elements changes but not the set of elements.

This method is internal to the framework; subclassers should not call this method.

Specified by:
doUpdateItem in class StructuredViewer
Parameters:
data -
element - the element
fullMap - true if mappings are added and removed, and false if only the new map gets installed

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

getElementAt

public Object getElementAt(int index)
Returns the element with the given index from this list viewer. Returns null if the index is out of range.

Parameters:
index - the zero-based index
Returns:
the element at the given index, or null if the index is out of range

getLabelProvider

public IBaseLabelProvider getLabelProvider()
The list viewer implementation of this Viewer framework method returns the label provider, which in the case of list viewers will be an instance of ILabelProvider.

Overrides:
getLabelProvider in class ContentViewer
Returns:
a label provider

getList

public List getList()
Returns this list viewer's list control.

Returns:
the list control

getSelectionFromWidget

protected List getSelectionFromWidget()
Description copied from class: StructuredViewer
Retrieves the selection, as a List, from the underlying widget.

Specified by:
getSelectionFromWidget in class StructuredViewer
Returns:
the list of selected elements

indexForElement

protected int indexForElement(Object element)

inputChanged

protected void inputChanged(Object input,
                            Object oldInput)
Description copied from class: Viewer
Internal hook method called when the input to this viewer is initially set or subsequently changed.

The default implementation does nothing. Subclassers may override this method to do something when a viewer's input is set. A typical use is populate the viewer.

Overrides:
inputChanged in class Viewer
Parameters:
input - the new input of this viewer, or null if none
oldInput - the old input element or null if there was previously no input

internalRefresh

protected void internalRefresh(Object element)
Description copied from class: StructuredViewer
Refreshes this viewer starting at the given element.

Specified by:
internalRefresh in class StructuredViewer
Parameters:
element - the element

remove

public void remove(Object[] elements)
Removes the given elements from this list viewer. The selection is updated if required.

This method should be called (by the content provider) when elements have been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model.

Parameters:
elements - the elements to remove

remove

public void remove(Object element)
Removes the given element from this list viewer. The selection is updated if necessary.

This method should be called (by the content provider) when a single element has been removed from the model, in order to cause the viewer to accurately reflect the model. This method only affects the viewer, not the model. Note that there is another method for efficiently processing the simultaneous removal of multiple elements.

Parameters:
element - the element

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

setLabelProvider

public void setLabelProvider(IBaseLabelProvider labelProvider)
The list viewer implementation of this Viewer framework method ensures that the given label provider is an instance of ILabelProvider.

Overrides:
setLabelProvider in class ContentViewer
Parameters:
labelProvider - the label provider, or null if none

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.

Specified by:
setSelectionToWidget in class StructuredViewer
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

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.