Class ContentAssistant

java.lang.Object
org.eclipse.jface.text.contentassist.ContentAssistant
All Implemented Interfaces:
IContentAssistant, IContentAssistantExtension, IContentAssistantExtension2, IContentAssistantExtension3, IContentAssistantExtension4, IWidgetTokenKeeper, IWidgetTokenKeeperExtension
Direct Known Subclasses:
SubjectControlContentAssistant

The standard implementation of the 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.
  • Field Details

    • SELECT_NEXT_PROPOSAL_COMMAND_ID

      public static final String SELECT_NEXT_PROPOSAL_COMMAND_ID
      Content assist command identifier for 'select next proposal'.
      Since:
      3.4
      See Also:
    • SELECT_PREVIOUS_PROPOSAL_COMMAND_ID

      public static final String SELECT_PREVIOUS_PROPOSAL_COMMAND_ID
      Content assist command identifier for 'select previous proposal'.
      Since:
      3.4
      See Also:
    • STORE_SIZE_X

      public static final String STORE_SIZE_X
      Dialog store constant for the x-size of the completion proposal pop-up
      Since:
      3.0
      See Also:
    • STORE_SIZE_Y

      public static final String 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

      public static final String 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

      public static final String 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_PRIORITY
      The 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

      public void setDocumentPartitioning(String partitioning)
      Sets the document partitioning this content assistant is using.
      Parameters:
      partitioning - the document partitioning for this content assistant
      Since:
      3.0
    • getDocumentPartitioning

      public String getDocumentPartitioning()
      Description copied from interface: IContentAssistantExtension
      Returns the document partitioning this content assistant is using.
      Specified by:
      getDocumentPartitioning in interface IContentAssistantExtension
      Returns:
      the document partitioning this content assistant is using
    • setContentAssistProcessor

      public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType)
      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, or null to remove an existing one
      contentType - the content type under which to register
    • addContentAssistProcessor

      public void addContentAssistProcessor(IContentAssistProcessor processor, String contentType)
      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 add
      contentType - Document token content-type it applies to
      Since:
      3.12
    • removeContentAssistProcessor

      public void removeContentAssistProcessor(IContentAssistProcessor processor)
      removes the given processor from all content types in this ContentAssistant
      Parameters:
      processor - The content-assist process to remove
      Since:
      3.17
    • getContentAssistProcessor

      public IContentAssistProcessor getContentAssistProcessor(String contentType)
      Description copied from interface: IContentAssistant
      Returns the content assist processor to be used for the given content type.
      Specified by:
      getContentAssistProcessor in interface IContentAssistant
      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

      protected ContentAssistant.AutoAssistListener createAutoAssistListener()
      This method allows subclasses to provide their own ContentAssistant.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
    • 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
    • setContextInformationPopupBackground

      public void setContextInformationPopupBackground(Color background)
      Sets the context information popup's background color.
      Parameters:
      background - the background color
    • setContextInformationPopupForeground

      public void setContextInformationPopupForeground(Color foreground)
      Sets the context information popup's foreground color.
      Parameters:
      foreground - the foreground color
      Since:
      2.0
    • setProposalSelectorBackground

      public void setProposalSelectorBackground(Color background)
      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

      public void setProposalSelectorForeground(Color foreground)
      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

      public void setContextSelectorBackground(Color background)
      Sets the context selector's background color.
      Parameters:
      background - the background color
      Since:
      2.0
    • setContextSelectorForeground

      public void setContextSelectorForeground(Color foreground)
      Sets the context selector's foreground color.
      Parameters:
      foreground - the foreground color
      Since:
      2.0
    • setInformationControlCreator

      public void setInformationControlCreator(IInformationControlCreator creator)
      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

      protected void install(IContentAssistSubjectControl contentAssistSubjectControl)
    • install

      public void install(ITextViewer textViewer)
      Description copied from interface: IContentAssistant
      Installs content assist support on the given text viewer.
      Specified by:
      install in interface IContentAssistant
      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 interface IContentAssistant
    • showPossibleCompletions

      public String showPossibleCompletions()
      Description copied from interface: IContentAssistant
      Shows all possible completions of the content at the viewer's cursor position.
      Specified by:
      showPossibleCompletions in interface IContentAssistant
      Returns:
      an optional error message if no proposals can be computed
    • completePrefix

      public String completePrefix()
      Description copied from interface: IContentAssistantExtension
      Inserts the common prefix of the available completions. If no common prefix can be computed it is identical to IContentAssistant.showPossibleCompletions().
      Specified by:
      completePrefix in interface IContentAssistantExtension
      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

      public String showContextInformation()
      Description copied from interface: IContentAssistant
      Shows context information for the content at the viewer's cursor position.
      Specified by:
      showContextInformation in interface IContentAssistant
      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

      public boolean requestWidgetToken(IWidgetTokenOwner owner)
      Description copied from interface: IWidgetTokenKeeper
      The given widget token owner requests the widget token from this token keeper. Returns true if the token is released by this token keeper. Note, the keeper must not call releaseWidgetToken(IWidgetTokenKeeper) explicitly.

      Replaced by IWidgetTokenKeeperExtension.requestWidgetToken(IWidgetTokenOwner, int).

      Specified by:
      requestWidgetToken in interface IWidgetTokenKeeper
      Parameters:
      owner - the token owner
      Returns:
      true if token has been released false otherwise
    • requestWidgetToken

      public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority)
      Description copied from interface: IWidgetTokenKeeperExtension
      The given widget token owner requests the widget token from this token keeper. Returns true if the token is released by this token keeper. Note, the keeper must not call releaseWidgetToken(IWidgetTokenKeeper) explicitly.

      The general contract is that the receiver should release the token if priority exceeds the receiver's priority.

      Specified by:
      requestWidgetToken in interface IWidgetTokenKeeperExtension
      Parameters:
      owner - the token owner
      priority - the priority of the request
      Returns:
      true if token has been released false otherwise
    • setFocus

      public boolean setFocus(IWidgetTokenOwner owner)
      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 interface IWidgetTokenKeeperExtension
      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

      public 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.

      Note: This API is only valid if the information control implements IInformationControlExtension3. Not following this restriction will later result in an UnsupportedOperationException.

      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

      protected Point restoreCompletionProposalPopupSize()
      Restores the content assist's proposal pop-up size.
      Returns:
      the stored size or null if none
      Since:
      3.0
    • restoreContextSelectorPopupSize

      protected Point 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

      public void addCompletionListener(ICompletionListener listener)
      Description copied from interface: IContentAssistantExtension2
      Adds a completion listener that will be informed before proposals are computed.
      Specified by:
      addCompletionListener in interface IContentAssistantExtension2
      Parameters:
      listener - the listener
    • removeCompletionListener

      public void removeCompletionListener(ICompletionListener listener)
      Description copied from interface: IContentAssistantExtension2
      Removes a completion listener.
      Specified by:
      removeCompletionListener in interface IContentAssistantExtension2
      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 no false.
      Specified by:
      setRepeatedInvocationMode in interface IContentAssistantExtension2
      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 interface IContentAssistantExtension2
      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 via IContentAssistantExtension2.setStatusMessage(String).
      Specified by:
      setStatusLineVisible in interface IContentAssistantExtension2
      Parameters:
      show - true to show a message line, false to not show one.
    • setStatusMessage

      public void setStatusMessage(String message)
      Description copied from interface: IContentAssistantExtension2
      Sets the caption message displayed at the bottom of the completion proposal popup.
      Specified by:
      setStatusMessage in interface IContentAssistantExtension2
      Parameters:
      message - the message
    • setEmptyMessage

      public void setEmptyMessage(String message)
      Description copied from interface: IContentAssistantExtension2
      Sets the text to be shown if no proposals are available and empty lists are displayed.
      Specified by:
      setEmptyMessage in interface IContentAssistantExtension2
      Parameters:
      message - the text for the empty list
    • setRepeatedInvocationTrigger

      public void setRepeatedInvocationTrigger(KeySequence sequence)
      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 interface IContentAssistantExtension3
      Parameters:
      sequence - the key sequence used for the repeated invocation mode or null 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

      public final IHandler getHandler(String commandId)
      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 interface IContentAssistantExtension4
      Parameters:
      commandId - the command identifier
      Returns:
      the handler for the given command identifier
      Since:
      3.4
    • registerHandler

      protected final void registerHandler(String commandId, IHandler handler)
      Registers the given handler under the given command identifier.
      Parameters:
      commandId - the command identifier
      handler - 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 - if true the support for colored labels is enabled in the proposal popup
      Since:
      3.4
    • setSorter

      public void setSorter(ICompletionProposalSorter sorter)
      Sets the proposal sorter.
      Parameters:
      sorter - the sorter to be used, or null 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 with fAsynchronous
      Parameters:
      enable - whether or not to enable this feature
      Since:
      3.21