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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given element to this table viewer.voidAdds the given elements to this table viewer.protected voidassertContentProviderType(IContentProvider provider) Assert that the content provider is of one of the supported types.voidclear(int index) Clear the table item at the specified indexbooleanReturns true if the element is present in the viewer.protected abstract voiddoClear(int index) Clears the item at the given zero-relative index in the receiver.protected abstract voidClears all the items in the receiver.protected abstract voidDeselects all selected items in the receiver.protected WidgetdoFindInputItem(Object element) Returns the widget in this viewer's control which represents the given element if it is the viewer's input.protected WidgetdoFindItem(Object element) Returns the widget in this viewer's control which represent the given element.protected abstract WidgetdoGetColumn(int index) Returns the column at the given, zero-relative index in the receiver.protected abstract ItemdoGetItem(int index) Returns the item at the given, zero-relative index in the receiver.protected abstract intReturns 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 ofItemthat 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 intSearches 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 voiddoRemove(int[] indices) Removes the items from the receiver's list at the given zero-relative indices.protected abstract voiddoRemove(int start, int end) Removes the items from the receiver which are between the given zero-relative start and end indices (inclusive).protected abstract voidRemoves all of the items from the receiver.protected abstract voiddoResetItem(Item item) Resets the given item in the receiver.protected abstract voiddoSelect(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected abstract voiddoSetItemCount(int count) Sets the number of items contained in the receiver.protected abstract voiddoSetSelection(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected abstract voiddoSetSelection(Item[] items) Sets the receiver's selection to be the given array of items.protected abstract voiddoShowItem(Item item) Shows the item.protected abstract voidShows the selection.protected voiddoUpdateItem(Widget widget, Object element, boolean fullMap) Copies the attributes of the given element into the given SWT item.protected WidgetgetColumnViewerOwner(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 thisViewerframework method returns the label provider, which in the case of table viewers will be an instance of eitherITableLabelProviderorILabelProvider.protected Object[]getRawChildren(Object parent) Returns the children of the given parent without sorting and filtering them.protected ListRetrieves the selection, as aList, from the underlying widget.protected voidhandleDispose(DisposeEvent event) Handles a dispose event on this viewer's control.protected voidhookControl(Control control) Adds event listener hooks to the given control.protected intindexForElement(Object element) protected voidinputChanged(Object input, Object oldInput) Internal hook method called when the input to this viewer is initially set or subsequently changed.voidInserts the given element into this table viewer at the given position.protected abstract ViewerRowinternalCreateNewRowPart(int style, int rowIndex) Create a new row.protected voidinternalRefresh(Object element) Refreshes this viewer starting at the given element.protected voidinternalRefresh(Object element, boolean updateLabels) Refreshes this viewer starting at the given element.voidRemoves the given element from this table viewer.voidRemoves the given elements from this table viewer.voidReplace the element at the given index with the given element.voidEnsures that the given element is visible, scrolling the viewer if necessary.voidsetContentProvider(IContentProvider provider) Sets the content provider used by thisAbstractTableViewer.voidsetItemCount(int count) Set the item count of the receiver.protected voidsetSelectionToWidget(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, updateSelectionMethods 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, usingElementMapMethods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, labelProviderChangedMethods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getControl, 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
-
AbstractTableViewer
public AbstractTableViewer()Create the new viewer for table like widgets
-
-
Method Details
-
hookControl
Description copied from class:ContentViewerAdds event listener hooks to the given control.All subclasses must call this method when their control is first established.
The
ContentViewerimplementation of this method hooks dispose events for the given control. Subclasses may override if they need to add other control hooks; however,super.hookControlmust be invoked.- Overrides:
hookControlin classColumnViewer- Parameters:
control- the control
-
handleDispose
Description copied from class:ContentViewerHandles a dispose event on this viewer's control.The
ContentViewerimplementation 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:
handleDisposein 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:StructuredViewerReturns 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:
doFindInputItemin classStructuredViewer- Parameters:
element- the element to find the representing widget for- Returns:
- the corresponding widget, or
nullif none
-
doFindItem
Description copied from class:StructuredViewerReturns 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:
doFindItemin classStructuredViewer- Parameters:
element- the element to find the representing widget for- Returns:
- the corresponding widget, or
nullif none
-
doUpdateItem
Description copied from class:StructuredViewerCopies the attributes of the given element into the given SWT item. The element map is updated according to the value offullMap. IffullMapistruethen the current mapping from element to widgets is removed and the new mapping is added. If full map isfalsethen 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:
doUpdateItemin classStructuredViewer- Parameters:
widget- widget item to updateelement- the element to representfullMap-trueif mappings are added and removed, andfalseif only the new map gets installed
-
getColumnViewerOwner
Description copied from class:ColumnViewerReturns the column widget at the given column index.- Specified by:
getColumnViewerOwnerin classColumnViewer- Parameters:
columnIndex- the column index- Returns:
- Widget the column widget
-
getElementAt
Returns the element with the given index from this table viewer. Returnsnullif 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
nullif the index is out of range
-
getLabelProvider
The table viewer implementation of thisViewerframework method returns the label provider, which in the case of table viewers will be an instance of eitherITableLabelProviderorILabelProvider. 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:
getLabelProviderin classContentViewer- Returns:
- a label provider
-
getSelectionFromWidget
Description copied from class:StructuredViewerRetrieves the selection, as aList, from the underlying widget.- Specified by:
getSelectionFromWidgetin 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:ViewerInternal 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:
inputChangedin classViewer- Parameters:
input- the new input of this viewer, ornullif noneoldInput- the old input element ornullif 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:StructuredViewerRefreshes this viewer starting at the given element.- Specified by:
internalRefreshin classStructuredViewer- Parameters:
element- the element
-
internalRefresh
Description copied from class:StructuredViewerRefreshes 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:
internalRefreshin classStructuredViewer- Parameters:
element- the elementupdateLabels-trueto update labels for existing elements,falseto 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: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
-
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.
- Specified by:
setSelectionToWidgetin classStructuredViewer- Parameters:
list- list of selected elements (element type:Object) ornullif the selection is to be clearedreveal-trueif the selection is to be made visible, andfalseotherwise
-
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:StructuredViewerReturns 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:
getRawChildrenin 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
IStructuredContentProviderorILazyContentProvider.- Overrides:
setContentProviderin classStructuredViewer- Parameters:
provider- the content provider- See Also:
-
assertContentProviderType
Description copied from class:StructuredViewerAssert that the content provider is of one of the supported types.- Overrides:
assertContentProviderTypein 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 ofItemthat 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.VIRTUALstyle, 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.VIRTUALstyle, 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
-