Class TableViewer
- All Implemented Interfaces:
- IInputProvider,- IInputSelectionProvider,- IPostSelectionProvider,- ISelectionProvider
- Direct Known Subclasses:
- CheckboxTableViewer
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
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.eclipse.jface.viewers.StructuredViewerStructuredViewer.ColorAndFontCollector, StructuredViewer.ColorAndFontCollectorWithProviders
- 
Field SummaryFields inherited from class org.eclipse.jface.viewers.ViewerWIDGET_DATA_KEY
- 
Constructor SummaryConstructorsConstructorDescriptionTableViewer(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.
- 
Method SummaryModifier and TypeMethodDescriptionprotected ColumnViewerEditorCreates the viewer editor used for editing cell contents.protected voiddoClear(int index) Clears the item at the given zero-relative index in the receiver.protected voidClears all the items in the receiver.protected voidDeselects all selected items in the receiver.protected WidgetdoFindItem(Object element) Returns the widget in this viewer's control which represent the given element.protected WidgetdoGetColumn(int index) Returns the column at the given, zero-relative index in the receiver.protected intReturns the number of columns contained in the receiver.protected ItemdoGetItem(int index) Returns the item at the given, zero-relative index in the receiver.protected intReturns the number of items contained in the receiver.protected Item[]Returns a (possibly empty) array of TableItems which are the items in the receiver.protected Item[]Returns an array ofItemthat are currently selected in the receiver.protected int[]Returns the zero-relative indices of the items which are currently selected in the receiver.protected 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 voiddoRemove(int[] indices) Removes the items from the receiver's list at the given zero-relative indices.protected voiddoRemove(int start, int end) Removes the items from the receiver which are between the given zero-relative start and end indices (inclusive).protected voidRemoves all of the items from the receiver.protected voiddoResetItem(Item item) Resets the given item in the receiver.protected voiddoSelect(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected voiddoSetItemCount(int count) Sets the number of items contained in the receiver.protected voiddoSetSelection(int[] indices) Selects the items at the given zero-relative indices in the receiver.protected voiddoSetSelection(Item[] items) Sets the receiver's selection to be the given array of items.protected voiddoShowItem(Item item) Shows the item.protected voidShows the selection.Returns the primary control associated with this viewer.protected ItemReturns theItemat the given widget-relative coordinates, ornullif there is no item at the given coordinates.getTable()Returns this table viewer's table control.protected ViewerRowgetViewerRowFromItem(Widget item) Returns aViewerRowassociated with the given row widget.protected ViewerRowinternalCreateNewRowPart(int style, int rowIndex) Create a new row with style at indexvoidrefresh(boolean updateLabels, boolean reveal) Refreshes this viewer with information freshly obtained from this viewer's model.voidRefreshes this viewer starting with the given element.voidRemoves the given elements from this table viewer.voidsetSelection(ISelection selection, boolean reveal) Sets a new selection for this viewer and optionally makes it visible.Methods inherited from class org.eclipse.jface.viewers.AbstractTableVieweradd, add, assertContentProviderType, clear, contains, doFindInputItem, doUpdateItem, getColumnViewerOwner, getElementAt, getLabelProvider, getRawChildren, getSelectionFromWidget, handleDispose, hookControl, indexForElement, inputChanged, insert, internalRefresh, internalRefresh, remove, replace, reveal, setContentProvider, setItemCount, setSelectionToWidgetMethods inherited from class org.eclipse.jface.viewers.ColumnViewerapplyEditorValue, cancelEditing, checkBusy, disassociate, editElement, firePostSelectionChanged, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getSortedChildren, getViewerRow, 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.StructuredVieweraddDoubleClickListener, 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, setSelectionToWidget, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapElement, unmapElement, update, updateItem, usingElementMapMethods inherited from class org.eclipse.jface.viewers.ContentViewergetContentProvider, getInput, labelProviderChangedMethods inherited from class org.eclipse.jface.viewers.VieweraddHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelectionMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.jface.viewers.ISelectionProvideraddSelectionChangedListener, removeSelectionChangedListener, setSelection
- 
Constructor Details- 
TableViewerCreates a table viewer on a newly-created table control under the given parent. The table 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. The table has no columns.- Parameters:
- parent- the parent control
 
- 
TableViewerCreates a table viewer on a newly-created table control under the given parent. The table control is created using the given style bits. The viewer has no input, no content provider, a default label provider, no sorter, and no filters. The table has no columns.- Parameters:
- parent- the parent control
- style- SWT style bits
 
- 
TableViewerCreates a table viewer on the given table control. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.- Parameters:
- table- the table control
 
 
- 
- 
Method Details- 
getControlDescription copied from class:ViewerReturns the primary control associated with this viewer.- Specified by:
- getControlin class- Viewer
- Returns:
- the SWT control which displays this viewer's content
 
- 
getTableReturns this table viewer's table control.- Returns:
- the table control
 
- 
createViewerEditorDescription copied from class:ColumnViewerCreates the viewer editor used for editing cell contents. To be implemented by subclasses.- Specified by:
- createViewerEditorin class- ColumnViewer
- Returns:
- the editor, or nullif this viewer does not support editing cell contents.
 
- 
setSelectionSets 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. - Overrides:
- setSelectionin class- StructuredViewer
- Parameters:
- selection- the new selection
- reveal-- trueif the selection is to be made visible, and- falseotherwise
- See Also:
 
- 
getViewerRowFromItemDescription copied from class:ColumnViewerReturns aViewerRowassociated 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.- Specified by:
- getViewerRowFromItemin class- ColumnViewer
- Parameters:
- item- the row widget
- Returns:
- ViewerRow a viewer row object
 
- 
internalCreateNewRowPartCreate a new row with style at index- Specified by:
- internalCreateNewRowPartin class- AbstractTableViewer
- Parameters:
- style- the row's style
- rowIndex- index of the new row
- Returns:
- ViewerRow
- Since:
- 3.3
 
- 
getItemAtDescription copied from class:ColumnViewerReturns theItemat the given widget-relative coordinates, ornullif there is no item at the given coordinates.- Specified by:
- getItemAtin class- ColumnViewer
- Parameters:
- p- the widget-relative coordinates
- Returns:
- the Itemat the coordinates ornullif there is no item at the given coordinates
 
- 
doGetItemCountprotected int doGetItemCount()Description copied from class:AbstractTableViewerReturns the number of items contained in the receiver.- Specified by:
- doGetItemCountin class- AbstractTableViewer
- Returns:
- the number of items
 
- 
doIndexOfDescription copied from class:AbstractTableViewerSearches 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.- Specified by:
- doIndexOfin class- AbstractTableViewer
- Parameters:
- item- the search item
- Returns:
- the index of the item
 
- 
doSetItemCountprotected void doSetItemCount(int count) Description copied from class:AbstractTableViewerSets the number of items contained in the receiver.- Specified by:
- doSetItemCountin class- AbstractTableViewer
- Parameters:
- count- the number of items
 
- 
doGetItemsDescription copied from class:AbstractTableViewerReturns a (possibly empty) array of TableItems which are the items in the receiver.- Specified by:
- doGetItemsin class- AbstractTableViewer
- Returns:
- the items in the receiver
 
- 
doGetColumnCountprotected int doGetColumnCount()Description copied from class:ColumnViewerReturns the number of columns contained in the receiver. If no columns were created by the programmer, this value is zero, despite the fact that visually, one column of items may be visible. This occurs when the programmer uses the column viewer like a list, adding elements but never creating a column.- Specified by:
- doGetColumnCountin class- ColumnViewer
- Returns:
- the number of columns
 
- 
doGetColumnDescription copied from class:AbstractTableViewerReturns 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.- Specified by:
- doGetColumnin class- AbstractTableViewer
- Parameters:
- index- the index of the column to return
- Returns:
- the column at the given index
 
- 
doGetItemDescription copied from class:AbstractTableViewerReturns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.- Specified by:
- doGetItemin class- AbstractTableViewer
- Parameters:
- index- the index of the item to return
- Returns:
- the item at the given index
 
- 
doGetSelectionDescription copied from class:AbstractTableViewerReturns 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.- Specified by:
- doGetSelectionin class- AbstractTableViewer
- Returns:
- an array representing the selection
 
- 
doGetSelectionIndicesprotected int[] doGetSelectionIndices()Description copied from class:AbstractTableViewerReturns 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.- Specified by:
- doGetSelectionIndicesin class- AbstractTableViewer
- Returns:
- an array representing the selection
 
- 
doClearAllprotected void doClearAll()Description copied from class:AbstractTableViewerClears 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.- Specified by:
- doClearAllin class- AbstractTableViewer
 
- 
doResetItemDescription copied from class:AbstractTableViewerResets the given item in the receiver. The text, icon and other attributes of the item are set to their default values.- Specified by:
- doResetItemin class- AbstractTableViewer
- Parameters:
- item- the item to reset
 
- 
doRemoveprotected void doRemove(int start, int end) Description copied from class:AbstractTableViewerRemoves the items from the receiver which are between the given zero-relative start and end indices (inclusive).- Specified by:
- doRemovein class- AbstractTableViewer
- Parameters:
- start- the start of the range
- end- the end of the range
 
- 
doRemoveAllprotected void doRemoveAll()Description copied from class:AbstractTableViewerRemoves all of the items from the receiver.- Specified by:
- doRemoveAllin class- AbstractTableViewer
 
- 
doRemoveprotected void doRemove(int[] indices) Description copied from class:AbstractTableViewerRemoves the items from the receiver's list at the given zero-relative indices.- Specified by:
- doRemovein class- AbstractTableViewer
- Parameters:
- indices- the array of indices of the items
 
- 
doShowItemDescription copied from class:AbstractTableViewerShows 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.- Specified by:
- doShowItemin class- AbstractTableViewer
- Parameters:
- item- the item to be shown
 
- 
doDeselectAllprotected void doDeselectAll()Description copied from class:AbstractTableViewerDeselects all selected items in the receiver.- Specified by:
- doDeselectAllin class- AbstractTableViewer
 
- 
doSetSelectionDescription copied from class:AbstractTableViewerSets 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. - Specified by:
- doSetSelectionin class- AbstractTableViewer
- Parameters:
- items- the array of items
 
- 
doShowSelectionprotected void doShowSelection()Description copied from class:AbstractTableViewerShows 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:
- doShowSelectionin class- AbstractTableViewer
 
- 
doSetSelectionprotected void doSetSelection(int[] indices) Description copied from class:AbstractTableViewerSelects 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. - Specified by:
- doSetSelectionin class- AbstractTableViewer
- Parameters:
- indices- the indices of the items to select
 
- 
doClearprotected void doClear(int index) Description copied from class:AbstractTableViewerClears 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.- Specified by:
- doClearin class- AbstractTableViewer
- Parameters:
- index- the index of the item to clear
- See Also:
 
- 
doSelectprotected void doSelect(int[] indices) Description copied from class:AbstractTableViewerSelects 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. - Specified by:
- doSelectin class- AbstractTableViewer
- Parameters:
- indices- the array of indices for the items to select
 
- 
refreshRefreshes this viewer starting with the given element. Labels are updated as described inrefresh(boolean updateLabels). The methods attempts to preserve the selection.Unlike the updatemethods, 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 theupdatemethods.Subclasses who can provide this feature can open this method for the public - Parameters:
- element- the element
- updateLabels-- trueto update labels for existing elements,- falseto only update labels as needed, assuming that labels for existing elements are unchanged.
- reveal-- trueto make the preserved selection visible afterwards
- Since:
- 3.3
 
- 
refreshpublic void refresh(boolean updateLabels, boolean reveal) Refreshes this viewer with information freshly obtained from this viewer's model. IfupdateLabelsistruethen 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 asrefresh().Note that the implementation may still obtain labels for existing elements even if updateLabelsis false. The intent is simply to allow optimization where possible.- Parameters:
- updateLabels-- trueto update labels for existing elements,- falseto only update labels as needed, assuming that labels for existing elements are unchanged.
- reveal-- trueto make the preserved selection visible afterwards
- Since:
- 3.3
 
- 
removeDescription copied from class:AbstractTableViewerRemoves 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. - Overrides:
- removein class- AbstractTableViewer
- Parameters:
- elements- the elements to remove
 
- 
doFindItemDescription 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. - Overrides:
- doFindItemin class- AbstractTableViewer
- Parameters:
- element- the element to find the representing widget for
- Returns:
- the corresponding widget, or nullif none
 
 
-