Class ContentAssistant
- All Implemented Interfaces:
IContentAssistant
,IContentAssistantExtension
,IContentAssistantExtension2
,IContentAssistantExtension3
,IContentAssistantExtension4
,ITextViewerLifecycle
,IWidgetTokenKeeper
,IWidgetTokenKeeperExtension
- Direct Known Subclasses:
SubjectControlContentAssistant
IContentAssistant
interface. Usually, clients
instantiate this class and configure it before using it.
Since 3.12, it can compute and display the proposals asynchronously when invoking
ContentAssistant(boolean)
with true
.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
An implementation ofIContentAssistListener
, this class is used to monitor key events in support of automatic activation of the content assistant. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Content assist command identifier for 'select next proposal'.static final String
Content assist command identifier for 'select previous proposal'.static final String
Dialog store constant for the x-size of the context selector pop-upstatic final String
Dialog store constant for the y-size of the context selector pop-upstatic final String
Dialog store constant for the x-size of the completion proposal pop-upstatic final String
Dialog store constant for the y-size of the completion proposal pop-upstatic final int
The popup priority: > linked position proposals and hover pop-ups.Fields inherited from interface org.eclipse.jface.text.contentassist.IContentAssistant
CONTEXT_INFO_ABOVE, CONTEXT_INFO_BELOW, PROPOSAL_OVERLAY, PROPOSAL_REMOVE, PROPOSAL_STACKED
-
Constructor Summary
ConstructorDescriptionCreates a new content assistant.ContentAssistant
(boolean asynchronous) Creates a new content assistant. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCompletionListener
(ICompletionListener listener) Adds a completion listener that will be informed before proposals are computed.void
addContentAssistProcessor
(IContentAssistProcessor processor, String contentType) Registers a given content assist processor for a particular content type.Inserts the common prefix of the available completions.protected void
Callback to signal this content assistant that the presentation of the context information has been stopped.protected ContentAssistant.AutoAssistListener
This method allows subclasses to provide their ownContentAssistant.AutoAssistListener
.final void
enableAutoActivateCompletionOnType
(boolean enable) Sets whether this completion list is shown on each valid character which is either a letter or digit.void
enableAutoActivation
(boolean enabled) Enables the content assistant's auto activation mode.void
enableAutoInsert
(boolean enabled) Enables the content assistant's auto insertion mode.void
enableColoredLabels
(boolean isEnabled) Enables the support for colored labels in the proposal popup.void
enableCompletionProposalTriggerChars
(boolean enable) Set whether completion trigger chars are enabled.void
enablePrefixCompletion
(boolean enabled) Sets the prefix completion property.int
Gets the delay after which the content assistant is automatically invoked if the cursor is behind an auto activation character.getContentAssistProcessor
(String contentType) Returns the content assist processor to be used for the given content type.Returns the document partitioning this content assistant is using.final IHandler
getHandler
(String commandId) Returns the handler for the given command identifier.boolean
Returns whether the content assistant proposal popup has the focus.protected void
hide()
Hides any open pop-ups.protected void
install()
protected void
install
(IContentAssistSubjectControl contentAssistSubjectControl) void
install
(ITextViewer textViewer) Installs content assist support on the given text viewer.boolean
Returns whether completion trigger char are enabled.protected boolean
Returns whether the context information popup is active.protected boolean
Returns whether proposal popup is active.protected void
Callback to signal this content assistant that the presentation of the possible completions has been stopped.protected final void
registerHandler
(String commandId, IHandler handler) Registers the given handler under the given command identifier.void
removeCompletionListener
(ICompletionListener listener) Removes a completion listener.void
removes the given processor from all content types in thisContentAssistant
boolean
The given widget token owner requests the widget token from this token keeper.boolean
requestWidgetToken
(IWidgetTokenOwner owner, int priority) The given widget token owner requests the widget token from this token keeper.protected Point
Restores the content assist's proposal pop-up size.protected Point
Restores the content assist's context selector pop-up size.void
setAutoActivationDelay
(int delay) Sets the delay after which the content assistant is automatically invoked if the cursor is behind an auto activation character.void
setContentAssistProcessor
(IContentAssistProcessor processor, String contentType) Registers a given content assist processor for a particular content type.void
setContextInformationPopupBackground
(Color background) Sets the context information popup's background color.void
setContextInformationPopupForeground
(Color foreground) Sets the context information popup's foreground color.void
setContextInformationPopupOrientation
(int orientation) Sets the context information popup's orientation.void
setContextSelectorBackground
(Color background) Sets the context selector's background color.void
setContextSelectorForeground
(Color foreground) Sets the context selector's foreground color.void
setDocumentPartitioning
(String partitioning) Sets the document partitioning this content assistant is using.void
setEmptyMessage
(String message) Sets the text to be shown if no proposals are available andempty lists
are displayed.boolean
setFocus
(IWidgetTokenOwner owner) Requests the receiver to give focus to its popup shell, hover, or similar.void
Sets the information control creator for the additional information control.void
setProposalPopupOrientation
(int orientation) Sets the proposal pop-ups' orientation.void
setProposalSelectorBackground
(Color background) Sets the proposal selector's background color.void
setProposalSelectorForeground
(Color foreground) Sets the proposal's foreground color.void
setRepeatedInvocationMode
(boolean cycling) Enables repeated invocation mode, which will trigger re-computation of the proposals when code assist is executed repeatedly.void
setRepeatedInvocationTrigger
(KeySequence sequence) Sets the key sequence to listen for in repeated invocation mode.void
setRestoreCompletionProposalSize
(IDialogSettings dialogSettings) Tells this information control manager to open the information control with the values contained in the given dialog settings and to store the control's last valid size in the given dialog settings.void
setShowEmptyList
(boolean showEmpty) Enables displaying an empty completion proposal pop-up.void
setSorter
(ICompletionProposalSorter sorter) Sets the proposal sorter.void
setStatusLineVisible
(boolean show) Enables displaying a status line below the proposal popup.void
setStatusMessage
(String message) Sets the caption message displayed at the bottom of the completion proposal popup.Shows context information for the content at the viewer's cursor position.Shows all possible completions of the content at the viewer's cursor position.protected void
Stores the content assist's proposal pop-up size.protected void
Stores the content assist's context selector pop-up size.void
Uninstalls content assist support from the text viewer it has previously be installed on.
-
Field Details
-
SELECT_NEXT_PROPOSAL_COMMAND_ID
Content assist command identifier for 'select next proposal'.- Since:
- 3.4
- See Also:
-
SELECT_PREVIOUS_PROPOSAL_COMMAND_ID
Content assist command identifier for 'select previous proposal'.- Since:
- 3.4
- See Also:
-
STORE_SIZE_X
Dialog store constant for the x-size of the completion proposal pop-up- Since:
- 3.0
- See Also:
-
STORE_SIZE_Y
Dialog store constant for the y-size of the completion proposal pop-up- Since:
- 3.0
- See Also:
-
STORE_CONTEXT_SELECTOR_POPUP_SIZE_X
Dialog store constant for the x-size of the context selector pop-up- Since:
- 3.9
- See Also:
-
STORE_CONTEXT_SELECTOR_POPUP_SIZE_Y
Dialog store constant for the y-size of the context selector pop-up- Since:
- 3.9
- See Also:
-
WIDGET_PRIORITY
public static final int WIDGET_PRIORITYThe popup priority: > linked position proposals and hover pop-ups. Default value:20
;- Since:
- 3.0
- See Also:
-
-
Constructor Details
-
ContentAssistant
public ContentAssistant()Creates a new content assistant. The content assistant is not automatically activated, overlays the completion proposals with context information list if necessary, and shows the context information above the location at which it was activated. If auto activation will be enabled, without further configuration steps, this content assistant is activated after a 500 milliseconds delay. It uses the default partitioning. -
ContentAssistant
public ContentAssistant(boolean asynchronous) Creates a new content assistant. The content assistant is not automatically activated, overlays the completion proposals with context information list if necessary, and shows the context information above the location at which it was activated. If auto activation will be enabled, without further configuration steps, this content assistant is activated after a 500 milliseconds delay. It uses the default partitioning.- Parameters:
asynchronous
-true
if this content assistant should present the proposals asynchronously,false
otherwise- Since:
- 3.12
-
-
Method Details
-
setDocumentPartitioning
Sets the document partitioning this content assistant is using.- Parameters:
partitioning
- the document partitioning for this content assistant- Since:
- 3.0
-
getDocumentPartitioning
Description copied from interface:IContentAssistantExtension
Returns the document partitioning this content assistant is using.- Specified by:
getDocumentPartitioning
in interfaceIContentAssistantExtension
- Returns:
- the document partitioning this content assistant is using
-
setContentAssistProcessor
Registers a given content assist processor for a particular content type. If there is already a processor registered for this type, the new processor is registered instead of the old one.- Parameters:
processor
- the content assist processor to register, ornull
to remove an existing onecontentType
- the content type under which to register
-
addContentAssistProcessor
Registers a given content assist processor for a particular content type. If there is already a processor registered for this type, it is kept and the new processor is appended to the list of processors for given content-type.- Parameters:
processor
- The content-assist process to addcontentType
- Document token content-type it applies to- Since:
- 3.12
-
removeContentAssistProcessor
removes the given processor from all content types in thisContentAssistant
- Parameters:
processor
- The content-assist process to remove- Since:
- 3.17
-
getContentAssistProcessor
Description copied from interface:IContentAssistant
Returns the content assist processor to be used for the given content type.- Specified by:
getContentAssistProcessor
in interfaceIContentAssistant
- Parameters:
contentType
- the type of the content for which this content assistant is to be requested- Returns:
- an instance content assist processor or
null
if none exists for the specified content type
-
enableAutoActivation
public void enableAutoActivation(boolean enabled) Enables the content assistant's auto activation mode.- Parameters:
enabled
- indicates whether auto activation is enabled or not
-
enableAutoInsert
public void enableAutoInsert(boolean enabled) Enables the content assistant's auto insertion mode. If enabled, the content assistant inserts a proposal automatically if it is the only proposal. In the case of ambiguities, the user must make the choice.- Parameters:
enabled
- indicates whether auto insertion is enabled or not- Since:
- 2.0
-
createAutoAssistListener
This method allows subclasses to provide their ownContentAssistant.AutoAssistListener
.- Returns:
- a new auto assist listener
- Since:
- 3.4
-
setAutoActivationDelay
public void setAutoActivationDelay(int delay) Sets the delay after which the content assistant is automatically invoked if the cursor is behind an auto activation character.- Parameters:
delay
- the auto activation delay (as of 3.6 a negative argument will be set to 0)
-
getAutoActivationDelay
public int getAutoActivationDelay()Gets the delay after which the content assistant is automatically invoked if the cursor is behind an auto activation character.- Returns:
- the auto activation delay (will not be negative)
- Since:
- 3.4
-
setProposalPopupOrientation
public void setProposalPopupOrientation(int orientation) Sets the proposal pop-ups' orientation. The following values may be used:- PROPOSAL_OVERLAY
proposal popup windows should overlay each other
- PROPOSAL_REMOVE
any currently shown proposal popup should be closed
- PROPOSAL_STACKED
proposal popup windows should be vertical stacked, with no overlap, beneath the line containing the current cursor location
- Parameters:
orientation
- the popup's orientation
- PROPOSAL_OVERLAY
-
setContextInformationPopupOrientation
public void setContextInformationPopupOrientation(int orientation) Sets the context information popup's orientation. The following values may be used:- CONTEXT_ABOVE
context information popup should always appear above the line containing the current cursor location
- CONTEXT_BELOW
context information popup should always appear below the line containing the current cursor location
- Parameters:
orientation
- the popup's orientation
- CONTEXT_ABOVE
-
setContextInformationPopupBackground
Sets the context information popup's background color.- Parameters:
background
- the background color
-
setContextInformationPopupForeground
Sets the context information popup's foreground color.- Parameters:
foreground
- the foreground color- Since:
- 2.0
-
setProposalSelectorBackground
Sets the proposal selector's background color.Note: As of 3.4, you should only call this method if you want to override the
JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR
.- Parameters:
background
- the background color- Since:
- 2.0
-
setProposalSelectorForeground
Sets the proposal's foreground color.Note: As of 3.4, you should only call this method if you want to override the
JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR
.- Parameters:
foreground
- the foreground color- Since:
- 2.0
-
setContextSelectorBackground
Sets the context selector's background color.- Parameters:
background
- the background color- Since:
- 2.0
-
setContextSelectorForeground
Sets the context selector's foreground color.- Parameters:
foreground
- the foreground color- Since:
- 2.0
-
setInformationControlCreator
Sets the information control creator for the additional information control.- Parameters:
creator
- the information control creator for the additional information control- Since:
- 2.0
-
install
-
install
Description copied from interface:IContentAssistant
Installs content assist support on the given text viewer.- Specified by:
install
in interfaceIContentAssistant
- Specified by:
install
in interfaceITextViewerLifecycle
- Parameters:
textViewer
- the text viewer on which content assist will work
-
install
protected void install() -
uninstall
public void uninstall()Description copied from interface:IContentAssistant
Uninstalls content assist support from the text viewer it has previously be installed on.- Specified by:
uninstall
in interfaceIContentAssistant
- Specified by:
uninstall
in interfaceITextViewerLifecycle
-
showPossibleCompletions
Description copied from interface:IContentAssistant
Shows all possible completions of the content at the viewer's cursor position.- Specified by:
showPossibleCompletions
in interfaceIContentAssistant
- Returns:
- an optional error message if no proposals can be computed
-
completePrefix
Description copied from interface:IContentAssistantExtension
Inserts the common prefix of the available completions. If no common prefix can be computed it is identical toIContentAssistant.showPossibleCompletions()
.- Specified by:
completePrefix
in interfaceIContentAssistantExtension
- Returns:
- an optional error message if no proposals can be computed
-
possibleCompletionsClosed
protected void possibleCompletionsClosed()Callback to signal this content assistant that the presentation of the possible completions has been stopped.- Since:
- 2.1
-
showContextInformation
Description copied from interface:IContentAssistant
Shows context information for the content at the viewer's cursor position.- Specified by:
showContextInformation
in interfaceIContentAssistant
- Returns:
- an optional error message if no context information can be computed
-
contextInformationClosed
protected void contextInformationClosed()Callback to signal this content assistant that the presentation of the context information has been stopped.- Since:
- 2.1
-
requestWidgetToken
Description copied from interface:IWidgetTokenKeeper
The given widget token owner requests the widget token from this token keeper. Returnstrue
if the token is released by this token keeper. Note, the keeper must not callreleaseWidgetToken(IWidgetTokenKeeper)
explicitly.Replaced by
IWidgetTokenKeeperExtension.requestWidgetToken(IWidgetTokenOwner, int)
.- Specified by:
requestWidgetToken
in interfaceIWidgetTokenKeeper
- Parameters:
owner
- the token owner- Returns:
true
if token has been releasedfalse
otherwise
-
requestWidgetToken
Description copied from interface:IWidgetTokenKeeperExtension
The given widget token owner requests the widget token from this token keeper. Returnstrue
if the token is released by this token keeper. Note, the keeper must not callreleaseWidgetToken(IWidgetTokenKeeper)
explicitly.The general contract is that the receiver should release the token if
priority
exceeds the receiver's priority.- Specified by:
requestWidgetToken
in interfaceIWidgetTokenKeeperExtension
- Parameters:
owner
- the token ownerpriority
- the priority of the request- Returns:
true
if token has been releasedfalse
otherwise
-
setFocus
Description copied from interface:IWidgetTokenKeeperExtension
Requests the receiver to give focus to its popup shell, hover, or similar. There is no assumption made whether the receiver actually succeeded in taking the focus. The return value gives a hint whether the receiver tried to take focus.- Specified by:
setFocus
in interfaceIWidgetTokenKeeperExtension
- Parameters:
owner
- the token owner- Returns:
true
if the receiver tried to take focus,false
if it did not.
-
hide
protected void hide()Hides any open pop-ups.- Since:
- 3.0
-
setRestoreCompletionProposalSize
Tells this information control manager to open the information control with the values contained in the given dialog settings and to store the control's last valid size in the given dialog settings.Note: This API is only valid if the information control implements
IInformationControlExtension3
. Not following this restriction will later result in anUnsupportedOperationException
.The constants used to store the values are:
- Parameters:
dialogSettings
- the dialog settings- Since:
- 3.0
-
storeCompletionProposalPopupSize
protected void storeCompletionProposalPopupSize()Stores the content assist's proposal pop-up size. -
storeContextSelectorPopupSize
protected void storeContextSelectorPopupSize()Stores the content assist's context selector pop-up size.- Since:
- 3.9
-
restoreCompletionProposalPopupSize
Restores the content assist's proposal pop-up size.- Returns:
- the stored size or
null
if none - Since:
- 3.0
-
restoreContextSelectorPopupSize
Restores the content assist's context selector pop-up size.- Returns:
- the stored size or
null
if none - Since:
- 3.9
-
enablePrefixCompletion
public void enablePrefixCompletion(boolean enabled) Sets the prefix completion property. If enabled, content assist delegates completion to prefix completion.- Parameters:
enabled
-true
to enable prefix completion,false
to disable
-
hasProposalPopupFocus
public boolean hasProposalPopupFocus()Returns whether the content assistant proposal popup has the focus.- Returns:
true
if the proposal popup has the focus- Since:
- 3.0
-
addCompletionListener
Description copied from interface:IContentAssistantExtension2
Adds a completion listener that will be informed before proposals are computed.- Specified by:
addCompletionListener
in interfaceIContentAssistantExtension2
- Parameters:
listener
- the listener
-
removeCompletionListener
Description copied from interface:IContentAssistantExtension2
Removes a completion listener.- Specified by:
removeCompletionListener
in interfaceIContentAssistantExtension2
- Parameters:
listener
- the listener to remove
-
setRepeatedInvocationMode
public void setRepeatedInvocationMode(boolean cycling) Description copied from interface:IContentAssistantExtension2
Enables repeated invocation mode, which will trigger re-computation of the proposals when code assist is executed repeatedly. The default is nofalse
.- Specified by:
setRepeatedInvocationMode
in interfaceIContentAssistantExtension2
- Parameters:
cycling
-true
to enable repetition mode,false
to disable
-
setShowEmptyList
public void setShowEmptyList(boolean showEmpty) Description copied from interface:IContentAssistantExtension2
Enables displaying an empty completion proposal pop-up. The default is not to show an empty list.- Specified by:
setShowEmptyList
in interfaceIContentAssistantExtension2
- Parameters:
showEmpty
-true
to show empty lists
-
setStatusLineVisible
public void setStatusLineVisible(boolean show) Description copied from interface:IContentAssistantExtension2
Enables displaying a status line below the proposal popup. The default is not to show the status line. The contents of the status line may be set viaIContentAssistantExtension2.setStatusMessage(String)
.- Specified by:
setStatusLineVisible
in interfaceIContentAssistantExtension2
- Parameters:
show
-true
to show a message line,false
to not show one.
-
setStatusMessage
Description copied from interface:IContentAssistantExtension2
Sets the caption message displayed at the bottom of the completion proposal popup.- Specified by:
setStatusMessage
in interfaceIContentAssistantExtension2
- Parameters:
message
- the message
-
setEmptyMessage
Description copied from interface:IContentAssistantExtension2
Sets the text to be shown if no proposals are available andempty lists
are displayed.- Specified by:
setEmptyMessage
in interfaceIContentAssistantExtension2
- Parameters:
message
- the text for the empty list
-
setRepeatedInvocationTrigger
Description copied from interface:IContentAssistantExtension3
Sets the key sequence to listen for in repeated invocation mode. If the key sequence is encountered, a step in the repetition iteration is triggered.- Specified by:
setRepeatedInvocationTrigger
in interfaceIContentAssistantExtension3
- Parameters:
sequence
- the key sequence used for the repeated invocation mode ornull
if none
-
isProposalPopupActive
protected boolean isProposalPopupActive()Returns whether proposal popup is active.- Returns:
true
if the proposal popup is active,false
otherwise- Since:
- 3.4
-
isContextInfoPopupActive
protected boolean isContextInfoPopupActive()Returns whether the context information popup is active.- Returns:
true
if the context information popup is active,false
otherwise- Since:
- 3.4
-
getHandler
Returns the handler for the given command identifier.The same handler instance will be returned when called a more than once with the same command identifier.
- Specified by:
getHandler
in interfaceIContentAssistantExtension4
- Parameters:
commandId
- the command identifier- Returns:
- the handler for the given command identifier
- Since:
- 3.4
-
registerHandler
Registers the given handler under the given command identifier.- Parameters:
commandId
- the command identifierhandler
- the handler- Since:
- 3.4
-
enableColoredLabels
public void enableColoredLabels(boolean isEnabled) Enables the support for colored labels in the proposal popup.Completion proposals can implement
ICompletionProposalExtension6
to provide colored proposal labels.- Parameters:
isEnabled
- iftrue
the support for colored labels is enabled in the proposal popup- Since:
- 3.4
-
setSorter
Sets the proposal sorter.- Parameters:
sorter
- the sorter to be used, ornull
if no sorting is requested- Since:
- 3.8
-
isCompletionProposalTriggerCharsEnabled
public boolean isCompletionProposalTriggerCharsEnabled()Returns whether completion trigger char are enabled. If false, completion proposal trigger chars are ignored and only Enter key can be used to select a proposal.- Returns:
- whether completion trigger char are enabled.
- Since:
- 3.15
- See Also:
-
enableCompletionProposalTriggerChars
public void enableCompletionProposalTriggerChars(boolean enable) Set whether completion trigger chars are enabled. If set to false, completion proposal trigger chars are ignored and only Enter key can be used to select a proposal.- Parameters:
enable
- whether current content assistant should consider completion trigger chars.- Since:
- 3.15
- See Also:
-
enableAutoActivateCompletionOnType
public final void enableAutoActivateCompletionOnType(boolean enable) Sets whether this completion list is shown on each valid character which is either a letter or digit. This works conjunction withfAsynchronous
- Parameters:
enable
- whether or not to enable this feature- Since:
- 3.21
-