Class Viewer
- All Implemented Interfaces:
- IInputProvider,- IInputSelectionProvider,- ISelectionProvider
- Direct Known Subclasses:
- AbstractViewer,- ContentViewer,- TextViewer
 A viewer can be created as an adapter on a pre-existing control (e.g.,
 creating a ListViewer on an existing List control).
 All viewers also provide a convenience constructor for creating the control.
 
Implementing a concrete 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 SummaryFieldsModifier and TypeFieldDescriptionprotected static final StringUnique key for associating element data with widgets.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddHelpListener(HelpListener listener) Adds a listener for help requests in this viewer.voidAdds a listener for selection changes in this selection provider.protected voidfireHelpRequested(HelpEvent event) Notifies any help listeners that help has been requested.protected voidNotifies any selection changed listeners that the viewer's selection has changed.abstract ControlReturns the primary control associated with this viewer.Returns the value of the property with the given name, ornullif the property is not found.abstract ObjectgetInput()Returns the input.abstract ISelectionReturns the current selection for this provider.protected voidhandleHelpRequest(HelpEvent event) Handles a help request from the underlying SWT control.protected voidinputChanged(Object input, Object oldInput) Internal hook method called when the input to this viewer is initially set or subsequently changed.abstract voidrefresh()Refreshes this viewer completely with information freshly obtained from this viewer's model.voidremoveHelpListener(HelpListener listener) Removes the given help listener from this viewer.voidRemoves the given selection change listener from this selection provider.scrollDown(int x, int y) Scrolls the viewer's control down by one item from the given display-relative coordinates.scrollUp(int x, int y) Scrolls the viewer's control up by one item from the given display-relative coordinates.voidSets the value of the property with the given name to the given value, or tonullif the property is to be removed.abstract voidSets or clears the input for this viewer.voidsetSelection(ISelection selection) The viewer implementation of thisISelectionProvidermethod make the new selection for this viewer without making it visible.abstract voidsetSelection(ISelection selection, boolean reveal) Sets a new selection for this viewer and optionally makes it visible.
- 
Field Details- 
WIDGET_DATA_KEYUnique key for associating element data with widgets.- See Also:
 
 
- 
- 
Constructor Details- 
Viewerprotected Viewer()Creates a new viewer.
 
- 
- 
Method Details- 
addHelpListenerAdds a listener for help requests in this viewer. Has no effect if an identical listener is already registered.- Parameters:
- listener- a help listener
 
- 
addSelectionChangedListenerDescription copied from interface:ISelectionProviderAdds a listener for selection changes in this selection provider. Has no effect if an identical listener is already registered.- Specified by:
- addSelectionChangedListenerin interface- ISelectionProvider
- Parameters:
- listener- a selection changed listener
 
- 
fireHelpRequestedNotifies any help listeners that help has been requested. Only listeners registered at the time this method is called are notified.- Parameters:
- event- a help event
- See Also:
 
- 
fireSelectionChangedNotifies any selection changed listeners that the viewer's selection has changed. Only listeners registered at the time this method is called are notified.- Parameters:
- event- a selection changed event
- See Also:
 
- 
getControlReturns the primary control associated with this viewer.- Returns:
- the SWT control which displays this viewer's content
 
- 
getDataReturns the value of the property with the given name, ornullif the property is not found.The default implementation performs a (linear) search of an internal table. Overriding this method is generally not required if the number of different keys is small. If a more efficient representation of a viewer's properties is required, override both getDataandsetData.- Parameters:
- key- the property name
- Returns:
- the property value, or nullif the property is not found
 
- 
getInputDescription copied from interface:IInputProviderReturns the input.- Specified by:
- getInputin interface- IInputProvider
- Returns:
- the input object
 
- 
getSelectionDescription copied from interface:ISelectionProviderReturns the current selection for this provider.- Specified by:
- getSelectionin interface- ISelectionProvider
- Returns:
- the current selection
 
- 
handleHelpRequestHandles a help request from the underlying SWT control. The default behavior is to fire a help request, with the event's data modified to hold this viewer.- Parameters:
- event- the event
 
- 
inputChangedInternal hook method called when the input to this viewer is initially set or subsequently changed.The default implementation does nothing. Subclassers may override this method to do something when a viewer's input is set. A typical use is populate the viewer. - Parameters:
- input- the new input of this viewer, or- nullif none
- oldInput- the old input element or- nullif there was previously no input
 
- 
refreshpublic abstract void refresh()Refreshes this viewer completely with information freshly obtained from this viewer's model.
- 
removeHelpListenerRemoves the given help listener from this viewer. Has no effect if an identical listener is not registered.- Parameters:
- listener- a help listener
 
- 
removeSelectionChangedListenerDescription copied from interface:ISelectionProviderRemoves the given selection change listener from this selection provider. Has no effect if an identical listener is not registered.- Specified by:
- removeSelectionChangedListenerin interface- ISelectionProvider
- Parameters:
- listener- a selection changed listener
 
- 
scrollDownScrolls the viewer's control down by one item from the given display-relative coordinates. Returns the newly revealed Item, ornullif no scrolling occurred or if the viewer doesn't represent an item-based widget.- Parameters:
- x- horizontal coordinate
- y- vertical coordinate
- Returns:
- the item scrolled down to
 
- 
scrollUpScrolls the viewer's control up by one item from the given display-relative coordinates. Returns the newly revealed Item, ornullif no scrolling occurred or if the viewer doesn't represent an item-based widget.- Parameters:
- x- horizontal coordinate
- y- vertical coordinate
- Returns:
- the item scrolled up to
 
- 
setDataSets the value of the property with the given name to the given value, or tonullif the property is to be removed. If this viewer has such a property, its value is replaced; otherwise a new property is added.The default implementation records properties in an internal table which is searched linearly. Overriding this method is generally not required if the number of different keys is small. If a more efficient representation of a viewer's properties is required, override both getDataandsetData.- Parameters:
- key- the property name
- value- the property value, or- nullif the property is not found
 
- 
setInputSets or clears the input for this viewer.- Parameters:
- input- the input of this viewer, or- nullif none
 
- 
setSelectionThe viewer implementation of thisISelectionProvidermethod make the new selection for this viewer without making it visible.This method is equivalent to setSelection(selection,false).Note that some implementations may not be able to set the selection without also revealing it, for example (as of 3.3) TreeViewer. - Specified by:
- setSelectionin interface- ISelectionProvider
- Parameters:
- selection- the new selection
 
- 
setSelectionSets a new selection for this viewer and optionally makes it visible.Subclasses must implement this method. - Parameters:
- selection- the new selection
- reveal-- trueif the selection is to be made visible, and- falseotherwise
 
 
-