Class ContentViewer
- All Implemented Interfaces:
IInputProvider
,IInputSelectionProvider
,ISelectionProvider
- Direct Known Subclasses:
ContentMergeViewer
,StructuredViewer
A viewer's model consists of elements, represented by objects. A viewer
defines and implements generic infrastructure for handling model input,
updates, and selections in terms of elements. Input is obtained by querying
an IContentProvider
which returns elements. The elements
themselves are not displayed directly. They are mapped to labels, containing
text and/or an image, using the viewer's ILabelProvider
.
Implementing a concrete content viewer typically involves the following steps:
- create SWT controls for viewer (in constructor) (optional)
- initialize SWT controls from input (inputChanged)
- define viewer-specific update methods
- support selections (
setSelection
,getSelection
)
-
Field Summary
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a content viewer with no input, no content provider, and a default label provider. -
Method Summary
Modifier and TypeMethodDescriptionReturns the content provider used by this viewer, ornull
if this view does not yet have a content provider.getInput()
TheContentViewer
implementation of thisIInputProvider
method returns the current input of this viewer, ornull
if none.Returns the label provider used by this viewer.protected void
handleDispose
(DisposeEvent event) Handles a dispose event on this viewer's control.protected void
Handles a label provider changed event.protected void
hookControl
(Control control) Adds event listener hooks to the given control.protected void
Notifies that the label provider has changed.void
setContentProvider
(IContentProvider contentProvider) Sets the content provider used by this viewer.void
TheContentViewer
implementation of thisViewer
method invokesinputChanged
on the content provider and then theinputChanged
hook method.void
setLabelProvider
(IBaseLabelProvider labelProvider) Sets the label provider for this viewer.Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getControl, getData, getSelection, handleHelpRequest, inputChanged, refresh, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection, setSelection
-
Constructor Details
-
ContentViewer
protected ContentViewer()Creates a content viewer with no input, no content provider, and a default label provider.
-
-
Method Details
-
getContentProvider
Returns the content provider used by this viewer, ornull
if this view does not yet have a content provider.The
ContentViewer
implementation of this method returns the content provider recorded is an internal state variable. Overriding this method is generally not required; however, if overriding in a subclass,super.getContentProvider
must be invoked.- Returns:
- the content provider, or
null
if none
-
getInput
TheContentViewer
implementation of thisIInputProvider
method returns the current input of this viewer, ornull
if none. The viewer's input provides the "model" for the viewer's content.- Specified by:
getInput
in interfaceIInputProvider
- Specified by:
getInput
in classViewer
- Returns:
- the input object
-
getLabelProvider
Returns the label provider used by this viewer.The
ContentViewer
implementation of this method returns the label provider recorded in an internal state variable; if none has been set (withsetLabelProvider
) a default label provider will be created, remembered, and returned. Overriding this method is generally not required; however, if overriding in a subclass,super.getLabelProvider
must be invoked.- Returns:
- a label provider
-
handleDispose
Handles a dispose event on this viewer's control.The
ContentViewer
implementation 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
.- Parameters:
event
- a dispose event
-
handleLabelProviderChanged
Handles a label provider changed event.The
ContentViewer
implementation of this method callslabelProviderChanged()
to cause a complete refresh of the viewer. Subclasses may reimplement or extend.- Parameters:
event
- the change event
-
hookControl
Adds event listener hooks to the given control.All subclasses must call this method when their control is first established.
The
ContentViewer
implementation of this method hooks dispose events for the given control. Subclasses may override if they need to add other control hooks; however,super.hookControl
must be invoked.- Parameters:
control
- the control
-
labelProviderChanged
protected void labelProviderChanged()Notifies that the label provider has changed.The
ContentViewer
implementation of this method callsrefresh()
. Subclasses may reimplement or extend. -
setContentProvider
Sets the content provider used by this viewer.The
ContentViewer
implementation 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.setContentProvider
must be invoked.- Parameters:
contentProvider
- the content provider- See Also:
-
setInput
TheContentViewer
implementation of thisViewer
method invokesinputChanged
on the content provider and then theinputChanged
hook method. This method fails if this viewer does not have a content provider. Subclassers are advised to overrideinputChanged
rather than this method, but may extend this method if required. -
setLabelProvider
Sets the label provider for this viewer.The
ContentViewer
implementation 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.setLabelProvider
must be invoked.- Parameters:
labelProvider
- the label provider, ornull
if none
-