Class ListViewer
- All Implemented Interfaces:
IInputProvider,IInputSelectionProvider,IPostSelectionProvider,ISelectionProvider
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jface.viewers.StructuredViewer
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders -
Field Summary
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY -
Constructor Summary
ConstructorsConstructorDescriptionListViewer(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
Modifier and TypeMethodDescriptionReturns the primary control associated with this viewer.getList()Returns this list viewer's list control.protected voidAdds the given string to the underlying widget at the given indexprotected voidDeselects all selected items in the underlying widget.protected intReturns the number of items contained in the underlying widget.protected int[]Returns the zero-relative indices of the items which are currently selected in the underlying widget.protected intReturns the index of the item currently at the top of the viewable area.protected voidlistRemove(int index) Removes the item from the underlying widget at the given zero-relative index.protected voidRemoves all of the items from the underlying widget.protected voidlistSetItem(int index, String string) Sets the text of the item at the given index in the underlying widget.protected voidlistSetItems(String[] labels) Sets the underlying widget's items to be the given array of items.protected voidlistSetSelection(int[] ixs) Selects the items at the given zero-relative indices in the underlying widget.protected voidlistSetTopIndex(int index) Sets the index of the item to be at the top of the viewable area.protected voidShows the selection.voidEnsures that the given element is visible, scrolling the viewer if necessary.protected voidsetSelectionToWidget(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.AbstractListViewer
add, add, doFindInputItem, doFindItem, doUpdateItem, getElementAt, getLabelProvider, getSelectionFromWidget, indexForElement, inputChanged, insert, internalRefresh, remove, remove, setLabelProviderMethods inherited from class org.eclipse.jface.viewers.StructuredViewer
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, usingElementMapMethods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, labelProviderChangedMethods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelectionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.jface.viewers.ISelectionProvider
addSelectionChangedListener, removeSelectionChangedListener, setSelection
-
Constructor Details
-
ListViewer
Creates a list viewer on a newly-created list control under the given parent. The list control is created using the SWT style bitsMULTI, H_SCROLL, V_SCROLL,andBORDER. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.- Parameters:
parent- the parent control
-
ListViewer
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 controlstyle- the SWT style bits
-
ListViewer
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 Details
-
getControl
Description copied from class:ViewerReturns the primary control associated with this viewer.- Specified by:
getControlin classViewer- Returns:
- the SWT control which displays this viewer's content
-
getList
Returns this list viewer's list control.- Returns:
- the list control
-
reveal
Description copied from class:StructuredViewerEnsures that the given element is visible, scrolling the viewer if necessary. The selection is unchanged.- Specified by:
revealin classStructuredViewer- Parameters:
element- the element to reveal
-
listAdd
Description copied from class:AbstractListViewerAdds the given string to the underlying widget at the given index- Specified by:
listAddin classAbstractListViewer- Parameters:
string- the string to addindex- position to insert the string into
-
listSetItem
Description copied from class:AbstractListViewerSets the text of the item at the given index in the underlying widget.- Specified by:
listSetItemin classAbstractListViewer- Parameters:
index- index to modifystring- new text
-
listGetSelectionIndices
protected int[] listGetSelectionIndices()Description copied from class:AbstractListViewerReturns 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:
listGetSelectionIndicesin classAbstractListViewer- Returns:
- the array of indices of the selected items
-
listGetItemCount
protected int listGetItemCount()Description copied from class:AbstractListViewerReturns the number of items contained in the underlying widget.- Specified by:
listGetItemCountin classAbstractListViewer- Returns:
- the number of items
-
listSetItems
Description copied from class:AbstractListViewerSets the underlying widget's items to be the given array of items.- Specified by:
listSetItemsin classAbstractListViewer- Parameters:
labels- the array of label text
-
listRemoveAll
protected void listRemoveAll()Description copied from class:AbstractListViewerRemoves all of the items from the underlying widget.- Specified by:
listRemoveAllin classAbstractListViewer
-
listRemove
protected void listRemove(int index) Description copied from class:AbstractListViewerRemoves the item from the underlying widget at the given zero-relative index.- Specified by:
listRemovein classAbstractListViewer- Parameters:
index- the index for the item
-
listSetSelection
protected void listSetSelection(int[] ixs) Description copied from class:AbstractListViewerSelects 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:
listSetSelectionin classAbstractListViewer- Parameters:
ixs- the indices of the items to select
-
listDeselectAll
protected void listDeselectAll()Description copied from class:AbstractListViewerDeselects all selected items in the underlying widget.- Specified by:
listDeselectAllin classAbstractListViewer
-
listShowSelection
protected void listShowSelection()Description copied from class:AbstractListViewerShows 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:
listShowSelectionin classAbstractListViewer
-
listGetTopIndex
protected int listGetTopIndex()Description copied from class:AbstractListViewerReturns the index of the item currently at the top of the viewable area.Default implementation returns -1.
- Overrides:
listGetTopIndexin classAbstractListViewer- Returns:
- index, -1 for none
-
listSetTopIndex
protected void listSetTopIndex(int index) Description copied from class:AbstractListViewerSets the index of the item to be at the top of the viewable area.Default implementation does nothing.
- Overrides:
listSetTopIndexin classAbstractListViewer- Parameters:
index- the given index. -1 for none. index will always refer to a valid index.
-
setSelectionToWidget
Description copied from class:StructuredViewerParlays 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:
setSelectionToWidgetin classAbstractListViewer- Parameters:
in- list of selected elements (element type:Object) ornullif the selection is to be clearedreveal-trueif the selection is to be made visible, andfalseotherwise
-