public class TableViewer extends AbstractTableViewer
Table
control.
This class is not intended to be subclassed outside the viewer framework. It is designed to be instantiated with a pre-existing SWT table control and configured with a domain-specific content provider, table label provider, element filter (optional), and element sorter (optional).
Label providers for table viewers must implement either the
ITableLabelProvider
or the ILabelProvider
interface
(see TableViewer.setLabelProvider
for more details).
As of 3.1 the TableViewer now supports the SWT.VIRTUAL flag. If the
underlying table is SWT.VIRTUAL, the content provider may implement ILazyContentProvider
instead of IStructuredContentProvider
. Note
that in this case, the viewer does not support sorting or filtering. Also
note that in this case, the Widget based APIs may return null if the element
is not specified or not created yet.
Users of SWT.VIRTUAL should also avoid using getItems() from the Table within the TreeViewer as this does not necessarily generate a callback for the TreeViewer to populate the items. It also has the side effect of creating all of the items thereby eliminating the performance improvements of SWT.VIRTUAL.
Users setting up an editable table with more than 1 column have to pass the SWT.FULL_SELECTION style bit
SWT.VIRTUAL
,
doFindItem(Object)
,
AbstractTableViewer.internalRefresh(Object, boolean)
StructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
WIDGET_DATA_KEY
Constructor and Description |
---|
TableViewer(Composite parent)
Creates a table viewer on a newly-created table control under the given
parent.
|
TableViewer(Composite parent,
int style)
Creates a table viewer on a newly-created table control under the given
parent.
|
TableViewer(Table table)
Creates a table viewer on the given table control.
|
Modifier and Type | Method and Description |
---|---|
protected ColumnViewerEditor |
createViewerEditor()
Creates the viewer editor used for editing cell contents.
|
protected void |
doClear(int index)
Clears the item at the given zero-relative index in the receiver.
|
protected void |
doClearAll()
Clears all the items in the receiver.
|
protected void |
doDeselectAll()
Deselects all selected items in the receiver.
|
protected Widget |
doFindItem(Object element)
Returns the widget in this viewer's control which represent the given
element.
|
protected Widget |
doGetColumn(int index)
Returns the column at the given, zero-relative index in the receiver.
|
protected int |
doGetColumnCount()
Returns the number of columns contained in the receiver.
|
protected Item |
doGetItem(int index)
Returns the item at the given, zero-relative index in the receiver.
|
protected int |
doGetItemCount()
Returns the number of items contained in the receiver.
|
protected Item[] |
doGetItems()
Returns a (possibly empty) array of TableItems which are the items in the
receiver.
|
protected Item[] |
doGetSelection()
Returns an array of
Item that are currently selected in the
receiver. |
protected int[] |
doGetSelectionIndices()
Returns the zero-relative indices of the items which are currently
selected in the receiver.
|
protected int |
doIndexOf(Item item)
Searches the receiver's list starting at the first item (index 0) until
an item is found that is equal to the argument, and returns the index of
that item.
|
protected void |
doRemove(int[] indices)
Removes the items from the receiver's list at the given zero-relative
indices.
|
protected void |
doRemove(int start,
int end)
Removes the items from the receiver which are between the given
zero-relative start and end indices (inclusive).
|
protected void |
doRemoveAll()
Removes all of the items from the receiver.
|
protected void |
doResetItem(Item item)
Resets the given item in the receiver.
|
protected void |
doSelect(int[] indices)
Selects the items at the given zero-relative indices in the receiver.
|
protected void |
doSetItemCount(int count)
Sets the number of items contained in the receiver.
|
protected void |
doSetSelection(int[] indices)
Selects the items at the given zero-relative indices in the receiver.
|
protected void |
doSetSelection(Item[] items)
Sets the receiver's selection to be the given array of items.
|
protected void |
doShowItem(Item item)
Shows the item.
|
protected void |
doShowSelection()
Shows the selection.
|
Control |
getControl()
Returns the primary control associated with this viewer.
|
protected Item |
getItemAt(Point p)
Returns the
Item at the given widget-relative coordinates, or
null if there is no item at the given coordinates. |
Table |
getTable()
Returns this table viewer's table control.
|
protected ViewerRow |
getViewerRowFromItem(Widget item)
Returns a
ViewerRow associated with the given row widget. |
protected ViewerRow |
internalCreateNewRowPart(int style,
int rowIndex)
Create a new row with style at index
|
void |
refresh(boolean updateLabels,
boolean reveal)
Refreshes this viewer with information freshly obtained from this
viewer's model.
|
void |
refresh(Object element,
boolean updateLabels,
boolean reveal)
Refreshes this viewer starting with the given element.
|
void |
remove(Object[] elements)
Removes the given elements from this table viewer.
|
void |
setSelection(ISelection selection,
boolean reveal)
Sets a new selection for this viewer and optionally makes it visible.
|
add, add, assertContentProviderType, clear, doFindInputItem, doUpdateItem, getColumnViewerOwner, getElementAt, getLabelProvider, getRawChildren, getSelectionFromWidget, handleDispose, hookControl, indexForElement, inputChanged, insert, internalRefresh, internalRefresh, remove, replace, reveal, setItemCount, setSelectionToWidget
applyEditorValue, cancelEditing, checkBusy, editElement, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getViewerRow, hookEditingSupport, isBusy, isCellEditorActive, refresh, refresh, setBusy, setCellEditors, setCellModifier, setColumnProperties, setColumnViewerEditor, setLabelProvider, triggerEditorActivationEvent, update
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, assertElementsNotNull, associate, buildLabel, disassociate, equals, filter, findItem, findItems, fireDoubleClick, fireOpen, firePostSelectionChanged, getColorAndFontCollector, getComparator, getComparer, getFilteredChildren, getFilters, getRoot, getSelection, getSortedChildren, getSorter, handleDoubleSelect, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, handleSelect, hasFilters, internalUpdate, mapElement, needsRefilter, preservingSelection, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setContentProvider, setFilters, setInput, setSelectionToWidget, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapAllElements, unmapElement, unmapElement, 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 TableViewer(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. The table has no columns.parent
- the parent controlpublic TableViewer(Composite parent, int style)
parent
- the parent controlstyle
- SWT style bitspublic TableViewer(Table table)
table
- the table controlpublic Control getControl()
Viewer
getControl
in class Viewer
public Table getTable()
protected ColumnViewerEditor createViewerEditor()
ColumnViewer
createViewerEditor
in class ColumnViewer
null
if this viewer does not support
editing cell contents.public void setSelection(ISelection selection, boolean reveal)
Sets a new selection for this viewer and optionally makes it visible. The TableViewer implementation of this method is inefficient for the ILazyContentProvider as lookup is done by indices rather than elements and may require population of the entire table in worse case.
Use Table#setSelection(int[] indices) and Table#showSelection() if you wish to set selection more efficiently when using a ILazyContentProvider.
setSelection
in class StructuredViewer
selection
- the new selectionreveal
- true
if the selection is to be made visible, and
false
otherwiseTable.setSelection(int[])
,
Table.showSelection()
protected ViewerRow getViewerRowFromItem(Widget item)
ColumnViewer
ViewerRow
associated with the given row widget.
Implementations may re-use the same instance for different row widgets;
callers can only use the viewer row locally and until the next call to
this method.getViewerRowFromItem
in class ColumnViewer
item
- the row widgetprotected ViewerRow internalCreateNewRowPart(int style, int rowIndex)
internalCreateNewRowPart
in class AbstractTableViewer
style
- rowIndex
- protected Item getItemAt(Point p)
ColumnViewer
Item
at the given widget-relative coordinates, or
null
if there is no item at the given coordinates.getItemAt
in class ColumnViewer
p
- the widget-relative coordinatesItem
at the coordinates or null
if there
is no item at the given coordinatesprotected int doGetItemCount()
AbstractTableViewer
doGetItemCount
in class AbstractTableViewer
protected int doIndexOf(Item item)
AbstractTableViewer
doIndexOf
in class AbstractTableViewer
item
- the search itemprotected void doSetItemCount(int count)
AbstractTableViewer
doSetItemCount
in class AbstractTableViewer
count
- the number of itemsprotected Item[] doGetItems()
AbstractTableViewer
doGetItems
in class AbstractTableViewer
protected int doGetColumnCount()
ColumnViewer
doGetColumnCount
in class ColumnViewer
protected Widget doGetColumn(int index)
AbstractTableViewer
doGetColumn
in class AbstractTableViewer
index
- the index of the column to returnprotected Item doGetItem(int index)
AbstractTableViewer
doGetItem
in class AbstractTableViewer
index
- the index of the item to returnprotected Item[] doGetSelection()
AbstractTableViewer
Item
that are currently selected in the
receiver. The order of the items is unspecified. An empty array indicates
that no items are selected.doGetSelection
in class AbstractTableViewer
protected int[] doGetSelectionIndices()
AbstractTableViewer
doGetSelectionIndices
in class AbstractTableViewer
protected void doClearAll()
AbstractTableViewer
SWT.VIRTUAL
style, these attributes are requested
again as needed.doClearAll
in class AbstractTableViewer
protected void doResetItem(Item item)
AbstractTableViewer
doResetItem
in class AbstractTableViewer
item
- the item to resetprotected void doRemove(int start, int end)
AbstractTableViewer
doRemove
in class AbstractTableViewer
start
- the start of the rangeend
- the end of the rangeprotected void doRemoveAll()
AbstractTableViewer
doRemoveAll
in class AbstractTableViewer
protected void doRemove(int[] indices)
AbstractTableViewer
doRemove
in class AbstractTableViewer
indices
- the array of indices of the itemsprotected void doShowItem(Item item)
AbstractTableViewer
doShowItem
in class AbstractTableViewer
item
- the item to be shownprotected void doDeselectAll()
AbstractTableViewer
doDeselectAll
in class AbstractTableViewer
protected void doSetSelection(Item[] items)
AbstractTableViewer
Items that are not in the receiver are ignored. If the receiver is single-select and multiple items are specified, then all items are ignored.
doSetSelection
in class AbstractTableViewer
items
- the array of itemsprotected void doShowSelection()
AbstractTableViewer
doShowSelection
in class AbstractTableViewer
protected void doSetSelection(int[] indices)
AbstractTableViewer
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.
doSetSelection
in class AbstractTableViewer
indices
- the indices of the items to selectprotected void doClear(int index)
AbstractTableViewer
SWT.VIRTUAL
style, these
attributes are requested again as needed.doClear
in class AbstractTableViewer
index
- the index of the item to clearSWT.VIRTUAL
,
SWT.SetData
protected void doSelect(int[] indices)
AbstractTableViewer
If the item at a given index is not selected, it is selected. If the item at a given index was already selected, it remains 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.
doSelect
in class AbstractTableViewer
indices
- the array of indices for the items to selectpublic void refresh(Object element, boolean updateLabels, boolean reveal)
refresh(boolean updateLabels)
. The methods
attempts to preserve the selection.
Unlike the update
methods, this handles structural changes
to the given element (e.g. addition or removal of children). If only the
given element needs updating, it is more efficient to use the
update
methods.
Subclasses who can provide this feature can open this method for the public
element
- the elementupdateLabels
- true
to update labels for existing elements,
false
to only update labels as needed, assuming that labels
for existing elements are unchanged.reveal
- true
to make the preserved selection visible afterwardspublic void refresh(boolean updateLabels, boolean reveal)
updateLabels
is true
then
labels for otherwise unaffected elements are updated as well. Otherwise,
it assumes labels for existing elements are unchanged, and labels are
only obtained as needed (for example, for new elements).
Calling refresh(true)
has the same effect as
refresh()
.
Note that the implementation may still obtain labels for existing
elements even if updateLabels
is false. The intent is simply
to allow optimization where possible.
updateLabels
- true
to update labels for existing elements,
false
to only update labels as needed, assuming that labels
for existing elements are unchanged.reveal
- true
to make the preserved selection visible afterwardspublic void remove(Object[] elements)
AbstractTableViewer
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.
remove
in class AbstractTableViewer
elements
- the elements to removeprotected Widget doFindItem(Object element)
StructuredViewer
This method is internal to the framework; subclassers should not call this method.
doFindItem
in class AbstractTableViewer
null
if none
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.