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
Nested ClassesModifier and TypeClassDescriptionprotected classAn implementation ofIContentAssistListener, this class is used to monitor key events in support of automatic activation of the content assistant. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringContent assist command identifier for 'select next proposal'.static final StringContent assist command identifier for 'select previous proposal'.static final StringDialog store constant for the x-size of the context selector pop-upstatic final StringDialog store constant for the y-size of the context selector pop-upstatic final StringDialog store constant for the x-size of the completion proposal pop-upstatic final StringDialog store constant for the y-size of the completion proposal pop-upstatic final intThe 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
ConstructorsConstructorDescriptionCreates a new content assistant.ContentAssistant(boolean asynchronous) Creates a new content assistant. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompletionListener(ICompletionListener listener) Adds a completion listener that will be informed before proposals are computed.voidaddContentAssistProcessor(IContentAssistProcessor processor, String contentType) Registers a given content assist processor for a particular content type.Inserts the common prefix of the available completions.protected voidCallback to signal this content assistant that the presentation of the context information has been stopped.protected ContentAssistant.AutoAssistListenerThis method allows subclasses to provide their ownContentAssistant.AutoAssistListener.final voidenableAutoActivateCompletionOnType(boolean enable) Sets whether this completion list is shown on each valid character which is either a letter or digit.voidenableAutoActivation(boolean enabled) Enables the content assistant's auto activation mode.voidenableAutoInsert(boolean enabled) Enables the content assistant's auto insertion mode.voidenableColoredLabels(boolean isEnabled) Enables the support for colored labels in the proposal popup.voidenableCompletionProposalTriggerChars(boolean enable) Set whether completion trigger chars are enabled.voidenablePrefixCompletion(boolean enabled) Sets the prefix completion property.intGets 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 IHandlergetHandler(String commandId) Returns the handler for the given command identifier.booleanReturns whether the content assistant proposal popup has the focus.protected voidhide()Hides any open pop-ups.protected voidinstall()protected voidinstall(IContentAssistSubjectControl contentAssistSubjectControl) voidinstall(ITextViewer textViewer) Installs content assist support on the given text viewer.booleanReturns whether completion trigger char are enabled.protected booleanReturns whether the context information popup is active.protected booleanReturns whether proposal popup is active.protected voidCallback to signal this content assistant that the presentation of the possible completions has been stopped.protected final voidregisterHandler(String commandId, IHandler handler) Registers the given handler under the given command identifier.voidremoveCompletionListener(ICompletionListener listener) Removes a completion listener.voidremoves the given processor from all content types in thisContentAssistantbooleanThe given widget token owner requests the widget token from this token keeper.booleanrequestWidgetToken(IWidgetTokenOwner owner, int priority) The given widget token owner requests the widget token from this token keeper.protected PointRestores the content assist's proposal pop-up size.protected PointRestores the content assist's context selector pop-up size.voidsetAutoActivationDelay(int delay) Sets the delay after which the content assistant is automatically invoked if the cursor is behind an auto activation character.voidsetContentAssistProcessor(IContentAssistProcessor processor, String contentType) Registers a given content assist processor for a particular content type.voidsetContextInformationPopupBackground(Color background) Sets the context information popup's background color.voidsetContextInformationPopupForeground(Color foreground) Sets the context information popup's foreground color.voidsetContextInformationPopupOrientation(int orientation) Sets the context information popup's orientation.voidsetContextSelectorBackground(Color background) Sets the context selector's background color.voidsetContextSelectorForeground(Color foreground) Sets the context selector's foreground color.voidsetDocumentPartitioning(String partitioning) Sets the document partitioning this content assistant is using.voidsetEmptyMessage(String message) Sets the text to be shown if no proposals are available andempty listsare displayed.booleansetFocus(IWidgetTokenOwner owner) Requests the receiver to give focus to its popup shell, hover, or similar.voidSets the information control creator for the additional information control.voidsetProposalPopupOrientation(int orientation) Sets the proposal pop-ups' orientation.voidsetProposalSelectorBackground(Color background) Sets the proposal selector's background color.voidsetProposalSelectorForeground(Color foreground) Sets the proposal's foreground color.voidsetRepeatedInvocationMode(boolean cycling) Enables repeated invocation mode, which will trigger re-computation of the proposals when code assist is executed repeatedly.voidsetRepeatedInvocationTrigger(KeySequence sequence) Sets the key sequence to listen for in repeated invocation mode.voidsetRestoreCompletionProposalSize(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.voidsetShowEmptyList(boolean showEmpty) Enables displaying an empty completion proposal pop-up.voidsetSorter(ICompletionProposalSorter sorter) Sets the proposal sorter.voidsetStatusLineVisible(boolean show) Enables displaying a status line below the proposal popup.voidsetStatusMessage(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 voidStores the content assist's proposal pop-up size.protected voidStores the content assist's context selector pop-up size.voidUninstalls 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-trueif this content assistant should present the proposals asynchronously,falseotherwise- 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:IContentAssistantExtensionReturns the document partitioning this content assistant is using.- Specified by:
getDocumentPartitioningin 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, ornullto 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:IContentAssistantReturns the content assist processor to be used for the given content type.- Specified by:
getContentAssistProcessorin interfaceIContentAssistant- Parameters:
contentType- the type of the content for which this content assistant is to be requested- Returns:
- an instance content assist processor or
nullif 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:IContentAssistantInstalls content assist support on the given text viewer.- Specified by:
installin interfaceIContentAssistant- Specified by:
installin interfaceITextViewerLifecycle- Parameters:
textViewer- the text viewer on which content assist will work
-
install
protected void install() -
uninstall
public void uninstall()Description copied from interface:IContentAssistantUninstalls content assist support from the text viewer it has previously be installed on.- Specified by:
uninstallin interfaceIContentAssistant- Specified by:
uninstallin interfaceITextViewerLifecycle
-
showPossibleCompletions
Description copied from interface:IContentAssistantShows all possible completions of the content at the viewer's cursor position.- Specified by:
showPossibleCompletionsin interfaceIContentAssistant- Returns:
- an optional error message if no proposals can be computed
-
completePrefix
Description copied from interface:IContentAssistantExtensionInserts the common prefix of the available completions. If no common prefix can be computed it is identical toIContentAssistant.showPossibleCompletions().- Specified by:
completePrefixin 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:IContentAssistantShows context information for the content at the viewer's cursor position.- Specified by:
showContextInformationin 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:IWidgetTokenKeeperThe given widget token owner requests the widget token from this token keeper. Returnstrueif the token is released by this token keeper. Note, the keeper must not callreleaseWidgetToken(IWidgetTokenKeeper)explicitly.Replaced by
IWidgetTokenKeeperExtension.requestWidgetToken(IWidgetTokenOwner, int).- Specified by:
requestWidgetTokenin interfaceIWidgetTokenKeeper- Parameters:
owner- the token owner- Returns:
trueif token has been releasedfalseotherwise
-
requestWidgetToken
Description copied from interface:IWidgetTokenKeeperExtensionThe given widget token owner requests the widget token from this token keeper. Returnstrueif 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
priorityexceeds the receiver's priority.- Specified by:
requestWidgetTokenin interfaceIWidgetTokenKeeperExtension- Parameters:
owner- the token ownerpriority- the priority of the request- Returns:
trueif token has been releasedfalseotherwise
-
setFocus
Description copied from interface:IWidgetTokenKeeperExtensionRequests 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:
setFocusin interfaceIWidgetTokenKeeperExtension- Parameters:
owner- the token owner- Returns:
trueif the receiver tried to take focus,falseif 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
nullif none - Since:
- 3.0
-
restoreContextSelectorPopupSize
Restores the content assist's context selector pop-up size.- Returns:
- the stored size or
nullif 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-trueto enable prefix completion,falseto disable
-
hasProposalPopupFocus
public boolean hasProposalPopupFocus()Returns whether the content assistant proposal popup has the focus.- Returns:
trueif the proposal popup has the focus- Since:
- 3.0
-
addCompletionListener
Description copied from interface:IContentAssistantExtension2Adds a completion listener that will be informed before proposals are computed.- Specified by:
addCompletionListenerin interfaceIContentAssistantExtension2- Parameters:
listener- the listener
-
removeCompletionListener
Description copied from interface:IContentAssistantExtension2Removes a completion listener.- Specified by:
removeCompletionListenerin interfaceIContentAssistantExtension2- Parameters:
listener- the listener to remove
-
setRepeatedInvocationMode
public void setRepeatedInvocationMode(boolean cycling) Description copied from interface:IContentAssistantExtension2Enables repeated invocation mode, which will trigger re-computation of the proposals when code assist is executed repeatedly. The default is nofalse.- Specified by:
setRepeatedInvocationModein interfaceIContentAssistantExtension2- Parameters:
cycling-trueto enable repetition mode,falseto disable
-
setShowEmptyList
public void setShowEmptyList(boolean showEmpty) Description copied from interface:IContentAssistantExtension2Enables displaying an empty completion proposal pop-up. The default is not to show an empty list.- Specified by:
setShowEmptyListin interfaceIContentAssistantExtension2- Parameters:
showEmpty-trueto show empty lists
-
setStatusLineVisible
public void setStatusLineVisible(boolean show) Description copied from interface:IContentAssistantExtension2Enables 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:
setStatusLineVisiblein interfaceIContentAssistantExtension2- Parameters:
show-trueto show a message line,falseto not show one.
-
setStatusMessage
Description copied from interface:IContentAssistantExtension2Sets the caption message displayed at the bottom of the completion proposal popup.- Specified by:
setStatusMessagein interfaceIContentAssistantExtension2- Parameters:
message- the message
-
setEmptyMessage
Description copied from interface:IContentAssistantExtension2Sets the text to be shown if no proposals are available andempty listsare displayed.- Specified by:
setEmptyMessagein interfaceIContentAssistantExtension2- Parameters:
message- the text for the empty list
-
setRepeatedInvocationTrigger
Description copied from interface:IContentAssistantExtension3Sets 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:
setRepeatedInvocationTriggerin interfaceIContentAssistantExtension3- Parameters:
sequence- the key sequence used for the repeated invocation mode ornullif none
-
isProposalPopupActive
protected boolean isProposalPopupActive()Returns whether proposal popup is active.- Returns:
trueif the proposal popup is active,falseotherwise- Since:
- 3.4
-
isContextInfoPopupActive
protected boolean isContextInfoPopupActive()Returns whether the context information popup is active.- Returns:
trueif the context information popup is active,falseotherwise- 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:
getHandlerin 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
ICompletionProposalExtension6to provide colored proposal labels.- Parameters:
isEnabled- iftruethe 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, ornullif 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
-