Class AbstractTableViewer
- All Implemented Interfaces:
IInputProvider
,IInputSelectionProvider
,IPostSelectionProvider
,ISelectionProvider
- Direct Known Subclasses:
TableViewer
Table
like widgets can use to provide a
viewer on top of their widget implementations.
This class is not intended to be subclassed outside of the JFace viewers framework.
- Since:
- 3.3
-
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given element to this table viewer.void
Adds the given elements to this table viewer.protected void
assertContentProviderType
(IContentProvider provider) Assert that the content provider is of one of the supported types.void
clear
(int index) Clear the table item at the specified indexboolean
Returns true if the element is present in the viewer.protected abstract void
doClear
(int index) Clears the item at the given zero-relative index in the receiver.protected abstract void
Clears all the items in the receiver.protected abstract void
Deselects all selected items in the receiver.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 abstract Widget
doGetColumn
(int index) Returns the column at the given, zero-relative index in the receiver.protected abstract Item
doGetItem
(int index) Returns the item at the given, zero-relative index in the receiver.protected abstract int
Returns the number of items contained in the receiver.protected abstract Item[]
Returns a (possibly empty) array of TableItems which are the items in the receiver.protected abstract Item[]
Returns an array ofItem
that are currently selected in the receiver.protected abstract int[]
Returns the zero-relative indices of the items which are currently selected in the receiver.protected abstract int
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 abstract void
doRemove
(int[] indices) Removes the items from the receiver's list at the given zero-relative indices.protected abstract 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 abstract void
Removes all of the items from the receiver.protected abstract void
doResetItem
(Item item) Resets the given item in the receiver.protected abstract void
doSelect
(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected abstract void
doSetItemCount
(int count) Sets the number of items contained in the receiver.protected abstract void
doSetSelection
(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected abstract void
doSetSelection
(Item[] items) Sets the receiver's selection to be the given array of items.protected abstract void
doShowItem
(Item item) Shows the item.protected abstract void
Shows the selection.protected void
doUpdateItem
(Widget widget, Object element, boolean fullMap) Copies the attributes of the given element into the given SWT item.protected Widget
getColumnViewerOwner
(int columnIndex) Returns the column widget at the given column index.getElementAt
(int index) Returns the element with the given index from this table viewer.The table viewer implementation of thisViewer
framework method returns the label provider, which in the case of table viewers will be an instance of eitherITableLabelProvider
orILabelProvider
.protected Object[]
getRawChildren
(Object parent) Returns the children of the given parent without sorting and filtering them.protected List
Retrieves the selection, as aList
, from the underlying widget.protected void
handleDispose
(DisposeEvent event) Handles a dispose event on this viewer's control.protected void
hookControl
(Control control) Adds event listener hooks to the given control.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.void
Inserts the given element into this table viewer at the given position.protected abstract ViewerRow
internalCreateNewRowPart
(int style, int rowIndex) Create a new row.protected void
internalRefresh
(Object element) Refreshes this viewer starting at the given element.protected void
internalRefresh
(Object element, boolean updateLabels) Refreshes this viewer starting at the given element.void
Removes the given element from this table viewer.void
Removes the given elements from this table viewer.void
Replace the element at the given index with the given element.void
Ensures that the given element is visible, scrolling the viewer if necessary.void
setContentProvider
(IContentProvider provider) Sets the content provider used by thisAbstractTableViewer
.void
setItemCount
(int count) Set the item count of the receiver.protected void
setSelectionToWidget
(List list, boolean reveal) Parlays the given list of selected elements into selections on this viewer's control.Methods inherited from class org.eclipse.jface.viewers.ColumnViewer
applyEditorValue, cancelEditing, checkBusy, createViewerEditor, disassociate, doGetColumnCount, editElement, firePostSelectionChanged, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getItemAt, getLabelProvider, getSortedChildren, getViewerRow, getViewerRowFromItem, handleDoubleSelect, hookEditingSupport, isBusy, isCellEditorActive, isExpandableNode, refresh, refresh, setBusy, setCellEditors, setCellModifier, setColumnProperties, setColumnViewerEditor, setDisplayIncrementally, setLabelProvider, triggerEditorActivationEvent, unmapAllElements, update, updateSelection
Methods inherited from class org.eclipse.jface.viewers.StructuredViewer
addDoubleClickListener, addDragSupport, addDropSupport, addFilter, addOpenListener, addPostSelectionChangedListener, assertElementsNotNull, associate, buildLabel, equals, filter, findItem, findItems, fireDoubleClick, fireOpen, getColorAndFontCollector, getComparator, getComparer, getFilteredChildren, getFilters, getRoot, getSelection, getSorter, getStructuredSelection, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, handleSelect, hasFilters, internalUpdate, mapElement, needsRefilter, preservingSelection, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setFilters, setInput, setSelection, setSelectionToWidget, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapElement, unmapElement, update, updateItem, usingElementMap
Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, labelProviderChanged
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getControl, 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
Methods inherited from interface org.eclipse.jface.viewers.ISelectionProvider
addSelectionChangedListener, removeSelectionChangedListener, setSelection
-
Constructor Details
-
AbstractTableViewer
public AbstractTableViewer()Create the new viewer for table like widgets
-
-
Method Details
-
hookControl
Description copied from class:ContentViewer
Adds event listener hooks to the given control.All subclasses must call this method when their control is first established.
The
ContentViewer
implementation of this method hooks dispose events for the given control. Subclasses may override if they need to add other control hooks; however,super.hookControl
must be invoked.- Overrides:
hookControl
in classColumnViewer
- Parameters:
control
- the control
-
handleDispose
Description copied from class:ContentViewer
Handles a dispose event on this viewer's control.The
ContentViewer
implementation of this method disposes of this viewer's label provider and content provider (if it has one). Subclasses should override this method to perform any additional cleanup of resources; however, overriding methods must invokesuper.handleDispose
.- Overrides:
handleDispose
in classColumnViewer
- Parameters:
event
- a dispose event
-
add
Adds the given elements to this table 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
-
internalCreateNewRowPart
Create a new row. Callers can only use the returned object locally and before making the next call on the viewer since it may be re-used for subsequent method calls.- Parameters:
style
- the style for the new rowrowIndex
- the index of the row or -1 if the row is appended at the end- Returns:
- the newly created row
-
add
Adds the given element to this table 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 to add
-
doFindInputItem
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 classStructuredViewer
- Parameters:
element
- the element to find the representing widget for- Returns:
- the corresponding widget, or
null
if none
-
doFindItem
Description copied from class:StructuredViewer
Returns the widget in this viewer's control which represent the given element. This method searches all the children of the input element.This method is internal to the framework; subclassers should not call this method.
- Specified by:
doFindItem
in classStructuredViewer
- Parameters:
element
- the element to find the representing widget for- Returns:
- the corresponding widget, or
null
if none
-
doUpdateItem
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 offullMap
. IffullMap
istrue
then the current mapping from element to widgets is removed and the new mapping is added. If full map isfalse
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 classStructuredViewer
- Parameters:
widget
- widget item to updateelement
- the element to representfullMap
-true
if mappings are added and removed, andfalse
if only the new map gets installed
-
getColumnViewerOwner
Description copied from class:ColumnViewer
Returns the column widget at the given column index.- Specified by:
getColumnViewerOwner
in classColumnViewer
- Parameters:
columnIndex
- the column index- Returns:
- Widget the column widget
-
getElementAt
Returns the element with the given index from this table viewer. Returnsnull
if the index is out of range.This method is internal to the framework.
- Parameters:
index
- the zero-based index- Returns:
- the element at the given index, or
null
if the index is out of range
-
getLabelProvider
The table viewer implementation of thisViewer
framework method returns the label provider, which in the case of table viewers will be an instance of eitherITableLabelProvider
orILabelProvider
. If it is anITableLabelProvider
, then it provides a separate label text and image for each column. If it is anILabelProvider
, then it provides only the label text and image for the first column, and any remaining columns are blank.- Overrides:
getLabelProvider
in classContentViewer
- Returns:
- a label provider
-
getSelectionFromWidget
Description copied from class:StructuredViewer
Retrieves the selection, as aList
, from the underlying widget.- Specified by:
getSelectionFromWidget
in classStructuredViewer
- Returns:
- the list of selected elements
-
indexForElement
- Parameters:
element
- the element to insert- Returns:
- the index where the item should be inserted.
-
inputChanged
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 classViewer
- Parameters:
input
- the new input of this viewer, ornull
if noneoldInput
- the old input element ornull
if there was previously no input
-
insert
Inserts the given element into this table viewer at the given position. If this viewer has a sorter, the position is ignored and the element is inserted at the correct position in the sort order.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:
element
- the elementposition
- a 0-based position relative to the model, or -1 to indicate the last position
-
internalRefresh
Description copied from class:StructuredViewer
Refreshes this viewer starting at the given element.- Specified by:
internalRefresh
in classStructuredViewer
- Parameters:
element
- the element
-
internalRefresh
Description copied from class:StructuredViewer
Refreshes this viewer starting at the given element. Labels are updated as described inrefresh(boolean updateLabels)
.The default implementation simply calls
internalRefresh(element)
, ignoringupdateLabels
.If this method is overridden to do the actual refresh, then
internalRefresh(Object element)
should simply callinternalRefresh(element, true)
.- Overrides:
internalRefresh
in classStructuredViewer
- Parameters:
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.
-
remove
Removes the given elements from this table 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
Removes the given element from this table 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.
NOTE: removing an object from a virtual table will decrement the itemCount.- Parameters:
element
- the element
-
reveal
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 classStructuredViewer
- Parameters:
element
- the element to reveal
-
setSelectionToWidget
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 classStructuredViewer
- Parameters:
list
- list of selected elements (element type:Object
) ornull
if the selection is to be clearedreveal
-true
if the selection is to be made visible, andfalse
otherwise
-
setItemCount
public void setItemCount(int count) Set the item count of the receiver.- Parameters:
count
- the new table size.- Since:
- 3.1
-
replace
Replace the element at the given index with the given element. This method will not call the content provider to verify. Note that this method will materialize a TableItem the given index..- Parameters:
element
- the new elementindex
- the index of the table item to replace- Since:
- 3.1
- See Also:
-
clear
public void clear(int index) Clear the table item at the specified index- Parameters:
index
- the index of the table item to be cleared- Since:
- 3.1
-
getRawChildren
Description copied from class:StructuredViewer
Returns the children of the given parent without sorting and filtering them. The resulting array must not be modified, as it may come directly from the model's internal state.Returns an empty array if the given parent is
null
.- Overrides:
getRawChildren
in classColumnViewer
- Parameters:
parent
- the parent element- Returns:
- the child elements
-
setContentProvider
Sets the content provider used by thisAbstractTableViewer
.Content providers for abstract table viewers must implement either
IStructuredContentProvider
orILazyContentProvider
.- Overrides:
setContentProvider
in classStructuredViewer
- Parameters:
provider
- the content provider- See Also:
-
assertContentProviderType
Description copied from class:StructuredViewer
Assert that the content provider is of one of the supported types.- Overrides:
assertContentProviderType
in classStructuredViewer
- Parameters:
provider
- content provider to check
-
doIndexOf
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. If no item is found, returns -1.- Parameters:
item
- the search item- Returns:
- the index of the item
- Since:
- 3.3
-
doGetItemCount
protected abstract int doGetItemCount()Returns the number of items contained in the receiver.- Returns:
- the number of items
- Since:
- 3.3
-
doSetItemCount
protected abstract void doSetItemCount(int count) Sets the number of items contained in the receiver.- Parameters:
count
- the number of items- Since:
- 3.3
-
doGetItems
Returns a (possibly empty) array of TableItems which are the items in the receiver.- Returns:
- the items in the receiver
- Since:
- 3.3
-
doGetColumn
Returns the column at the given, zero-relative index in the receiver. Throws an exception if the index is out of range. Columns are returned in the order that they were created. If no TableColumns were created by the programmer, this method will throw ERROR_INVALID_RANGE despite the fact that a single column of data may be visible in the table. This occurs when the programmer uses the table like a list, adding items but never creating a column.- Parameters:
index
- the index of the column to return- Returns:
- the column at the given index
- Throws:
IllegalArgumentException
- - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)- Since:
- 3.3
-
doGetItem
Returns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.- Parameters:
index
- the index of the item to return- Returns:
- the item at the given index
- Throws:
IllegalArgumentException
- - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)- Since:
- 3.3
-
doGetSelection
Returns an array ofItem
that are currently selected in the receiver. The order of the items is unspecified. An empty array indicates that no items are selected.- Returns:
- an array representing the selection
- Since:
- 3.3
-
doGetSelectionIndices
protected abstract int[] doGetSelectionIndices()Returns the zero-relative indices of the items which are currently selected in the receiver. The order of the indices is unspecified. The array is empty if no items are selected.- Returns:
- an array representing the selection
- Since:
- 3.3
-
doClearAll
protected abstract void doClearAll()Clears all the items in the receiver. The text, icon and other attributes of the items are set to their default values. If the table was created with theSWT.VIRTUAL
style, these attributes are requested again as needed.- Since:
- 3.3
-
doResetItem
Resets the given item in the receiver. The text, icon and other attributes of the item are set to their default values.- Parameters:
item
- the item to reset- Since:
- 3.3
-
doRemove
protected abstract void doRemove(int start, int end) Removes the items from the receiver which are between the given zero-relative start and end indices (inclusive).- Parameters:
start
- the start of the rangeend
- the end of the range- Throws:
IllegalArgumentException
- - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)- Since:
- 3.3
-
doRemoveAll
protected abstract void doRemoveAll()Removes all of the items from the receiver.- Since:
- 3.3
-
doRemove
protected abstract void doRemove(int[] indices) Removes the items from the receiver's list at the given zero-relative indices.- Parameters:
indices
- the array of indices of the items- Throws:
IllegalArgumentException
- - if the array is null, or if any of the indices is not between 0 and the number of elements in the list minus 1 (inclusive)- Since:
- 3.3
-
doShowItem
Shows the item. If the item is already showing in the receiver, this method simply returns. Otherwise, the items are scrolled until the item is visible.- Parameters:
item
- the item to be shown- Throws:
IllegalArgumentException
- - if the item is null- Since:
- 3.3
-
doDeselectAll
protected abstract void doDeselectAll()Deselects all selected items in the receiver.- Since:
- 3.3
-
doSetSelection
Sets the receiver's selection to be the given array of items. The current selection is cleared before the new items are selected, and if necessary the receiver is scrolled to make the new selection visible.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.
- Parameters:
items
- the array of items- Throws:
IllegalArgumentException
- - if the array of items is null- Since:
- 3.3
-
doShowSelection
protected abstract void doShowSelection()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.- Since:
- 3.3
-
doSetSelection
protected abstract void doSetSelection(int[] indices) Selects the items at the given zero-relative indices in the receiver. The current selection is cleared before the new items are selected, and if necessary the receiver is scrolled to make the new selection visible.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.
- Parameters:
indices
- the indices of the items to select- Throws:
IllegalArgumentException
- - if the array of indices is null- Since:
- 3.3
-
doClear
protected abstract void doClear(int index) Clears the item at the given zero-relative index in the receiver. The text, icon and other attributes of the item are set to the default value. If the table was created with theSWT.VIRTUAL
style, these attributes are requested again as needed.- Parameters:
index
- the index of the item to clear- Throws:
IllegalArgumentException
- - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)- Since:
- 3.3
- See Also:
-
doSelect
protected abstract void doSelect(int[] indices) Selects the items at the given zero-relative indices in the receiver. The current selection is not cleared before the new items are selected.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.
- Parameters:
indices
- the array of indices for the items to select- Throws:
IllegalArgumentException
- - if the array of indices is null
-
contains
Returns true if the element is present in the viewer. If the viewer has incremental display set then the element is searched inside expandable node also. i.e. it searches inside the remaining elements to be populated.- Parameters:
element
- model element- Returns:
- if given model element is contained in the viewer
- Since:
- 3.31
-