public class SourceViewer extends TextViewer implements ISourceViewer, ISourceViewerExtension, ISourceViewerExtension2, ISourceViewerExtension3, ISourceViewerExtension4
ISourceViewer
and its extension
interfaces. 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. A
source viewer uses an IOverviewRuler
as its presentation area
for the annotation overview. The overview ruler is a small strip shown right
of the viewer's text widget.
Clients are supposed to instantiate a source viewer and subsequently to
communicate with it exclusively using the ISourceViewer
and
its extension interfaces.
Clients may subclass this class but should expect some breakage by future releases.
Modifier and Type | Class and Description |
---|---|
protected class |
SourceViewer.RulerLayout
Layout of a source viewer.
|
TextViewer.TextHoverKey, TextViewer.WidgetCommand
ITextViewerExtension8.EnrichMode
Modifier and Type | Field and Description |
---|---|
protected static String |
_SELECTION_POSITION_CATEGORY
Partial name of the position category to manage remembered selections.
|
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 IAnnotationHover |
fOverviewRulerAnnotationHover
The viewer's overview ruler annotation hover
|
protected IPresentationReconciler |
fPresentationReconciler
The viewer's presentation reconciler
|
protected IQuickAssistAssistant |
fQuickAssistAssistant
This viewer's quick assist assistant.
|
protected boolean |
fQuickAssistAssistantInstalled
Flag indicating whether this viewer's quick assist assistant is installed.
|
protected IReconciler |
fReconciler
The viewer's model reconciler
|
protected String |
fSelectionCategory
Position category used by the selection updater
|
protected Stack |
fSelections
Stack of saved selections in the underlying document
|
protected IPositionUpdater |
fSelectionUpdater
Position updater for saved selections
|
protected static int |
GAP_SIZE
The size of the gap between the vertical ruler and the text widget
(value
2 ). |
protected static int |
GAP_SIZE_1
The size of the gap between the vertical ruler and the text widget
(value
1 ). |
protected static Object |
MODEL_ANNOTATION_MODEL
Key of the model annotation model inside the visual annotation model.
|
fAutoIndentStrategies, fDefaultPrefixChars, fDoubleClickStrategies, fEventConsumer, fFindReplaceDocumentAdapter, fHoverControlCreator, fHyperlinkDetectors, fHyperlinkManager, fHyperlinkPresenter, fHyperlinkStateMask, fIgnoreAutoIndent, fIndentChars, fInformationMapping, fLastTopPixel, fMarkPosition, fPaintManager, fPartitioning, fReplaceTextPresentation, fTextHovers, fTextInputListeners, fTextListeners, fTextPresentationListeners, fUndoManager, fViewportListeners, INTERNAL, KEY, MOUSE, MOUSE_END, RESIZE, SCROLLER, SHIFTING, TRACE_ERRORS
WIDGET_DATA_KEY
CONTENTASSIST_CONTEXT_INFORMATION, CONTENTASSIST_PROPOSALS, FORMAT, INFORMATION, QUICK_ASSIST
DEFAULT_HOVER_STATE_MASK
COPY, CUT, DELETE, PASTE, PREFIX, PRINT, REDO, SELECT_ALL, SHIFT_LEFT, SHIFT_RIGHT, STRIP_PREFIX, UNDO
Constructor and Description |
---|
SourceViewer(Composite parent,
IVerticalRuler ruler,
int styles)
Constructs a new source viewer.
|
SourceViewer(Composite parent,
IVerticalRuler verticalRuler,
IOverviewRuler overviewRuler,
boolean showAnnotationsOverview,
int styles)
Constructs a new source viewer.
|
Modifier and Type | Method and Description |
---|---|
void |
activatePlugins()
Activates the installed plug-ins.
|
void |
addVerticalRulerColumn(IVerticalRulerColumn column)
Adds the give column as last column to this viewer's vertical ruler.
|
boolean |
canDoOperation(int operation)
Returns whether the operation specified by the given operation code
can be performed.
|
protected void |
clearRememberedSelection() |
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.
|
protected IFormattingContext |
createFormattingContext()
Creates a new formatting context for a format operation.
|
protected IFormattingContext |
createFormattingContext(int selectionOffset,
int selectionLength)
Creates a new formatting context for a format operation.
|
protected Layout |
createLayout()
Creates the layout used for this viewer.
|
protected IAnnotationModel |
createVisualAnnotationModel(IAnnotationModel annotationModel)
Creates the visual annotation model on top of the given annotation model.
|
protected void |
disposeVisualAnnotationModel()
Disposes the visual annotation model.
|
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.
|
protected void |
ensureAnnotationHoverManagerInstalled()
After this method has been executed the caller knows that any installed annotation hover has been installed.
|
protected void |
ensureOverviewHoverManagerInstalled()
After this method has been executed the caller knows that any installed overview hover has been installed.
|
IAnnotationModel |
getAnnotationModel()
Returns this viewer's annotation model.
|
ContentAssistantFacade |
getContentAssistantFacade()
Returns a facade for this viewer's content assistant.
|
Control |
getControl()
Returns the primary control associated with this viewer.
|
IAnnotationHover |
getCurrentAnnotationHover()
Returns the currently displayed annotation hover if any,
null otherwise. |
IQuickAssistAssistant |
getQuickAssistAssistant()
Returns this viewers quick assist assistant.
|
IQuickAssistInvocationContext |
getQuickAssistInvocationContext()
Returns this viewer's quick assist invocation context.
|
IRegion |
getRangeIndication()
Returns the viewer's range indication.
|
protected IVerticalRuler |
getVerticalRuler()
Returns the vertical ruler of this viewer.
|
IAnnotationModel |
getVisualAnnotationModel()
Returns the visual annotation model of this viewer.
|
protected void |
handleDispose()
Frees all resources allocated by this viewer.
|
protected Point |
rememberSelection()
Remembers and returns the current selection.
|
void |
removeRangeIndication()
Removes the viewer's range indication.
|
void |
removeVerticalRulerColumn(IVerticalRulerColumn column)
Removes the give column from this viewer's vertical ruler.
|
protected void |
restoreSelection()
Restores a previously saved selection in the document.
|
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 modelRangeOffset,
int modelRangeLength)
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
exposes the specified region.
|
void |
setHoverEnrichMode(ITextViewerExtension8.EnrichMode mode)
Sets the hover enrich mode.
|
void |
setOverviewRulerAnnotationHover(IAnnotationHover annotationHover)
Sets the overview ruler's annotation hover of this source viewer.
|
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.
|
void |
showAnnotationsOverview(boolean show)
Shows/hides an overview representation of the annotations of the whole document of this viewer.
|
void |
unconfigure()
Rolls back the configuration process of this source viewer.
|
protected void |
updateSlaveDocuments(IDocument masterDocument)
Updates all slave documents of the given document.
|
_getVisibleRegionOffset, _internalGetVisibleRegion, addPainter, addPostSelectionChangedListener, addTextInputListener, addTextListener, addTextPresentationListener, addViewportListener, appendVerifyKeyListener, areMultipleLinesSelected, canPerformFind, changeTextPresentation, copyMarkedRegion, createDocumentAdapter, createSlaveDocument, createSlaveDocumentManager, createTextWidget, customizeDocumentCommand, deleteText, disableRedrawing, enabledRedrawing, enabledRedrawing, event2ModelRange, findAndSelect, findAndSelect, findAndSelectInRange, fireInputDocumentAboutToBeChanged, fireInputDocumentChanged, firePostSelectionChanged, fireSelectionChanged, freeSlaveDocument, getAverageCharWidth, getBottomIndex, getBottomIndexEndOffset, getClosestWidgetLineForModelLine, getCurrentTextHover, getDocument, getDocumentPartitioning, getEmptySelectionChangedEventDelay, getExtent, getFindReplaceDocumentAdapter, getFindReplaceTarget, getHoverEventLocation, getInput, getMark, getModelCoverage, getPaintManager, getRegisteredSupports, getRewriteTarget, getSelectedRange, getSelection, getSelectionProvider, getSlaveDocumentManager, getTextHover, getTextHover, getTextHoveringController, getTextOperationTarget, getTextWidget, getTopIndex, getTopIndexStartOffset, getTopInset, getUndoManager, getVisibleDocument, getVisibleLinesInViewport, getVisibleRegion, getWidthInPixels, getWidthInPixels, handleVerifyEvent, handleVisibleDocumentAboutToBeChanged, handleVisibleDocumentChanged, ignoreAutoEditStrategies, initializeDocumentInformationMapping, inputChanged, internalRevealRange, invalidateTextPresentation, invalidateTextPresentation, isBlockSelected, isEditable, isIgnoringAutoEditStrategies, isPrintable, markChanged, modelLine2WidgetLine, modelOffset2WidgetOffset, modelRange2ClosestWidgetRange, modelRange2WidgetRange, modelRange2WidgetRange, modelSelection2WidgetSelection, modelStyleRange2WidgetStyleRange, moveFocusToWidgetToken, overlapsWithVisibleRegion, prependAutoEditStrategy, prependVerifyKeyListener, print, print, redraws, refresh, register, releaseWidgetToken, removeAutoEditStrategy, removePainter, removePostSelectionChangedListener, removeTextHovers, removeTextInputListener, removeTextListener, removeTextPresentationListener, removeVerifyKeyListener, removeViewportListener, requestWidgetToken, requestWidgetToken, resetPlugins, resetVisibleRegion, revealRange, selectContentTypePlugin, selectionChanged, setAutoEditStrategies, setAutoIndentStrategy, setDefaultPrefixes, setDocumentPartitioning, setEditable, setEventConsumer, setHoverControlCreator, setHyperlinkDetectors, setHyperlinkPresenter, setIndentPrefixes, setInput, setMark, setRedraw, setRedraw, setSelectedRange, setSelection, setTabsToSpacesConverter, setTextColor, setTextColor, setTextDoubleClickStrategy, setTextHover, setTextHover, setTopIndex, setUndoManager, setVisibleDocument, setVisibleRegion, shift, shift, startSequentialRewriteMode, stopSequentialRewriteMode, unregister, updateSlaveDocument, updateTextListeners, updateViewportListeners, updateVisibleDocument, validateSelectionRange, widgetLine2ModelLine, widgetLineOfWidgetOffset, widgetlLine2ModelLine, widgetOffset2ModelOffset, widgetRange2ModelRange, widgetSelection2ModelSelection
addHelpListener, addSelectionChangedListener, fireHelpRequested, fireSelectionChanged, getData, handleHelpRequest, removeHelpListener, removeSelectionChangedListener, scrollDown, scrollUp, setData, setSelection
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
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
addSelectionChangedListener, removeSelectionChangedListener, setSelection
protected static final int GAP_SIZE
2
).
Note: As of 3.2, the text editor framework is no longer using 2 as
gap but 1, see {GAP_SIZE_1
.
protected static final int GAP_SIZE_1
1
).protected static final String _SELECTION_POSITION_CATEGORY
protected static final Object MODEL_ANNOTATION_MODEL
protected IContentAssistant fContentAssistant
protected boolean fContentAssistantInstalled
protected IQuickAssistAssistant fQuickAssistAssistant
protected boolean fQuickAssistAssistantInstalled
protected IContentFormatter fContentFormatter
protected IReconciler fReconciler
protected IPresentationReconciler fPresentationReconciler
protected IAnnotationHover fAnnotationHover
protected final Stack fSelections
protected IPositionUpdater fSelectionUpdater
protected String fSelectionCategory
protected IAnnotationHover fOverviewRulerAnnotationHover
protected IInformationPresenter fInformationPresenter
public SourceViewer(Composite parent, IVerticalRuler ruler, int styles)
parent
- the parent of the viewer's controlruler
- the vertical ruler used by this source viewerstyles
- the SWT style bits for the viewer's control,
if SWT.WRAP
is set then a custom document adapter needs to be provided, see TextViewer.createDocumentAdapter()
public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles)
showAnnotationsOverview
.
The viewer has not yet been initialized with a source viewer configuration.parent
- the parent of the viewer's controlverticalRuler
- the vertical ruler used by this source vieweroverviewRuler
- the overview rulershowAnnotationsOverview
- true
if the overview ruler should be visible, false
otherwisestyles
- the SWT style bits for the viewer's control,
if SWT.WRAP
is set then a custom document adapter needs to be provided, see TextViewer.createDocumentAdapter()
protected void createControl(Composite parent, int styles)
TextViewer
createControl
in class TextViewer
parent
- the parent of the viewer's controlstyles
- the SWT style bits for the viewer's controlprotected Layout createLayout()
public Control getControl()
Viewer
getControl
in interface ITextViewerExtension
getControl
in class TextViewer
public void setAnnotationHover(IAnnotationHover annotationHover)
ISourceViewer
setAnnotationHover
in interface ISourceViewer
annotationHover
- the hover to be used, null
is a valid argumentpublic void setOverviewRulerAnnotationHover(IAnnotationHover annotationHover)
annotationHover
- the hover to be used, null
is a valid argumentpublic void configure(SourceViewerConfiguration configuration)
ISourceViewer
ISourceViewerExtension2.unconfigure()
.configure
in interface ISourceViewer
configuration
- the source viewer configuration to be usedprotected void ensureAnnotationHoverManagerInstalled()
protected void ensureOverviewHoverManagerInstalled()
public void setHoverEnrichMode(ITextViewerExtension8.EnrichMode mode)
TextViewer
null
mode
defines when hovers
should be enriched once the mouse is moved into them.
If mode
is null
, hovers are automatically closed
when the mouse is moved out of the hover region
.
Note that a hover can only be enriched if its IInformationControlExtension5.getInformationPresenterControlCreator()
is not null
.
setHoverEnrichMode
in interface ITextViewerExtension8
setHoverEnrichMode
in class TextViewer
mode
- the enrich mode, or null
public void activatePlugins()
ITextViewer
activatePlugins
in interface ITextViewer
activatePlugins
in class TextViewer
public void setDocument(IDocument document)
ITextViewer
TextEvent
is
issued. This text event does not carry a related document event.setDocument
in interface ITextViewer
setDocument
in class TextViewer
document
- the viewer's new input document null
if nonepublic void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength)
ITextViewer
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)
.setDocument
in interface ITextViewer
setDocument
in class TextViewer
document
- the new input document or null
if nonevisibleRegionOffset
- the offset of the model rangevisibleRegionLength
- the length of the model rangepublic void setDocument(IDocument document, IAnnotationModel annotationModel)
ISourceViewer
TextEvent
is issued. This text event does not carry
a related document event.setDocument
in interface ISourceViewer
document
- the viewer's new input documentannotationModel
- the model for the viewer's visual annotationsITextViewer.setDocument(IDocument)
protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel)
annotationModel
- the wrapped annotation modelprotected void disposeVisualAnnotationModel()
public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength)
ISourceViewer
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)
.setDocument
in interface ISourceViewer
document
- the new input documentannotationModel
- the model of the viewer's visual annotationsmodelRangeOffset
- the offset of the model rangemodelRangeLength
- the length of the model rangeITextViewer.setDocument(IDocument, int, int)
public IAnnotationModel getAnnotationModel()
ISourceViewer
ISourceViewerExtension2.getVisualAnnotationModel()
in order to
get access to the viewer's visual annotation model.getAnnotationModel
in interface ISourceViewer
public IQuickAssistAssistant getQuickAssistAssistant()
ISourceViewerExtension3
getQuickAssistAssistant
in interface ISourceViewerExtension3
null
if none is configuredpublic final ContentAssistantFacade getContentAssistantFacade()
getContentAssistantFacade
in interface ISourceViewerExtension4
null
if none is
configuredpublic IQuickAssistInvocationContext getQuickAssistInvocationContext()
ISourceViewerExtension3
getQuickAssistInvocationContext
in interface ISourceViewerExtension3
null
if none is availablepublic IAnnotationModel getVisualAnnotationModel()
ISourceViewerExtension2
getVisualAnnotationModel
in interface ISourceViewerExtension2
public void unconfigure()
ISourceViewerExtension2
ISourceViewer.configure(SourceViewerConfiguration)
this method
can be called more than once without interleaving calls to
ISourceViewer.configure(SourceViewerConfiguration)
.unconfigure
in interface ISourceViewerExtension2
protected void handleDispose()
TextViewer
handleDispose
in class TextViewer
public boolean canDoOperation(int operation)
ITextOperationTarget
canDoOperation
in interface ITextOperationTarget
canDoOperation
in class TextViewer
operation
- the operation codetrue
if the specified operation can be performedprotected IFormattingContext createFormattingContext()
After the use of the context, clients are required to call
its dispose
method.
protected IFormattingContext createFormattingContext(int selectionOffset, int selectionLength)
FormattingContextProperties.CONTEXT_REGION
property set to an IRegion
,
the section of the document defined by that region is formatted, otherwise the whole
document is formatted.
The default implementation calls createFormattingContext()
and sets
the FormattingContextProperties.CONTEXT_REGION
property if the selection is
not empty. Overriding methods may implement a different logic, or return null
to indicate that the formatting operation should not proceed.
Returning null
may be used, for example, when the user clicks on
the Cancel button in a dialog that, in case of an empty selection, asks the user
whether formatting should be applied to the whole document or to the current statement.
Please notice that returning null
from this method cancels the already initiated
formatting operation unlike canDoOperation(int)
, which is used for enabling and
disabling formatting actions.
After the use of the context, clients are required to call its dispose
method.
selectionOffset
- the character offset of the selection in the documentselectionLength
- the length of the selectionnull
to cancel the formattingprotected Point rememberSelection()
restoreSelection()
.ITextViewer.getSelectedRange()
protected void restoreSelection()
If no selection was previously saved, nothing happens.
protected void clearRememberedSelection()
public void doOperation(int operation)
ITextOperationTarget
doOperation
must only be called if canDoOperation
returns true
.doOperation
in interface ITextOperationTarget
doOperation
in class TextViewer
operation
- the operation codeprotected void updateSlaveDocuments(IDocument masterDocument)
updateSlaveDocument
for their current visible range. Subclasses may reimplement.masterDocument
- the master documentpublic void enableOperation(int operation, boolean enable)
ITextOperationTargetExtension
enableOperation
in interface ITextOperationTargetExtension
enableOperation
in class TextViewer
operation
- the operation to enable/disableenable
- true
to enable the operation otherwise false
public void setRangeIndicator(Annotation rangeIndicator)
ISourceViewer
setRangeIndicator
in interface ISourceViewer
rangeIndicator
- the annotation to be used as this viewer's range indicatorpublic void setRangeIndication(int start, int length, boolean moveCursor)
ISourceViewer
setRangeIndication
in interface ISourceViewer
start
- the offset of the rangelength
- the length of the rangemoveCursor
- indicates whether the cursor should be moved to the given offsetpublic IRegion getRangeIndication()
ISourceViewer
getRangeIndication
in interface ISourceViewer
public void removeRangeIndication()
ISourceViewer
removeRangeIndication
in interface ISourceViewer
public void showAnnotations(boolean show)
ISourceViewer
By default, annotations and their presentation area are visible.
showAnnotations
in interface ISourceViewer
show
- indicates the visibility of annotationsprotected final IVerticalRuler getVerticalRuler()
public void addVerticalRulerColumn(IVerticalRulerColumn column)
column
- the column to be addedpublic void removeVerticalRulerColumn(IVerticalRulerColumn column)
column
- the column to be removedpublic void showAnnotationsOverview(boolean show)
ISourceViewerExtension
showAnnotationsOverview
in interface ISourceViewerExtension
show
- true
if annotation overview should be visible, false
otherwisepublic IAnnotationHover getCurrentAnnotationHover()
ISourceViewerExtension3
null
otherwise.getCurrentAnnotationHover
in interface ISourceViewerExtension3
null
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.