Eclipse Platform
2.0

org.eclipse.jface.text.source
Class SourceViewer

java.lang.Object
  |
  +--org.eclipse.jface.viewers.Viewer
        |
        +--org.eclipse.jface.text.TextViewer
              |
              +--org.eclipse.jface.text.source.SourceViewer
All Implemented Interfaces:
IInputProvider, IInputSelectionProvider, ISelectionProvider, ISourceViewer, ITextOperationTarget, ITextOperationTargetExtension, ITextViewer, ITextViewerExtension, IWidgetTokenOwner

public class SourceViewer
extends TextViewer
implements ISourceViewer

SWT based implementation of ISourceViewer. The same rules apply as for TextViewer. A source viewer uses an IVerticalRuler as its annotation presentation area. The vertical ruler is a small strip shown left of the viewer's text widget.

Clients are supposed to instantiate a source viewer and subsequently to communicate with it exclusively using the ISourceViewer interface. Clients should not subclass this class as it is rather likely that subclasses will be broken by future releases.


Nested Class Summary
 
Nested classes inherited from class org.eclipse.jface.text.TextViewer
TextViewer.WidgetCommand
 
Field Summary
protected  IAnnotationHover fAnnotationHover
          The viewer's annotation hover
protected  IContentAssistant fContentAssistant
          The viewer's content assistant
protected  boolean fContentAssistantInstalled
          Flag indicating whether the viewer's content assistant is installed
protected  IContentFormatter fContentFormatter
          The viewer's content formatter
protected  IInformationPresenter fInformationPresenter
          The viewer's information presenter
protected  IPresentationReconciler fPresentationReconciler
          The viewer's presentation reconciler
protected  IReconciler fReconciler
          The viewer's model reconciler
protected static int GAP_SIZE
          The size of the gap between the vertical ruler and the text widget
 
Fields inherited from class org.eclipse.jface.text.TextViewer
fAutoIndentStrategies, fDefaultPrefixChars, fDoubleClickStrategies, fEventConsumer, fHoverControlCreator, fIgnoreAutoIndent, fIndentChars, fLastTopPixel, fReplaceTextPresentation, fTextHovers, fTextInputListeners, fTextListeners, fUndoManager, fViewportListeners, INTERNAL, KEY, MOUSE, MOUSE_END, RESIZE, SCROLLER, SHIFTING, TRACE_ERRORS
 
Fields inherited from class org.eclipse.jface.viewers.Viewer
WIDGET_DATA_KEY
 
Fields inherited from interface org.eclipse.jface.text.source.ISourceViewer
CONTENTASSIST_CONTEXT_INFORMATION, CONTENTASSIST_PROPOSALS, FORMAT, INFORMATION
 
Fields inherited from interface org.eclipse.jface.text.ITextOperationTarget
COPY, CUT, DELETE, PASTE, PREFIX, PRINT, REDO, SELECT_ALL, SHIFT_LEFT, SHIFT_RIGHT, STRIP_PREFIX, UNDO
 
Constructor Summary
SourceViewer(Composite parent, IVerticalRuler ruler, int styles)
          Constructs a new source viewer.
 
Method Summary
 void activatePlugins()
          Activates the installed plug-ins.
 boolean canDoOperation(int operation)
          Returns whether the operation specified by the given operation code can be performed.
 void configure(SourceViewerConfiguration configuration)
          Configures the source viewer using the given configuration.
protected  void createControl(Composite parent, int styles)
          Creates the viewer's SWT control.
 void doOperation(int operation)
          Performs the operation specified by the operation code on the target.
 void enableOperation(int operation, boolean enable)
          Enables/disabled the given text operation.
 IAnnotationModel getAnnotationModel()
          Returns this viewer's annotation model.
 Control getControl()
          Returns the control of this viewer.
 IRegion getRangeIndication()
          Returns the viewer's range indication.
protected  void handleDispose()
          Frees all resources allocated by this viewer.
 void removeRangeIndication()
          Removes the viewer's range indication.
 void setAnnotationHover(IAnnotationHover annotationHover)
          Sets the annotation hover of this source viewer.
 void setDocument(IDocument document)
          Sets the given document as the text viewer's model and updates the presentation accordingly.
 void setDocument(IDocument document, IAnnotationModel annotationModel)
          Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations.
 void setDocument(IDocument document, IAnnotationModel annotationModel, int visibleRegionOffset, int visibleRegionLength)
          Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations.
 void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength)
          Sets the given document as this viewer's model and makes the specified region visible in the presentation.
 void setRangeIndication(int start, int length, boolean moveCursor)
          Sets the viewers's range indication to the specified range.
 void setRangeIndicator(Annotation rangeIndicator)
          Sets the annotation used by this viewer as range indicator.
 void showAnnotations(boolean show)
          Controls the visibility of annotations and in the case of separate presentation areas of text and annotations, the visibility of the annotation's presentation area.
 
Methods inherited from class org.eclipse.jface.text.TextViewer
addTextInputListener, addTextListener, addViewportListener, appendVerifyKeyListener, areMultipleLinesSelected, canPerformFind, changeTextPresentation, createDocumentAdapter, createTextWidget, customizeDocumentCommand, deleteText, disableRedrawing, enabledRedrawing, findAndSelect, fireInputDocumentAboutToBeChanged, fireInputDocumentChanged, getAverageCharWidth, getBottomIndex, getBottomIndexEndOffset, getDocument, getFindReplaceTarget, getInput, getMark, getRewriteTarget, getSelectedRange, getSelection, getSelectionProvider, getTextHover, getTextHoveringController, getTextOperationTarget, getTextWidget, getTopIndex, getTopIndexStartOffset, getTopInset, getVisibleDocument, getVisibleLinesInViewport, getVisibleRegion, getVisibleRegionOffset, getWidthInPixels, getWidthInPixels, handleVerifyEvent, inputChanged, internalGetVisibleRegion, internalRevealRange, invalidateTextPresentation, isBlockSelected, isEditable, isPrintable, markChanged, overlapsWithVisibleRegion, prependVerifyKeyListener, print, redraws, refresh, releaseWidgetToken, removeTextInputListener, removeTextListener, removeVerifyKeyListener, removeViewportListener, requestWidgetToken, resetPlugins, resetVisibleRegion, revealRange, selectContentTypePlugin, selectionChanged, setAutoIndentStrategy, setDefaultPrefixes, setEditable, setEventConsumer, setHoverControlCreator, setIndentPrefixes, setInput, setMark, setRedraw, setSelectedRange, setSelection, setTextColor, setTextColor, setTextDoubleClickStrategy, setTextHover, setTopIndex, setUndoManager, setVisibleRegion, shift, shift, startSequentialRewriteMode, stopSequentialRewriteMode, updateTextListeners, updateViewportListeners, validateSelectionRange
 
Methods inherited from class org.eclipse.jface.viewers.Viewer
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.jface.text.ITextViewer
addTextInputListener, addTextListener, addViewportListener, changeTextPresentation, getBottomIndex, getBottomIndexEndOffset, getDocument, getFindReplaceTarget, getSelectedRange, getSelectionProvider, getTextOperationTarget, getTextWidget, getTopIndex, getTopIndexStartOffset, getTopInset, getVisibleRegion, invalidateTextPresentation, isEditable, overlapsWithVisibleRegion, removeTextInputListener, removeTextListener, removeViewportListener, resetPlugins, resetVisibleRegion, revealRange, setAutoIndentStrategy, setDefaultPrefixes, setEditable, setEventConsumer, setIndentPrefixes, setSelectedRange, setTextColor, setTextColor, setTextDoubleClickStrategy, setTextHover, setTopIndex, setUndoManager, setVisibleRegion
 

Field Detail

fContentAssistant

protected IContentAssistant fContentAssistant
The viewer's content assistant


fContentAssistantInstalled

protected boolean fContentAssistantInstalled
Flag indicating whether the viewer's content assistant is installed

Since:
2.0

fContentFormatter

protected IContentFormatter fContentFormatter
The viewer's content formatter


fReconciler

protected IReconciler fReconciler
The viewer's model reconciler


fPresentationReconciler

protected IPresentationReconciler fPresentationReconciler
The viewer's presentation reconciler


fAnnotationHover

protected IAnnotationHover fAnnotationHover
The viewer's annotation hover


fInformationPresenter

protected IInformationPresenter fInformationPresenter
The viewer's information presenter

Since:
2.0

GAP_SIZE

protected static final int GAP_SIZE
The size of the gap between the vertical ruler and the text widget

See Also:
Constant Field Values
Constructor Detail

SourceViewer

public SourceViewer(Composite parent,
                    IVerticalRuler ruler,
                    int styles)
Constructs a new source viewer. The vertical ruler is initially visible. The viewer has not yet been initialized with a source viewer configuration.

Parameters:
parent - the parent of the viewer's control
ruler - the vertical ruler used by this source viewer
styles - the SWT style bits
Method Detail

createControl

protected void createControl(Composite parent,
                             int styles)
Description copied from class: TextViewer
Creates the viewer's SWT control. The viewer's text widget either is the control or is a child of the control.

Overrides:
createControl in class TextViewer
Parameters:
parent - the parent of the viewer's control
styles - the SWT style bits for the viewer's control

getControl

public Control getControl()
Description copied from interface: ITextViewerExtension
Returns the control of this viewer.

Specified by:
getControl in interface ITextViewerExtension
Overrides:
getControl in class TextViewer
Returns:
the control of this viewer

setAnnotationHover

public void setAnnotationHover(IAnnotationHover annotationHover)
Description copied from interface: ISourceViewer
Sets the annotation hover of this source viewer. The annotation hover provides the information to be displayed in a hover popup window if requested over the annotation presentation area. The annotation hover is assumed to be line oriented.

Specified by:
setAnnotationHover in interface ISourceViewer
Parameters:
annotationHover - the hover to be used, null is a valid argument

configure

public void configure(SourceViewerConfiguration configuration)
Description copied from interface: ISourceViewer
Configures the source viewer using the given configuration.

Specified by:
configure in interface ISourceViewer
Parameters:
configuration - the source viewer configuration to be used

activatePlugins

public void activatePlugins()
Description copied from interface: ITextViewer
Activates the installed plug-ins. If the plug-ins are already activated this call has no effect.

Specified by:
activatePlugins in interface ITextViewer
Overrides:
activatePlugins in class TextViewer

setDocument

public void setDocument(IDocument document)
Description copied from interface: ITextViewer
Sets the given document as the text viewer's model and updates the presentation accordingly. An approriate TextEvent is issued. This text event does not carry a related document event.

Specified by:
setDocument in interface ITextViewer
Overrides:
setDocument in class TextViewer
Parameters:
document - the viewer's new input document

setDocument

public void setDocument(IDocument document,
                        int visibleRegionOffset,
                        int visibleRegionLength)
Description copied from interface: ITextViewer
Sets the given document as this viewer's model and makes the specified region visible in the presentation. An approriate TextEvent is issued. The text event does not carry a related document event. This method is a convenience method for setDocument(document);setVisibleRegion(offset, length).

Specified by:
setDocument in interface ITextViewer
Overrides:
setDocument in class TextViewer
Parameters:
document - the new input document
visibleRegionOffset - the offset of the visible region
visibleRegionLength - the length of the visible region

setDocument

public void setDocument(IDocument document,
                        IAnnotationModel annotationModel)
Description copied from interface: ISourceViewer
Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations. The presentation is accordingly updated. An approriate TextEvent is issued. This text event does not carry a related document event.

Specified by:
setDocument in interface ISourceViewer
Parameters:
document - the viewer's new input document
annotationModel - the model for the viewer's visual annotations
See Also:
ITextViewer.setDocument(IDocument)

setDocument

public void setDocument(IDocument document,
                        IAnnotationModel annotationModel,
                        int visibleRegionOffset,
                        int visibleRegionLength)
Description copied from interface: ISourceViewer
Sets the given document as this viewer's text model and the given annotation model as the model for this viewer's visual annotations. The presentation is accordingly updated whereby only the specified region is made visible. An approriate TextEvent is issued. The text event does not carry a related document event. This method is a convenience method for setDocument(document, annotationModel);setVisibleRegion(offset, length).

Specified by:
setDocument in interface ISourceViewer
Parameters:
document - the new input document
annotationModel - the model of the viewer's visual annotations
visibleRegionOffset - the offset of the visible region
visibleRegionLength - the length of the visible region
See Also:
ITextViewer.setDocument(IDocument, int, int)

getAnnotationModel

public IAnnotationModel getAnnotationModel()
Description copied from interface: ISourceViewer
Returns this viewer's annotation model.

Specified by:
getAnnotationModel in interface ISourceViewer
Returns:
this viewer's annotation model

handleDispose

protected void handleDispose()
Description copied from class: TextViewer
Frees all resources allocated by this viewer. Internally called when the viewer's control has been disposed.

Overrides:
handleDispose in class TextViewer

canDoOperation

public boolean canDoOperation(int operation)
Description copied from interface: ITextOperationTarget
Returns whether the operation specified by the given operation code can be performed.

Specified by:
canDoOperation in interface ITextOperationTarget
Overrides:
canDoOperation in class TextViewer
Parameters:
operation - the operation code
Returns:
true if the specified operation can be performed

doOperation

public void doOperation(int operation)
Description copied from interface: ITextOperationTarget
Performs the operation specified by the operation code on the target. doOperation must only be called if canDoOperation returns true.

Specified by:
doOperation in interface ITextOperationTarget
Overrides:
doOperation in class TextViewer
Parameters:
operation - the operation code

enableOperation

public void enableOperation(int operation,
                            boolean enable)
Description copied from interface: ITextOperationTargetExtension
Enables/disabled the given text operation.

Specified by:
enableOperation in interface ITextOperationTargetExtension
Overrides:
enableOperation in class TextViewer
Parameters:
operation - the operation to enable/disable
enable - true to enable the operation otherwise false

setRangeIndicator

public void setRangeIndicator(Annotation rangeIndicator)
Description copied from interface: ISourceViewer
Sets the annotation used by this viewer as range indicator. The range covered by this annotation is referred to as range indication.

Specified by:
setRangeIndicator in interface ISourceViewer
Parameters:
rangeIndicator - the annotation to be used as this viewer's range indicator

setRangeIndication

public void setRangeIndication(int start,
                               int length,
                               boolean moveCursor)
Description copied from interface: ISourceViewer
Sets the viewers's range indication to the specified range. Its is indicated whether the cursor should also be moved to the beginning of the specified range.

Specified by:
setRangeIndication in interface ISourceViewer
Parameters:
start - the offset of the range
length - the length of the range
moveCursor - indicates whether the cursor should be moved to the given offset

getRangeIndication

public IRegion getRangeIndication()
Description copied from interface: ISourceViewer
Returns the viewer's range indication.

Specified by:
getRangeIndication in interface ISourceViewer
Returns:
the viewer's range indication.

removeRangeIndication

public void removeRangeIndication()
Description copied from interface: ISourceViewer
Removes the viewer's range indication. There is no visible range indication after this method completed.

Specified by:
removeRangeIndication in interface ISourceViewer
Returns:
the viewer's range indication

showAnnotations

public void showAnnotations(boolean show)
Description copied from interface: ISourceViewer
Controls the visibility of annotations and in the case of separate presentation areas of text and annotations, the visibility of the annotation's presentation area.

By default, annotations and their presentation area are visible.

Specified by:
showAnnotations in interface ISourceViewer
Parameters:
show - indicates the visibility of annotations

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.