Class CheckboxTreeViewer
- All Implemented Interfaces:
ICheckable,IInputProvider,IInputSelectionProvider,IPostSelectionProvider,ISelectionProvider
- Direct Known Subclasses:
ContainerCheckedTreeViewer
Tree
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 tree 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.AbstractTreeViewer
ALL_LEVELS, NO_EXPANDFields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY -
Constructor Summary
ConstructorsConstructorDescriptionCheckboxTreeViewer(Composite parent) Creates a tree viewer on a newly-created tree control under the given parent.CheckboxTreeViewer(Composite parent, int style) Creates a tree viewer on a newly-created tree control under the given parent.CheckboxTreeViewer(Tree tree) Creates a tree viewer on the given tree control. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCheckStateListener(ICheckStateListener listener) Adds a listener for changes to the checked state of elements in this viewer.protected voiddoUpdateItem(Item item, Object element) Copies the attributes of the given element into the given SWT item.protected voidNotifies any check state listeners that the check state of an element has changed.booleangetChecked(Object element) Returns the checked state of the given element.Object[]Returns a list of checked elements in this viewer's tree, including currently hidden ones that are marked as checked but are under a collapsed ancestor.booleanReturns the grayed state of the given element.Object[]Returns a list of grayed elements in this viewer's tree, including currently hidden ones that are marked as grayed but are under a collapsed ancestor.protected voidhandleDoubleSelect(SelectionEvent event) Handles a double-click select event from the widget.protected voidhandleSelect(SelectionEvent event) Handles a select event from the widget.protected voidpreservingSelection(Runnable updateCode) Attempts to preserves the current selection across a run of the given code.voidremoveCheckStateListener(ICheckStateListener listener) Removes the given check state listener from this viewer.voidsetAllChecked(boolean state) Deprecated.booleansetChecked(Object element, boolean state) Sets the checked state for the given element in this viewer.protected voidsetCheckedChildren(Item item, boolean state) Sets the checked state for the children of the given item.voidsetCheckedElements(Object[] elements) Sets which elements are checked in this viewer's tree.voidsetCheckStateProvider(ICheckStateProvider checkStateProvider) Sets theICheckStateProviderfor thisCheckboxTreeViewer.booleansetGrayChecked(Object element, boolean state) Check and gray the selection rather than calling both setGrayed and setChecked as an optimization.booleanSets the grayed state for the given element in this viewer.voidsetGrayedElements(Object... elements) Sets which elements are grayed in this viewer's tree.booleansetParentsGrayed(Object element, boolean state) Sets the grayed state for the given element and its parents in this viewer.booleansetSubtreeChecked(Object element, boolean state) Sets the checked state for the given element and its visible children in this viewer.Methods inherited from class org.eclipse.jface.viewers.TreeViewer
addTreeListener, assertContentProviderType, createViewerEditor, disassociate, doGetColumnCount, editElement, getChild, getChildren, getColumnViewerOwner, getControl, getExpanded, getItemAt, getItemCount, getItemCount, getItems, getLabelProvider, getParentElement, getParentItem, getRawChildren, getSelection, getTree, getViewerRowFromItem, handleTreeCollapse, handleTreeExpand, hookControl, internalAdd, internalInitializeTree, internalRefreshStruct, isExpandable, mapElement, newItem, remove, removeAll, replace, setChildCount, setContentProvider, setExpanded, setHasChildren, setSelection, setSelection, showItem, updatePlusMethods inherited from class org.eclipse.jface.viewers.AbstractTreeViewer
add, add, addSelectionListener, addTreeListener, associate, buildLabel, collapseAll, collapseToLevel, contains, createChildren, createTreeItem, doFindInputItem, doFindItem, doUpdateItem, expandAll, expandAll, expandToLevel, expandToLevel, expandToLevel, expandToLevel, fireTreeCollapsed, fireTreeExpanded, getAutoExpandLevel, getAutoExpandOnSingleChildLevels, getChildren, getExpandedElements, getExpandedState, getExpandedTreePaths, getNextItem, getPreviousItem, getSelection, getSelectionFromWidget, getSortedChildren, getStructuredSelection, getTreePathFromItem, getVisibleExpandedElements, indexForElement, inputChanged, insert, internalCollapseToLevel, internalExpand, internalExpandToLevel, internalFindItems, internalGetWidgetToSelect, internalIsInputOrEmptyPath, internalRefresh, internalRefresh, internalRefresh, internalRemove, internalRemove, isSameSelection, labelProviderChanged, remove, remove, remove, removeTreeListener, reveal, scrollDown, scrollUp, setAutoExpandLevel, setAutoExpandOnSingleChildLevels, setExpandedElements, setExpandedState, setExpandedStateWithAutoExpandOnSingleChild, setExpandedTreePaths, setExpandPreCheckFilters, setSelectionToWidget, setSelectionToWidget, updateChildrenMethods inherited from class org.eclipse.jface.viewers.ColumnViewer
applyEditorValue, cancelEditing, checkBusy, firePostSelectionChanged, getCell, getCellEditors, getCellModifier, getColumnProperties, getColumnViewerEditor, getItem, getLabelProvider, getViewerRow, handleDispose, 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, equals, filter, findItem, findItems, fireDoubleClick, fireOpen, getColorAndFontCollector, getComparator, getComparer, getFilteredChildren, getFilters, getRoot, getSorter, handleInvalidSelection, handleLabelProviderChanged, handleOpen, handlePostSelect, hasFilters, internalUpdate, needsRefilter, refresh, refresh, refreshItem, removeDoubleClickListener, removeFilter, removeOpenListener, removePostSelectionChangedListener, resetFilters, setComparator, setComparer, setFilters, setInput, setSorter, setUseHashlookup, testFindItem, testFindItems, unmapElement, unmapElement, update, updateItem, usingElementMapMethods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInputMethods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, 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
-
CheckboxTreeViewer
Creates a tree viewer on a newly-created tree control under the given parent. The tree control is created using the SWT style bits:CHECKandBORDER. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.- Parameters:
parent- the parent control
-
CheckboxTreeViewer
Creates a tree viewer on a newly-created tree control under the given parent. The tree control is created using the given SWT style bits, plus theCHECKstyle bit. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.- Parameters:
parent- the parent controlstyle- the SWT style bits
-
CheckboxTreeViewer
Creates a tree viewer on the given tree control. TheSWT.CHECKstyle bit must be set on the given tree control. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.- Parameters:
tree- the tree control
-
-
Method Details
-
addCheckStateListener
Description copied from interface:ICheckableAdds 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:
addCheckStateListenerin interfaceICheckable- Parameters:
listener- a check state listener
-
setCheckStateProvider
Sets theICheckStateProviderfor thisCheckboxTreeViewer. 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
Description copied from class:AbstractTreeViewerCopies the attributes of the given element into the given SWT item.- Overrides:
doUpdateItemin classAbstractTreeViewer- Parameters:
item- the SWT itemelement- the element
-
fireCheckStateChanged
Notifies any check state listeners that the check state of an element has changed. Only listeners registered at the time this method is called are notified.- Parameters:
event- a check state changed event- See Also:
-
getChecked
Description copied from interface:ICheckableReturns the checked state of the given element.- Specified by:
getCheckedin interfaceICheckable- Parameters:
element- the element- Returns:
trueif the element is checked, andfalseif not checked
-
getCheckedElements
Returns a list of checked elements in this viewer's tree, including currently hidden ones that are marked as checked but are under a collapsed ancestor.This method is typically used when preserving the interesting state of a viewer;
setCheckedElementsis used during the restore.- Returns:
- the array of checked elements
- See Also:
-
getGrayed
Returns the grayed state of the given element.- Parameters:
element- the element- Returns:
trueif the element is grayed, andfalseif not grayed
-
getGrayedElements
Returns a list of grayed elements in this viewer's tree, including currently hidden ones that are marked as grayed but are under a collapsed ancestor.This method is typically used when preserving the interesting state of a viewer;
setGrayedElementsis used during the restore.- Returns:
- the array of grayed elements
- See Also:
-
handleDoubleSelect
Description copied from class:StructuredViewerHandles a double-click select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Overrides:
handleDoubleSelectin classAbstractTreeViewer- Parameters:
event- the SWT selection event
-
handleSelect
Description copied from class:StructuredViewerHandles a select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Overrides:
handleSelectin classStructuredViewer- Parameters:
event- the SWT selection event
-
preservingSelection
Description copied from class:StructuredViewerAttempts 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
handleInvalidSelectionif the resulting selection is different from the old selection
- Overrides:
preservingSelectionin classStructuredViewer- Parameters:
updateCode- the code to run see #getPreserveSelection()
- discovers the old selection (via
-
removeCheckStateListener
Description copied from interface:ICheckableRemoves the given check state listener from this viewer. Has no effect if an identical listener is not registered.- Specified by:
removeCheckStateListenerin interfaceICheckable- Parameters:
listener- a check state listener
-
setChecked
Description copied from interface:ICheckableSets the checked state for the given element in this viewer. Does not fire events to check state listeners.- Specified by:
setCheckedin interfaceICheckable- Parameters:
element- the elementstate-trueif the item should be checked, andfalseif it should be unchecked- Returns:
trueif the checked state could be set, andfalseotherwise
-
setCheckedChildren
Sets the checked state for the children of the given item.- Parameters:
item- the itemstate-trueif the item should be checked, andfalseif it should be unchecked- Since:
- 3.11
-
setCheckedElements
Sets which elements are checked in this viewer's tree. The given list contains the elements that are to be checked; all other elements 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 array of checked elements- See Also:
-
setGrayed
Sets the grayed state for the given element in this viewer.- Parameters:
element- the elementstate-trueif the item should be grayed, andfalseif it should be ungrayed- Returns:
trueif the gray state could be set, andfalseotherwise
-
setGrayChecked
Check and gray the selection rather than calling both setGrayed and setChecked as an optimization. Does not fire events to check state listeners.- Parameters:
element- the item being checkedstate- a boolean indicating selection or deselection- Returns:
- boolean indicating success or failure.
-
setGrayedElements
Sets which elements are grayed in this viewer's tree. The given list contains the elements that are to be grayed; all other elements 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:
-
setParentsGrayed
Sets the grayed state for the given element and its parents in this viewer.- Parameters:
element- the elementstate-trueif the item should be grayed, andfalseif it should be ungrayed- Returns:
trueif the element is visible and the gray state could be set, andfalseotherwise- See Also:
-
setSubtreeChecked
Sets the checked state for the given element and its visible children in this viewer. Assumes that the element has been expanded before. To enforce that the item is expanded, callexpandToLevelfor the element. Does not fire events to check state listeners.- Parameters:
element- the elementstate-trueif the item should be checked, andfalseif it should be unchecked- Returns:
trueif the checked state could be set, andfalseotherwise
-
setAllChecked
Deprecated.as this method only checks or unchecks visible items is is recommended thatsetSubtreeChecked(Object, boolean)is used instead.Sets to the given value the checked state for all elements in this viewer. Does not fire events to check state listeners. Assumes that the element has been expanded before. To enforce that the item is expanded, callexpandToLevelfor the element.- Parameters:
state-trueif the element should be checked, andfalseif it should be unchecked- Since:
- 3.2
- See Also:
-
setSubtreeChecked(Object, boolean)is used instead.