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 CheckboxTableViewer


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
                          extended by 
org.eclipse.jface.viewers.CheckboxTableViewer
All Implemented Interfaces:
ICheckable, IInputProvider, IInputSelectionProvider, IPostSelectionProvider, ISelectionProvider

public class CheckboxTableViewer
extends TableViewer
implements ICheckable

A concrete viewer based on an SWT Table control with checkboxes on each node.

This class supports setting an ICheckStateProvider to set the checkbox states. To see standard SWT behavior, view SWT Snippet274.

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, label provider, element filter (optional), and element sorter (optional).

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
CheckboxTableViewer ( Composite parent)
          Deprecated. use newCheckList(Composite, int) or new CheckboxTableViewer(Table) instead (see below for details)
CheckboxTableViewer ( Composite parent, int style)
          Deprecated. use newCheckList(Composite, int) or new CheckboxTableViewer(Table) instead (see above for details)
CheckboxTableViewer ( Table table)
          Creates a table viewer on the given table control.
 
Method Summary
 void addCheckStateListener ( ICheckStateListener listener)
          Adds a listener for changes to the checked state of elements in this viewer.
protected static  Table createTable ( Composite parent, int style)
          Creates a new table control with one column.
protected  void doUpdateItem ( Widget widget, Object element, boolean fullMap)
          Copies the attributes of the given element into the given SWT item.
 boolean getChecked ( Object element)
          Returns the checked state of the given element.
  Object[] getCheckedElements ()
          Returns a list of elements corresponding to checked table items in this viewer.
 boolean getGrayed ( Object element)
          Returns the grayed state of the given element.
  Object[] getGrayedElements ()
          Returns a list of elements corresponding to grayed nodes in this viewer.
 void handleSelect ( SelectionEvent event)
          Handles a select event from the widget.
static  CheckboxTableViewer newCheckList ( Composite parent, int style)
          Creates a table viewer on a newly-created table control under the given parent.
protected  void preservingSelection ( Runnable updateCode)
          Attempts to preserves the current selection across a run of the given code.
 void removeCheckStateListener ( ICheckStateListener listener)
          Removes the given check state listener from this viewer.
 void setAllChecked (boolean state)
          Sets to the given value the checked state for all elements in this viewer.
 void setAllGrayed (boolean state)
          Sets to the given value the grayed state for all elements in this viewer.
 boolean setChecked ( Object element, boolean state)
          Sets the checked state for the given element in this viewer.
 void setCheckedElements ( Object[] elements)
          Sets which nodes are checked in this viewer.
 void setCheckStateProvider ( ICheckStateProvider checkStateProvider)
          Sets the ICheckStateProvider for this CheckboxTreeViewer.
 boolean setGrayed ( Object element, boolean state)
          Sets the grayed state for the given element in this viewer.
 void setGrayedElements ( Object[] elements)
          Sets which nodes are grayed in this viewer.
 
Methods inherited from class org.eclipse.jface.viewers. TableViewer
createViewerEditor, doClear, doClearAll, doDeselectAll, doFindItem, doGetColumn, doGetColumnCount, doGetItem, doGetItemCount, doGetItems, doGetSelection, doGetSelectionIndices, doIndexOf, doRemove, doRemove, doRemoveAll, doResetItem, doSelect, doSetItemCount, doSetSelection, doSetSelection, doShowItem, doShowSelection, getControl, getItemAt, getTable, getViewerRowFromItem, internalCreateNewRowPart, refresh, refresh, remove, setSelection
 
Methods inherited from class org.eclipse.jface.viewers. AbstractTableViewer
add, add, assertContentProviderType, clear, doFindInputItem, 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, hasFilters, internalUpdate, mapElement, needsRefilter, 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

CheckboxTableViewer

public CheckboxTableViewer(
Composite parent)
Deprecated. use newCheckList(Composite, int) or new CheckboxTableViewer(Table) instead (see below for details)

Creates a table viewer on a newly-created table control under the given parent. The table control is created using the SWT style bits: SWT.CHECK and SWT.BORDER. The table has one column. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.

This is equivalent to calling new CheckboxTableViewer(parent, SWT.BORDER). See that constructor for more details.

Parameters:
parent - the parent control

CheckboxTableViewer

public CheckboxTableViewer(
Composite parent,
                           int style)
Deprecated. use newCheckList(Composite, int) or new CheckboxTableViewer(Table) instead (see above for details)

Creates a table viewer on a newly-created table control under the given parent. The table control is created using the given SWT style bits, plus the SWT.CHECK style bit. The table has one column. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.

This also adds a TableColumn for the single column, and sets a TableLayout on the table which sizes the column to fill the table for its initial sizing, but does nothing on subsequent resizes.

If the caller just needs to show a single column with no header, it is preferable to use the newCheckList factory method instead, since SWT properly handles the initial sizing and subsequent resizes in this case.

If the caller adds its own columns, uses Table.setHeadersVisible(true), or needs to handle dynamic resizing of the table, it is recommended to create the Table itself, specifying the SWT.CHECK style bit (along with any other style bits needed), and use new CheckboxTableViewer(Table) rather than this constructor.

Parameters:
parent - the parent control
style - SWT style bits

CheckboxTableViewer

public CheckboxTableViewer(
Table table)
Creates a table viewer on the given table control. The SWT.CHECK style bit must be set 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

newCheckList

public static 
CheckboxTableViewer newCheckList(
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 SWT style bits, plus the SWT.CHECK style bit. The table shows its contents in a single column, with no header. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.

No TableColumn is added. SWT does not require a TableColumn if showing only a single column with no header. SWT correctly handles the initial sizing and subsequent resizes in this case.

Parameters:
parent - the parent control
style - SWT style bits
Returns:
CheckboxTableViewer
Since:
2.0

addCheckStateListener

public void addCheckStateListener(
ICheckStateListener listener)
Description copied from interface: ICheckable
Adds a listener for changes to the checked state of elements in this viewer. Has no effect if an identical listener is already registered.

Specified by:
addCheckStateListener in interface ICheckable
Parameters:
listener - a check state listener

setCheckStateProvider

public void setCheckStateProvider(
ICheckStateProvider checkStateProvider)
Sets the ICheckStateProvider for this CheckboxTreeViewer. The check state provider will supply the logic for deciding whether the check box associated with each item should be checked, grayed or unchecked.

Parameters:
checkStateProvider - The provider.
Since:
3.5

doUpdateItem

protected void doUpdateItem(
Widget widget,
                            
Object element,
                            boolean fullMap)
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 of fullMap. If fullMap is true then the current mapping from element to widgets is removed and the new mapping is added. If full map is false 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.

Overrides:
doUpdateItem in class AbstractTableViewer
element - element
fullMap - true if mappings are added and removed, and false if only the new map gets installed

createTable

protected static 
Table createTable(
Composite parent,
                                   int style)
Creates a new table control with one column.

Parameters:
parent - the parent control
style - style bits
Returns:
a new table control

getChecked

public boolean getChecked(
Object element)
Description copied from interface: ICheckable
Returns the checked state of the given element.

Specified by:
getChecked in interface ICheckable
Parameters:
element - the element
Returns:
true if the element is checked, and false if not checked

getCheckedElements

public 
Object[] getCheckedElements()
Returns a list of elements corresponding to checked table items in this viewer.

This method is typically used when preserving the interesting state of a viewer; setCheckedElements is used during the restore.

Returns:
the array of checked elements
See Also:
setCheckedElements(java.lang.Object[])

getGrayed

public boolean getGrayed(
Object element)
Returns the grayed state of the given element.

Parameters:
element - the element
Returns:
true if the element is grayed, and false if not grayed

getGrayedElements

public 
Object[] getGrayedElements()
Returns a list of elements corresponding to grayed nodes in this viewer.

This method is typically used when preserving the interesting state of a viewer; setGrayedElements is used during the restore.

Returns:
the array of grayed elements
See Also:
setGrayedElements(java.lang.Object[])

handleSelect

public void handleSelect(
SelectionEvent event)
Description copied from class: StructuredViewer
Handles a select event from the widget.

This method is internal to the framework; subclassers should not call this method.

Overrides:
handleSelect in class StructuredViewer
Parameters:
event - the SWT selection event

preservingSelection

protected void preservingSelection(
Runnable updateCode)
Description copied from class: StructuredViewer
Attempts to preserves the current selection across a run of the given code. This method should not preserve the selection if {link #getPreserveSelection()} returns false.

The default implementation of this method:

  • discovers the old selection (via getSelection)
  • runs the given runnable
  • attempts to restore the old selection (using setSelectionToWidget
  • rediscovers the resulting selection (via getSelection)
  • calls handleInvalidSelection if the resulting selection is different from the old selection

Overrides:
preservingSelection in class StructuredViewer
Parameters:
updateCode - the code to run see #getPreserveSelection()

removeCheckStateListener

public void removeCheckStateListener(
ICheckStateListener listener)
Description copied from interface: ICheckable
Removes the given check state listener from this viewer. Has no effect if an identical listener is not registered.

Specified by:
removeCheckStateListener in interface ICheckable
Parameters:
listener - a check state listener

setAllChecked

public void setAllChecked(boolean state)
Sets to the given value the checked state for all elements in this viewer. Does not fire events to check state listeners.

Parameters:
state - true if the element should be checked, and false if it should be unchecked

setAllGrayed

public void setAllGrayed(boolean state)
Sets to the given value the grayed state for all elements in this viewer.

Parameters:
state - true if the element should be grayed, and false if it should be ungrayed

setChecked

public boolean setChecked(
Object element,
                          boolean state)
Description copied from interface: ICheckable
Sets the checked state for the given element in this viewer. Does not fire events to check state listeners.

Specified by:
setChecked in interface ICheckable
Parameters:
element - the element
state - true if the item should be checked, and false if it should be unchecked
Returns:
true if the checked state could be set, and false otherwise

setCheckedElements

public void setCheckedElements(
Object[] elements)
Sets which nodes are checked in this viewer. The given list contains the elements that are to be checked; all other nodes are to be unchecked. Does not fire events to check state listeners.

This method is typically used when restoring the interesting state of a viewer captured by an earlier call to getCheckedElements.

Parameters:
elements - the list of checked elements (element type: Object)
See Also:
getCheckedElements()

setGrayed

public boolean setGrayed(
Object element,
                         boolean state)
Sets the grayed state for the given element in this viewer.

Parameters:
element - the element
state - true if the item should be grayed, and false if it should be ungrayed
Returns:
true if the element is visible and the gray state could be set, and false otherwise

setGrayedElements

public void setGrayedElements(
Object[] elements)
Sets which nodes are grayed in this viewer. The given list contains the elements that are to be grayed; all other nodes are to be ungrayed.

This method is typically used when restoring the interesting state of a viewer captured by an earlier call to getGrayedElements.

Parameters:
elements - the array of grayed elements
See Also:
getGrayedElements()

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