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
ConstructorsModifierConstructorDescriptionprotectedCreates 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, ornullif this view does not yet have a content provider.getInput()TheContentViewerimplementation of thisIInputProvidermethod returns the current input of this viewer, ornullif none.Returns the label provider used by this viewer.protected voidhandleDispose(DisposeEvent event) Handles a dispose event on this viewer's control.protected voidHandles a label provider changed event.protected voidhookControl(Control control) Adds event listener hooks to the given control.protected voidNotifies that the label provider has changed.voidsetContentProvider(IContentProvider contentProvider) Sets the content provider used by this viewer.voidTheContentViewerimplementation of thisViewermethod invokesinputChangedon the content provider and then theinputChangedhook method.voidsetLabelProvider(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, ornullif this view does not yet have a content provider.The
ContentViewerimplementation 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.getContentProvidermust be invoked.- Returns:
- the content provider, or
nullif none
-
getInput
TheContentViewerimplementation of thisIInputProvidermethod returns the current input of this viewer, ornullif none. The viewer's input provides the "model" for the viewer's content.- Specified by:
getInputin interfaceIInputProvider- Specified by:
getInputin classViewer- Returns:
- the input object
-
getLabelProvider
Returns the label provider used by this viewer.The
ContentViewerimplementation 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.getLabelProvidermust be invoked.- Returns:
- a label provider
-
handleDispose
Handles 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.- Parameters:
event- a dispose event
-
handleLabelProviderChanged
Handles a label provider changed event.The
ContentViewerimplementation 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
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.- Parameters:
control- the control
-
labelProviderChanged
protected void labelProviderChanged()Notifies that the label provider has changed.The
ContentViewerimplementation of this method callsrefresh(). Subclasses may reimplement or extend. -
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.- Parameters:
contentProvider- the content provider- See Also:
-
setInput
TheContentViewerimplementation 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. -
setLabelProvider
Sets 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.- Parameters:
labelProvider- the label provider, ornullif none
-