Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.jface.viewers
Class TableViewer


java.lang.Object
  extended by 

org.eclipse.jface.viewers.Viewer
      extended by 

org.eclipse.jface.viewers.ContentViewer
          extended by 

org.eclipse.jface.viewers.StructuredViewer
              extended by 

org.eclipse.jface.viewers.ColumnViewer
                  extended by 

org.eclipse.jface.viewers.AbstractTableViewer
                      extended by 
org.eclipse.jface.viewers.TableViewer
All Implemented Interfaces:
IInputProvider, IInputSelectionProvider, IPostSelectionProvider, ISelectionProvider
Direct Known Subclasses:
CheckboxTableViewer

public class TableViewer
extends AbstractTableViewer

A concrete viewer based on a SWT 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:
SWT.VIRTUAL, doFindItem(Object), AbstractTableViewer.internalRefresh(Object, boolean)
Restriction:
This class is not intended to be subclassed by clients.

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
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.
 
Method Summary
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.
 
Methods inherited from class org.eclipse.jface.viewers. AbstractTableViewer
add, add, assertContentProviderType, clear, doFindInputItem, doUpdateItem, getColumnViewerOwner, getElementAt, getLabelProvider, getRawChildren, getSelectionFromWidget, handleDispose, hookControl, indexForElement, inputChanged, insert, internalRefresh, internalRefresh, remove, replace, reveal, setItemCount, setSelectionToWidget
 
Methods inherited from class org.eclipse.jface.viewers. ColumnViewer
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
 
Methods inherited from class org.eclipse.jface.viewers. StructuredViewer
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
 
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, 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 Detail

TableViewer

public TableViewer(
Composite parent)
Creates a table viewer on a newly-created table control under the given parent. The table control is created using the SWT style bits 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.

Parameters:
parent - the parent control

TableViewer

public TableViewer(
Composite parent,
                   int style)
Creates 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

TableViewer

public TableViewer(
Table table)
Creates 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 Detail

getControl

public 
Control getControl()
Description copied from class: Viewer
Returns the primary control associated with this viewer.

Specified by:
getControl in class Viewer
Returns:
the SWT control which displays this viewer's content

getTable

public 
Table getTable()
Returns this table viewer's table control.

Returns:
the table control

createViewerEditor

protected 
ColumnViewerEditor createViewerEditor()
Description copied from class: ColumnViewer
Creates the viewer editor used for editing cell contents. To be implemented by subclasses.

Specified by:
createViewerEditor in class ColumnViewer
Returns:
the editor, or null if this viewer does not support editing cell contents.

setSelection

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.

Overrides:
setSelection in class StructuredViewer
Parameters:
selection - the new selection
reveal - true if the selection is to be made visible, and false otherwise
See Also:
Table.setSelection(int[]), Table.showSelection()

getViewerRowFromItem

protected 
ViewerRow getViewerRowFromItem(
Widget item)
Description copied from class: ColumnViewer
Returns a 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.

Specified by:
getViewerRowFromItem in class ColumnViewer
Parameters:
item - the row widget
Returns:
ViewerRow a viewer row object

internalCreateNewRowPart

protected 
ViewerRow internalCreateNewRowPart(int style,
                                             int rowIndex)
Create a new row with style at index

Specified by:
internalCreateNewRowPart in class AbstractTableViewer
Parameters:
style -
rowIndex -
Returns:
ViewerRow
Since:
3.3

getItemAt

protected 
Item getItemAt(
Point p)
Description copied from class: ColumnViewer
Returns the Item at the given widget-relative coordinates, or null if there is no item at the given coordinates.

Specified by:
getItemAt in class ColumnViewer
Parameters:
p - the widget-relative coordinates
Returns:
the Item at the coordinates or null if there is no item at the given coordinates

doGetItemCount

protected int doGetItemCount()
Description copied from class: AbstractTableViewer
Returns the number of items contained in the receiver.

Specified by:
doGetItemCount in class AbstractTableViewer
Returns:
the number of items

doIndexOf

protected int doIndexOf(
Item item)
Description copied from class: AbstractTableViewer
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.

Specified by:
doIndexOf in class AbstractTableViewer
Parameters:
item - the search item
Returns:
the index of the item

doSetItemCount

protected void doSetItemCount(int count)
Description copied from class: AbstractTableViewer
Sets the number of items contained in the receiver.

Specified by:
doSetItemCount in class AbstractTableViewer
Parameters:
count - the number of items

doGetItems

protected 
Item[] doGetItems()
Description copied from class: AbstractTableViewer
Returns a (possibly empty) array of TableItems which are the items in the receiver.

Specified by:
doGetItems in class AbstractTableViewer
Returns:
the items in the receiver

doGetColumnCount

protected int doGetColumnCount()
Description copied from class: ColumnViewer
Returns 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:
doGetColumnCount in class ColumnViewer
Returns:
the number of columns

doGetColumn

protected 
Widget doGetColumn(int index)
Description copied from class: AbstractTableViewer
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.

Specified by:
doGetColumn in class AbstractTableViewer
Parameters:
index - the index of the column to return
Returns:
the column at the given index

doGetItem

protected 
Item doGetItem(int index)
Description copied from class: AbstractTableViewer
Returns the item at the given, zero-relative index in the receiver. Throws an exception if the index is out of range.

Specified by:
doGetItem in class AbstractTableViewer
Parameters:
index - the index of the item to return
Returns:
the item at the given index

doGetSelection

protected 
Item[] doGetSelection()
Description copied from class: AbstractTableViewer
Returns an array of Item that are currently selected in the receiver. The order of the items is unspecified. An empty array indicates that no items are selected.

Specified by:
doGetSelection in class AbstractTableViewer
Returns:
an array representing the selection

doGetSelectionIndices

protected int[] doGetSelectionIndices()
Description copied from class: AbstractTableViewer
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.

Specified by:
doGetSelectionIndices in class AbstractTableViewer
Returns:
an array representing the selection

doClearAll

protected void doClearAll()
Description copied from class: AbstractTableViewer
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 the SWT.VIRTUAL style, these attributes are requested again as needed.

Specified by:
doClearAll in class AbstractTableViewer

doResetItem

protected void doResetItem(
Item item)
Description copied from class: AbstractTableViewer
Resets the given item in the receiver. The text, icon and other attributes of the item are set to their default values.

Specified by:
doResetItem in class AbstractTableViewer
Parameters:
item - the item to reset

doRemove

protected void doRemove(int start,
                        int end)
Description copied from class: AbstractTableViewer
Removes the items from the receiver which are between the given zero-relative start and end indices (inclusive).

Specified by:
doRemove in class AbstractTableViewer
Parameters:
start - the start of the range
end - the end of the range

doRemoveAll

protected void doRemoveAll()
Description copied from class: AbstractTableViewer
Removes all of the items from the receiver.

Specified by:
doRemoveAll in class AbstractTableViewer

doRemove

protected void doRemove(int[] indices)
Description copied from class: AbstractTableViewer
Removes the items from the receiver's list at the given zero-relative indices.

Specified by:
doRemove in class AbstractTableViewer
Parameters:
indices - the array of indices of the items

doShowItem

protected void doShowItem(
Item item)
Description copied from class: AbstractTableViewer
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.

Specified by:
doShowItem in class AbstractTableViewer
Parameters:
item - the item to be shown

doDeselectAll

protected void doDeselectAll()
Description copied from class: AbstractTableViewer
Deselects all selected items in the receiver.

Specified by:
doDeselectAll in class AbstractTableViewer

doSetSelection

protected void doSetSelection(
Item[] items)
Description copied from class: AbstractTableViewer
Sets the receiver's selection to be the given array of items. The current selection is cleared before the new items are selected.

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:
doSetSelection in class AbstractTableViewer
Parameters:
items - the array of items

doShowSelection

protected void doShowSelection()
Description copied from class: AbstractTableViewer
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.

Specified by:
doShowSelection in class AbstractTableViewer

doSetSelection

protected void doSetSelection(int[] indices)
Description copied from class: AbstractTableViewer
Selects the items at the given zero-relative indices in the receiver. 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:
doSetSelection in class AbstractTableViewer
Parameters:
indices - the indices of the items to select

doClear

protected void doClear(int index)
Description copied from class: AbstractTableViewer
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 the SWT.VIRTUAL style, these attributes are requested again as needed.

Specified by:
doClear in class AbstractTableViewer
Parameters:
index - the index of the item to clear
See Also:
SWT.VIRTUAL, SWT.SetData

doSelect

protected void doSelect(int[] indices)
Description copied from class: AbstractTableViewer
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.

Specified by:
doSelect in class AbstractTableViewer
Parameters:
indices - the array of indices for the items to select

refresh

public void refresh(
Object element,
                    boolean updateLabels,
                    boolean reveal)
Refreshes this viewer starting with the given element. Labels are updated as described in 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

Parameters:
element - the element
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 afterwards
Since:
3.3

refresh

public void refresh(boolean updateLabels,
                    boolean reveal)
Refreshes this viewer with information freshly obtained from this viewer's model. If 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.

Parameters:
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 afterwards
Since:
3.3

remove

public void remove(
Object[] elements)
Description copied from class: AbstractTableViewer
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.

Overrides:
remove in class AbstractTableViewer
Parameters:
elements - the elements to remove

doFindItem

protected 
Widget doFindItem(
Object element)
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.

Overrides:
doFindItem in class AbstractTableViewer
Returns:
the corresponding widget, or null if none

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire