public class ListViewer extends AbstractListViewer
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.
TableViewer
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
WIDGET_DATA_KEY
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
Control |
getControl()
Returns the primary control associated with this viewer.
|
List |
getList()
Returns this list viewer's list control.
|
protected void |
listAdd(String string,
int index)
Adds the given string to the underlying widget at the given index
|
protected void |
listDeselectAll()
Deselects all selected items in the underlying widget.
|
protected int |
listGetItemCount()
Returns the number of items contained in the underlying widget.
|
protected int[] |
listGetSelectionIndices()
Returns the zero-relative indices of the items which are currently
selected in the underlying widget.
|
protected int |
listGetTopIndex()
Returns the index of the item currently at the top of the viewable area.
|
protected void |
listRemove(int index)
Removes the item from the underlying widget at the given
zero-relative index.
|
protected void |
listRemoveAll()
Removes all of the items from the underlying widget.
|
protected void |
listSetItem(int index,
String string)
Sets the text of the item at the given index in the underlying widget.
|
protected void |
listSetItems(String[] labels)
Sets the underlying widget's items to be the given array of items.
|
protected void |
listSetSelection(int[] ixs)
Selects the items at the given zero-relative indices in the underlying widget.
|
protected void |
listSetTopIndex(int index)
Sets the index of the item to be at the top of the viewable area.
|
protected void |
listShowSelection()
Shows the selection.
|
void |
reveal(Object element)
Ensures that the given element is visible, scrolling the viewer if
necessary.
|
protected void |
setSelectionToWidget(List in,
boolean reveal)
Parlays the given list of selected elements into selections on this
viewer's control.
|
add, add, doFindInputItem, doFindItem, doUpdateItem, getElementAt, getLabelProvider, getSelectionFromWidget, indexForElement, inputChanged, insert, internalRefresh, remove, remove, setLabelProvider
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, assertContentProviderType, assertElementsNotNull, associate, buildLabel, disassociate, equals, filter, findItem, findItems, fireDoubleClick, fireOpen, firePostSelectionChanged, getColorAndFontCollector, getComparator, getComparer, getFilteredChildren, getFilters, getItem, getRawChildren, getRoot, getSelection, getSortedChildren, getSorter, getStructuredSelection, handleDispose, handleDoubleSelect, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, handleSelect, hasFilters, hookControl, internalRefresh, internalUpdate, mapElement, needsRefilter, preservingSelection, refresh, refresh, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setContentProvider, setFilters, setInput, setSelection, setSelectionToWidget, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapAllElements, unmapElement, unmapElement, update, update, updateItem, updateSelection, usingElementMap
getContentProvider, getInput, labelProviderChanged
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addSelectionChangedListener, removeSelectionChangedListener, setSelection
public ListViewer(Composite parent)
MULTI, H_SCROLL, V_SCROLL,
and BORDER
.
The viewer has no input, no content provider, a default label provider,
no sorter, and no filters.parent
- the parent controlpublic ListViewer(Composite parent, int style)
parent
- the parent controlstyle
- the SWT style bitspublic ListViewer(List list)
list
- the list controlpublic Control getControl()
Viewer
getControl
in class Viewer
public List getList()
public void reveal(Object element)
StructuredViewer
reveal
in class StructuredViewer
element
- the element to revealprotected void listAdd(String string, int index)
AbstractListViewer
listAdd
in class AbstractListViewer
string
- the string to addindex
- position to insert the string intoprotected void listSetItem(int index, String string)
AbstractListViewer
listSetItem
in class AbstractListViewer
index
- index to modifystring
- new textprotected int[] listGetSelectionIndices()
AbstractListViewer
Note: This is not the actual structure used by the receiver to maintain its selection, so modifying the array will not affect the receiver.
listGetSelectionIndices
in class AbstractListViewer
protected int listGetItemCount()
AbstractListViewer
listGetItemCount
in class AbstractListViewer
protected void listSetItems(String[] labels)
AbstractListViewer
listSetItems
in class AbstractListViewer
labels
- the array of label textprotected void listRemoveAll()
AbstractListViewer
listRemoveAll
in class AbstractListViewer
protected void listRemove(int index)
AbstractListViewer
listRemove
in class AbstractListViewer
index
- the index for the itemprotected void listSetSelection(int[] ixs)
AbstractListViewer
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.
listSetSelection
in class AbstractListViewer
ixs
- the indices of the items to selectprotected void listDeselectAll()
AbstractListViewer
listDeselectAll
in class AbstractListViewer
protected void listShowSelection()
AbstractListViewer
listShowSelection
in class AbstractListViewer
protected int listGetTopIndex()
AbstractListViewer
Default implementation returns -1.
listGetTopIndex
in class AbstractListViewer
protected void listSetTopIndex(int index)
AbstractListViewer
Default implementation does nothing.
listSetTopIndex
in class AbstractListViewer
index
- the given index. -1 for none. index will always refer to a valid index.protected void setSelectionToWidget(List in, boolean reveal)
StructuredViewer
Subclasses should override to set their selection based on the given list of elements.
setSelectionToWidget
in class AbstractListViewer
in
- list of selected elements (element type: Object
)
or null
if the selection is to be clearedreveal
- true
if the selection is to be made visible,
and false
otherwise
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.