Class StructuredViewer
- All Implemented Interfaces:
IInputProvider,IInputSelectionProvider,IPostSelectionProvider,ISelectionProvider
- Direct Known Subclasses:
AbstractListViewer,ColumnViewer
Any number of viewer filters can be added to this viewer (using
addFilter). When the viewer receives an update, it asks each
of its filters if it is out of date, and refilters elements as required.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThe ColorAndFontCollector collects fonts and colors without a a color or font provider.protected classThe ColorAndFontCollector is a helper class for viewers that have color and font support ad optionally decorators. -
Field Summary
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDoubleClickListener(IDoubleClickListener listener) Adds a listener for double-clicks in this viewer.voidaddDragSupport(int operations, Transfer[] transferTypes, DragSourceListener listener) Adds support for dragging items out of this viewer via a user drag-and-drop operation.voidaddDropSupport(int operations, Transfer[] transferTypes, DropTargetListener listener) Adds support for dropping items into this viewer via a user drag-and-drop operation.voidaddFilter(ViewerFilter filter) Adds the given filter to this viewer, and triggers refiltering and resorting of the elements.voidaddOpenListener(IOpenListener listener) Adds a listener for selection-open in this viewer.voidAdds a listener for post selection changes in this selection provider.protected voidassertContentProviderType(IContentProvider provider) Assert that the content provider is of one of the supported types.protected voidassertElementsNotNull(Object... elements) Asserts that the given array of elements is itself non-nulland contains nonullelements.protected voidAssociates the given element with the given widget.protected voidbuildLabel(ViewerLabel updateLabel, Object element) Build a label up for the element using the supplied label provider.protected voiddisassociate(Item item) Disassociates the given SWT item from its corresponding element.protected abstract WidgetdoFindInputItem(Object element) Returns the widget in this viewer's control which represents the given element if it is the viewer's input.protected abstract WidgetdoFindItem(Object element) Returns the widget in this viewer's control which represent the given element.protected abstract voiddoUpdateItem(Widget item, Object element, boolean fullMap) Copies the attributes of the given element into the given SWT item.protected booleanCompares two elements for equality.protected Object[]Returns the result of running the given elements through the filters.protected final WidgetFinds the widget which represents the given element.protected final Widget[]Finds the widgets which represent the given element.protected voidfireDoubleClick(DoubleClickEvent event) Notifies any double-click listeners that a double-click has been received.protected voidNotifies any open event listeners that a open event has been received.protected voidNotifies any post selection listeners that a post selection event has been received.protected StructuredViewer.ColorAndFontCollectorGet the ColorAndFontCollector for the receiver.Return this viewer's comparator used to sort elements.Returns the comparer to use for comparing elements, ornullif none has been set.protected Object[]getFilteredChildren(Object parent) Returns the filtered array of children of the given element.Returns this viewer's filters.protected ItemgetItem(int x, int y) Deprecated.protected Object[]getRawChildren(Object parent) Returns the children of the given parent without sorting and filtering them.protected ObjectgetRoot()Returns the root element.TheStructuredViewerimplementation of this method returns the result as anIStructuredSelection.protected abstract ListRetrieves the selection, as aList, from the underlying widget.protected Object[]getSortedChildren(Object parent) Returns the sorted and filtered set of children of the given element.Returns this viewer's sorter, ornullif it does not have one.Returns theIStructuredSelectionof this viewer.protected voidhandleDispose(DisposeEvent event) Handles a dispose event on this viewer's control.protected voidhandleDoubleSelect(SelectionEvent event) Handles a double-click select event from the widget.protected voidhandleInvalidSelection(ISelection invalidSelection, ISelection newSelection) Handles an invalid selection.protected voidTheStructuredViewerimplementation of thisContentViewermethod callsupdateif the event specifies that the label of a given element has changed, otherwise it calls super.protected voidhandleOpen(SelectionEvent event) Handles an open event from the OpenStrategy.protected voidHandles a post select event from the widget.protected voidhandleSelect(SelectionEvent event) Handles a select event from the widget.protected booleanReturns whether this viewer has any filters.protected voidhookControl(Control control) Adds event listener hooks to the given control.protected abstract 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.protected voidinternalUpdate(Widget widget, Object element, String[] properties) Updates the given element's presentation when one or more of its properties changes.protected voidmapElement(Object element, Widget item) Adds the element item pair to the element map.protected booleanneedsRefilter(Object element, String property) Determines whether a change to the given property of the given element would require refiltering and/or resorting.protected voidpreservingSelection(Runnable updateCode) Attempts to preserves the current selection across a run of the given code.voidrefresh()Refreshes this viewer completely with information freshly obtained from this viewer's model.voidrefresh(boolean updateLabels) Refreshes this viewer with information freshly obtained from this viewer's model.voidRefreshes this viewer starting with the given element.voidRefreshes this viewer starting with the given element.protected final voidrefreshItem(Widget widget, Object element) Refreshes the given item with the given element.voidRemoves the given double-click listener from this viewer.voidremoveFilter(ViewerFilter filter) Removes the given filter from this viewer, and triggers refiltering and resorting of the elements if required.voidremoveOpenListener(IOpenListener listener) Removes the given open listener from this viewer.voidRemoves the given listener for post selection changes from this selection provider.voidDiscards this viewer's filters and triggers refiltering and resorting of the elements.abstract voidEnsures that the given element is visible, scrolling the viewer if necessary.voidsetComparator(ViewerComparator comparator) Sets this viewer's comparator to be used for sorting elements, and triggers refiltering and resorting of this viewer's element.voidsetComparer(IElementComparer comparer) Sets the comparer to use for comparing elements, ornullto use the defaultequalsandhashCodemethods on the elements themselves.voidsetContentProvider(IContentProvider provider) Sets the content provider used by this viewer.voidsetFilters(ViewerFilter... filters) Sets the filters, replacing any previous filters, and triggers refiltering and resorting of the elements.final voidTheContentViewerimplementation of thisViewermethod invokesinputChangedon the content provider and then theinputChangedhook method.voidsetLabelProvider(IBaseLabelProvider labelProvider) Sets the label provider for this viewer.voidsetSelection(ISelection selection, boolean reveal) Sets a new selection for this viewer and optionally makes it visible.protected abstract voidsetSelectionToWidget(List l, boolean reveal) Parlays the given list of selected elements into selections on this viewer's control.protected voidsetSelectionToWidget(ISelection selection, boolean reveal) Converts the selection to aListand callssetSelectionToWidget(List, boolean).voidsetSorter(ViewerSorter sorter) Deprecated.usesetComparator()instead.voidsetUseHashlookup(boolean enable) Configures whether this structured viewer uses an internal hash table to speed up the mapping between elements and SWT items.testFindItem(Object element) Hook for testing.Widget[]testFindItems(Object element) Hook for testing.protected voidRemoves all elements from the map.protected voidunmapElement(Object element) Removes the given element from the internal element to widget map.protected voidunmapElement(Object element, Widget item) Removes the given association from the internal element to widget map.voidUpdates the given elements' presentation when one or more of their properties change.voidUpdates the given element's presentation when one or more of its properties changes.protected final voidupdateItem(Widget widget, Object element) Copies attributes of the given element into the given widget.protected voidupdateSelection(ISelection selection) Updates the selection of this viewer.protected booleanReturns whether this structured viewer is configured to use an internal map to speed up the mapping between elements and SWT items.Methods inherited from class org.eclipse.jface.viewers.ContentViewer
getContentProvider, getInput, getLabelProvider, labelProviderChangedMethods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getControl, getData, handleHelpRequest, inputChanged, 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
-
StructuredViewer
protected StructuredViewer()Creates a structured element viewer. The viewer has no input, no content provider, a default label provider, no sorter, and no filters.
-
-
Method Details
-
addDoubleClickListener
Adds a listener for double-clicks in this viewer. Has no effect if an identical listener is already registered.- Parameters:
listener- a double-click listener
-
addOpenListener
Adds a listener for selection-open in this viewer. Has no effect if an identical listener is already registered.- Parameters:
listener- an open listener
-
addPostSelectionChangedListener
Description copied from interface:IPostSelectionProviderAdds a listener for post selection changes in this selection provider. Has no effect if an identical listener is already registered.- Specified by:
addPostSelectionChangedListenerin interfaceIPostSelectionProvider- Parameters:
listener- a selection changed listener
-
addDragSupport
Adds support for dragging items out of this viewer via a user drag-and-drop operation.- Parameters:
operations- a bitwise OR of the supported drag and drop operation types (DROP_COPY,DROP_LINK, andDROP_MOVE)transferTypes- the transfer types that are supported by the drag operationlistener- the callback that will be invoked to set the drag data and to cleanup after the drag and drop operation finishes- See Also:
-
addDropSupport
Adds support for dropping items into this viewer via a user drag-and-drop operation.- Parameters:
operations- a bitwise OR of the supported drag and drop operation types (DROP_COPY,DROP_LINK, andDROP_MOVE)transferTypes- the transfer types that are supported by the drop operationlistener- the callback that will be invoked after the drag and drop operation finishes- See Also:
-
addFilter
Adds the given filter to this viewer, and triggers refiltering and resorting of the elements. If you want to add more than one filter consider usingsetFilters(ViewerFilter...).- Parameters:
filter- a viewer filter- See Also:
-
assertElementsNotNull
Asserts that the given array of elements is itself non-nulland contains nonullelements.- Parameters:
elements- the array to check
-
associate
Associates the given element with the given widget. Sets the given item's data to be the element, and maps the element to the item in the element map (if enabled).- Parameters:
element- the elementitem- the widget
-
disassociate
Disassociates the given SWT item from its corresponding element. Sets the item's data tonulland removes the element from the element map (if enabled).- Parameters:
item- the widget
-
doFindInputItem
Returns 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.
- Parameters:
element- the element to find the representing widget for- Returns:
- the corresponding widget, or
nullif none
-
doFindItem
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.
- Parameters:
element- the element to find the representing widget for- Returns:
- the corresponding widget, or
nullif none
-
doUpdateItem
Copies 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.
- Parameters:
item- widget item to updateelement- the element to representfullMap-trueif mappings are added and removed, andfalseif only the new map gets installed
-
equals
Compares two elements for equality. Uses the element comparer if one has been set, otherwise uses the defaultequalsmethod on the elements themselves.- Parameters:
elementA- the first elementelementB- the second element- Returns:
- whether elementA is equal to elementB
-
filter
Returns the result of running the given elements through the filters.- Parameters:
elements- the elements to filter- Returns:
- only the elements which all filters accept
-
findItem
Finds the widget which represents the given element.The default implementation of this method tries first to find the widget for the given element assuming that it is the viewer's input; this is done by calling
doFindInputItem. If it is not found there, it is looked up in the internal element map provided that this feature has been enabled. If the element map is disabled, the widget is found viadoFindInputItem.- Parameters:
element- the element- Returns:
- the corresponding widget, or
nullif none
-
findItems
Finds the widgets which represent the given element. The returned array must not be changed by clients; it might change upon calling other methods on this viewer.This method was introduced to support multiple equal elements in a viewer (see
AbstractTreeViewer). Multiple equal elements are only supported if the element map is enabled by callingsetUseHashlookup(boolean)and passingtrue.The default implementation of this method tries first to find the widget for the given element assuming that it is the viewer's input; this is done by calling
doFindInputItem. If it is not found there, the widgets are looked up in the internal element map provided that this feature has been enabled. If the element map is disabled, the widget is found viadoFindItem.- Parameters:
element- the element- Returns:
- the corresponding widgets
- Since:
- 3.2
-
fireDoubleClick
Notifies any double-click listeners that a double-click has been received. Only listeners registered at the time this method is called are notified.- Parameters:
event- a double-click event- See Also:
-
fireOpen
Notifies any open event listeners that a open event has been received. Only listeners registered at the time this method is called are notified.- Parameters:
event- a double-click event- See Also:
-
firePostSelectionChanged
Notifies any post selection listeners that a post selection event has been received. Only listeners registered at the time this method is called are notified.- Parameters:
event- a selection changed event- See Also:
-
getComparer
Returns the comparer to use for comparing elements, ornullif none has been set. If specified, the viewer uses this to compare and hash elements rather than the elements' own equals and hashCode methods.- Returns:
- the comparer to use for comparing elements or
null
-
getFilteredChildren
Returns the filtered array of children of the given element. The resulting array must not be modified, as it may come directly from the model's internal state.- Parameters:
parent- the parent element- Returns:
- a filtered array of child elements
-
getFilters
Returns this viewer's filters.- Returns:
- an array of viewer filters
- See Also:
-
getItem
Deprecated.This method is deprecated in 3.3 in favor ofColumnViewer.getItemAt(org.eclipse.swt.graphics.Point). Viewers who are not subclasses ofColumnViewershould consider using a widget relative implementation likeColumnViewer.getItemAt(org.eclipse.swt.graphics.Point).Returns the item at the given display-relative coordinates, ornullif there is no item at that location or the underlying SWT-Control is not made up ofItem(e.gListViewer)The default implementation of this method returns
null.- Parameters:
x- horizontal coordinatey- vertical coordinate- Returns:
- the item, or
nullif there is no item at the given coordinates
-
getRawChildren
Returns 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.- Parameters:
parent- the parent element- Returns:
- the child elements
-
getRoot
Returns the root element.The default implementation of this framework method forwards to
getInput. Override if the root element is different from the viewer's input element.- Returns:
- the root element, or
nullif none
-
getSelection
TheStructuredViewerimplementation of this method returns the result as anIStructuredSelection.Call
Subclasses do not typically override this method, but implementgetStructuredSelection()instead to get an instance ofIStructuredSelectiondirectly.getSelectionFromWidget(List)instead. If they override this method, they should return anIStructuredSelectionas well.- Specified by:
getSelectionin interfaceISelectionProvider- Specified by:
getSelectionin classViewer- Returns:
- ISelection
-
getStructuredSelection
Returns theIStructuredSelectionof this viewer.Subclasses whose
getSelection()specifies to return a more specific type should also override this method and return that type.- Returns:
- IStructuredSelection
- Throws:
ClassCastException- if the selection of the viewer is not an instance of IStructuredSelection- Since:
- 3.11
-
getSelectionFromWidget
Retrieves the selection, as aList, from the underlying widget.- Returns:
- the list of selected elements
-
getSortedChildren
Returns the sorted and filtered set of children of the given element. The resulting array must not be modified, as it may come directly from the model's internal state.- Parameters:
parent- the parent element- Returns:
- a sorted and filtered array of child elements
-
getSorter
Returns this viewer's sorter, ornullif it does not have one. If this viewer has a comparator that was set viasetComparator(ViewerComparator)then this method will returnnullif the comparator is not an instance of ViewerSorter.It is recommended to use
getComparator()instead.- Returns:
- a viewer sorter, or
nullif none or if the comparator is not an instance of ViewerSorter
-
getComparator
Return this viewer's comparator used to sort elements. This method should be used instead ofgetSorter().- Returns:
- a viewer comparator, or
nullif none - Since:
- 3.2
-
handleDoubleSelect
Handles a double-click select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Parameters:
event- the SWT selection event
-
handleOpen
Handles an open event from the OpenStrategy.This method is internal to the framework; subclassers should not call this method.
- Parameters:
event- the SWT selection event
-
handleInvalidSelection
Handles an invalid selection.This framework method is called if a model change picked up by a viewer results in an invalid selection. For instance if an element contained in the selection has been removed from the viewer, the viewer is free to either remove the element from the selection or to pick another element as its new selection. The default implementation of this method calls
updateSelection. Subclasses may override it to implement a different strategy for picking a new selection when the old selection becomes invalid.- Parameters:
invalidSelection- the selection before the viewer was updatednewSelection- the selection after the update, ornullif none
-
handleLabelProviderChanged
TheStructuredViewerimplementation of thisContentViewermethod callsupdateif the event specifies that the label of a given element has changed, otherwise it calls super. Subclasses may reimplement or extend.- Overrides:
handleLabelProviderChangedin classContentViewer- Parameters:
event- the event that generated this update
-
handleSelect
Handles a select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Parameters:
event- the SWT selection event
-
handlePostSelect
Handles a post select event from the widget.This method is internal to the framework; subclassers should not call this method.
- Parameters:
e- the SWT selection event
-
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 classContentViewer- Parameters:
control- the control
-
hasFilters
protected boolean hasFilters()Returns whether this viewer has any filters.- Returns:
- boolean
-
internalRefresh
Refreshes this viewer starting at the given element.- Parameters:
element- the element
-
internalRefresh
Refreshes 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).- Parameters:
element- the elementupdateLabels-trueto update labels for existing elements,falseto only update labels as needed, assuming that labels for existing elements are unchanged.- Since:
- 2.0
-
mapElement
Adds the element item pair to the element map.This method is internal to the framework; subclassers should not call this method.
- Parameters:
element- the elementitem- the corresponding widget
-
needsRefilter
Determines whether a change to the given property of the given element would require refiltering and/or resorting.This method is internal to the framework; subclassers should not call this method.
- Parameters:
element- the elementproperty- the property- Returns:
trueif refiltering is required, andfalseotherwise
-
preservingSelection
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
handleInvalidSelectionif the resulting selection is different from the old selection
- Parameters:
updateCode- the code to run see #getPreserveSelection()
- discovers the old selection (via
-
refresh
public void refresh()Description copied from class:ViewerRefreshes this viewer completely with information freshly obtained from this viewer's model. -
refresh
public void refresh(boolean updateLabels) 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.- Since:
- 2.0
-
refresh
Refreshes this viewer starting with the given element.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.- Parameters:
element- the element
-
refresh
Refreshes this viewer starting with the given element. Labels are updated as described inrefresh(boolean updateLabels).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.- Parameters:
element- the elementupdateLabels-trueto update labels for existing elements,falseto only update labels as needed, assuming that labels for existing elements are unchanged.- Since:
- 2.0
-
refreshItem
Refreshes the given item with the given element. CallsdoUpdateItem(..., false).This method is internal to the framework; subclassers should not call this method.
- Parameters:
widget- the widgetelement- the element
-
removeOpenListener
Removes the given open listener from this viewer. Has no effect if an identical listener is not registered.- Parameters:
listener- an open listener
-
removePostSelectionChangedListener
Description copied from interface:IPostSelectionProviderRemoves the given listener for post selection changes from this selection provider. Has no effect if an identical listener is not registered.- Specified by:
removePostSelectionChangedListenerin interfaceIPostSelectionProvider- Parameters:
listener- a selection changed listener
-
removeDoubleClickListener
Removes the given double-click listener from this viewer. Has no effect if an identical listener is not registered.- Parameters:
listener- a double-click listener
-
removeFilter
Removes the given filter from this viewer, and triggers refiltering and resorting of the elements if required. Has no effect if the identical filter is not registered. If you want to remove more than one filter consider usingsetFilters(ViewerFilter...).- Parameters:
filter- a viewer filter- See Also:
-
setFilters
Sets the filters, replacing any previous filters, and triggers refiltering and resorting of the elements.- Parameters:
filters- an varargs of viewer filters- Since:
- 3.3
-
resetFilters
public void resetFilters()Discards this viewer's filters and triggers refiltering and resorting of the elements. -
reveal
Ensures that the given element is visible, scrolling the viewer if necessary. The selection is unchanged.- Parameters:
element- the element to reveal
-
setContentProvider
Sets the content provider used by this viewer.The
ContentViewerimplementation of this method records the content provider in an internal state variable. Overriding this method is generally not required; however, if overriding in a subclass,super.setContentProvidermust be invoked.The
StructuredViewerimplementation of this method callsassertContentProviderType(IContentProvider)to validate the content provider. For aStructuredViewer, the content provider must implementIStructuredContentProvider.- Overrides:
setContentProviderin classContentViewer- Parameters:
provider- the content provider- See Also:
-
assertContentProviderType
Assert that the content provider is of one of the supported types.- Parameters:
provider- content provider to check
-
setInput
Description copied from class:ContentViewerTheContentViewerimplementation of thisViewermethod invokesinputChangedon the content provider and then theinputChangedhook method. This method fails if this viewer does not have a content provider. Subclassers are advised to overrideinputChangedrather than this method, but may extend this method if required.- Overrides:
setInputin classContentViewer- Parameters:
input- the input of this viewer, ornullif none
-
setSelection
Description copied from class:ViewerSets a new selection for this viewer and optionally makes it visible.Subclasses must implement this method.
- Specified by:
setSelectionin classViewer- Parameters:
selection- the new selectionreveal-trueif the selection is to be made visible, andfalseotherwise
-
setSelectionToWidget
Parlays 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.
- Parameters:
l- list of selected elements (element type:Object) ornullif the selection is to be clearedreveal-trueif the selection is to be made visible, andfalseotherwise
-
setSelectionToWidget
Converts the selection to aListand callssetSelectionToWidget(List, boolean). The selection is expected to be anIStructuredSelectionof elements. If not, the selection is cleared.Subclasses do not typically override this method, but implement
setSelectionToWidget(List, boolean)instead.- Parameters:
selection- an IStructuredSelection of elementsreveal-trueto reveal the first element in the selection, orfalseotherwise
-
setSorter
Deprecated.usesetComparator()instead.Sets this viewer's sorter and triggers refiltering and resorting of this viewer's element. Passingnullturns sorting off.- Parameters:
sorter- a viewer sorter, ornullif none
-
setComparator
Sets this viewer's comparator to be used for sorting elements, and triggers refiltering and resorting of this viewer's element.nullturns sorting off. To get the viewer's comparator, callgetComparator().IMPORTANT: This method was introduced in 3.2. If a reference to this viewer object is passed to clients who call
getSorter(), null may be returned from from that method even though the viewer is sorting its elements using the viewer's comparator.- Parameters:
comparator- a viewer comparator, ornullif none- Since:
- 3.2
-
setUseHashlookup
public void setUseHashlookup(boolean enable) Configures whether this structured viewer uses an internal hash table to speed up the mapping between elements and SWT items. This must be called before the viewer is given an input (viasetInput).Note: enabling hash lookup requires from client code that elements managed by the viewer properly implement
Object.hashCode()andObject.equals(Object)and that equal elements are not added to the same parent in the tree (each equal element should have a different parent chain).- Parameters:
enable-trueto enable hash lookup, andfalseto disable it
-
setComparer
Sets the comparer to use for comparing elements, ornullto use the defaultequalsandhashCodemethods on the elements themselves.- Parameters:
comparer- the comparer to use for comparing elements ornull
-
testFindItem
Hook for testing.- Parameters:
element- the element- Returns:
- the corresponding widget, or
nullif none
-
testFindItems
Hook for testing.- Parameters:
element- the element- Returns:
- the corresponding widgets
- Since:
- 3.2
-
unmapAllElements
protected void unmapAllElements()Removes all elements from the map.This method is internal to the framework; subclassers should not call this method.
-
unmapElement
Removes the given element from the internal element to widget map. Does nothing if mapping is disabled. If mapping is enabled, the given element must be present.This method is internal to the framework; subclassers should not call this method.
- Parameters:
element- the element
-
unmapElement
Removes the given association from the internal element to widget map. Does nothing if mapping is disabled, or if the given element does not map to the given item.This method is internal to the framework; subclassers should not call this method.
- Parameters:
element- the elementitem- the item to unmap- Since:
- 2.0
-
update
Updates the given elements' presentation when one or more of their properties change. Only the given elements are updated.This does not handle structural changes (e.g. addition or removal of elements), and does not update any other related elements (e.g. child elements). To handle structural changes, use the
refreshmethods instead.This should be called when an element has changed in the model, in order to have the viewer accurately reflect the model. This method only affects the viewer, not the model.
Specifying which properties are affected may allow the viewer to optimize the update. For example, if the label provider is not affected by changes to any of these properties, an update may not actually be required. Specifying
propertiesasnullforces a full update of the given elements.If the viewer has a sorter which is affected by a change to one of the properties, the elements' positions are updated to maintain the sort order. Note that resorting may not happen if
propertiesisnull.If the viewer has a filter which is affected by a change to one of the properties, elements may appear or disappear if the change affects whether or not they are filtered out. Note that resorting may not happen if
propertiesisnull.- Parameters:
elements- the elementsproperties- the properties that have changed, ornullto indicate unknown
-
update
Updates the given element's presentation when one or more of its properties changes. Only the given element is updated.This does not handle structural changes (e.g. addition or removal of elements), and does not update any other related elements (e.g. child elements). To handle structural changes, use the
refreshmethods instead.This should be called when an element has changed in the model, in order to have the viewer accurately reflect the model. This method only affects the viewer, not the model.
Specifying which properties are affected may allow the viewer to optimize the update. For example, if the label provider is not affected by changes to any of these properties, an update may not actually be required. Specifying
propertiesasnullforces a full update of the element.If the viewer has a sorter which is affected by a change to one of the properties, the element's position is updated to maintain the sort order. Note that resorting may not happen if
propertiesisnull.If the viewer has a filter which is affected by a change to one of the properties, the element may appear or disappear if the change affects whether or not the element is filtered out. Note that filtering may not happen if
propertiesisnull.- Parameters:
element- the elementproperties- the properties that have changed, ornullto indicate unknown
-
internalUpdate
Updates the given element's presentation when one or more of its properties changes. Only the given element is updated.EXPERIMENTAL. Not to be used except by JDT. This method was added to support JDT's explorations into grouping by working sets, which requires viewers to support multiple equal elements. See bug 76482 for more details. This support will likely be removed in Eclipse 3.3 in favor of proper support for multiple equal elements (which was implemented for AbtractTreeViewer in 3.2).
- Parameters:
widget- the widget for the elementelement- the elementproperties- the properties that have changed, ornullto indicate unknown
-
updateItem
Copies attributes of the given element into the given widget.This method is internal to the framework; subclassers should not call this method. Calls
doUpdateItem(widget, element, true).- Parameters:
widget- the widgetelement- the element
-
updateSelection
Updates the selection of this viewer.This framework method should be called when the selection in the viewer widget changes.
The default implementation of this method notifies all selection change listeners recorded in an internal state variable. Overriding this method is generally not required; however, if overriding in a subclass,
super.updateSelectionmust be invoked.- Parameters:
selection- the selection, ornullif none
-
usingElementMap
protected boolean usingElementMap()Returns whether this structured viewer is configured to use an internal map to speed up the mapping between elements and SWT items.The default implementation of this framework method checks whether the internal map has been initialized.
- Returns:
trueif the element map is enabled, andfalseif disabled
-
setLabelProvider
Description copied from class:ContentViewerSets the label provider for this viewer.The
ContentViewerimplementation of this method ensures that the given label provider is connected to this viewer and the former label provider is disconnected from this viewer. Overriding this method is generally not required; however, if overriding in a subclass,super.setLabelProvidermust be invoked.- Overrides:
setLabelProviderin classContentViewer- Parameters:
labelProvider- the label provider, ornullif none
-
buildLabel
Build a label up for the element using the supplied label provider.- Parameters:
updateLabel- The ViewerLabel to collect the result inelement- The element being decorated.
-
getColorAndFontCollector
Get the ColorAndFontCollector for the receiver.- Returns:
- ColorAndFontCollector
- Since:
- 3.1
-
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 classContentViewer- Parameters:
event- a dispose event
-
ColumnViewer.getItemAt(org.eclipse.swt.graphics.Point).