org.eclipse.xtext.ui.editor.contentassist
Class ConfigurableCompletionProposal

java.lang.Object
  extended by org.eclipse.xtext.ui.editor.contentassist.ConfigurableCompletionProposal
All Implemented Interfaces:
java.lang.Comparable<ConfigurableCompletionProposal>, org.eclipse.jface.text.contentassist.ICompletionProposal, org.eclipse.jface.text.contentassist.ICompletionProposalExtension2, org.eclipse.jface.text.contentassist.ICompletionProposalExtension3, org.eclipse.jface.text.contentassist.ICompletionProposalExtension4, org.eclipse.jface.text.contentassist.ICompletionProposalExtension5, org.eclipse.jface.text.contentassist.ICompletionProposalExtension6

public class ConfigurableCompletionProposal
extends java.lang.Object
implements java.lang.Comparable<ConfigurableCompletionProposal>, org.eclipse.jface.text.contentassist.ICompletionProposal, org.eclipse.jface.text.contentassist.ICompletionProposalExtension2, org.eclipse.jface.text.contentassist.ICompletionProposalExtension3, org.eclipse.jface.text.contentassist.ICompletionProposalExtension4, org.eclipse.jface.text.contentassist.ICompletionProposalExtension5, org.eclipse.jface.text.contentassist.ICompletionProposalExtension6

Author:
Sebastian Zarnekow - Initial contribution and API, Michael Clay, Christoph Kulla - Added support for hovers

Nested Class Summary
protected static class ConfigurableCompletionProposal.ExitPolicy
           
static interface ConfigurableCompletionProposal.IReplacementTextApplier
           
 
Constructor Summary
ConfigurableCompletionProposal(java.lang.String replacementString, int replacementOffset, int replacementLength, int cursorPosition)
          Creates a new completion proposal based on the provided information.
ConfigurableCompletionProposal(java.lang.String replacementString, int replacementOffset, int replacementLength, int cursorPosition, org.eclipse.swt.graphics.Image image, org.eclipse.jface.viewers.StyledString displayString, org.eclipse.jface.text.contentassist.IContextInformation contextInformation, java.lang.String additionalProposalInfo)
          Creates a new completion proposal.
 
Method Summary
 void apply(org.eclipse.jface.text.IDocument document)
          Inserts the proposed completion into the given document.
 void apply(org.eclipse.jface.text.ITextViewer viewer, char trigger, int stateMask, int offset)
          Applies the proposed completion to the given document.
 int compareTo(ConfigurableCompletionProposal other)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.String getAdditionalProposalInfo()
          Returns optional additional information about the proposal.
 java.lang.Object getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor monitor)
          Returns additional information about the proposal.
 org.eclipse.jface.text.contentassist.IContextInformation getContextInformation()
          Returns optional context information associated with this proposal.
 int getCursorPosition()
           
 java.lang.String getDisplayString()
          Returns the string to be displayed in the list of completion proposals.
 org.eclipse.swt.graphics.Image getImage()
          Returns the image to be displayed in the list of completion proposals.
 org.eclipse.jface.text.IInformationControlCreator getInformationControlCreator()
          Returns the information control creator of this completion proposal.
 PrefixMatcher getMatcher()
           
 int getPrefixCompletionStart(org.eclipse.jface.text.IDocument document, int completionOffset)
          Returns the document offset at which the receiver would insert its proposal.
 java.lang.CharSequence getPrefixCompletionText(org.eclipse.jface.text.IDocument document, int completionOffset)
          Returns the string that would be inserted at the position returned from ICompletionProposalExtension3.getPrefixCompletionStart(IDocument, int) if this proposal was applied.
 int getPriority()
           
 int getReplaceContextLength()
           
 int getReplacementLength()
           
 int getReplacementOffset()
           
 java.lang.String getReplacementString()
           
 org.eclipse.swt.graphics.Point getSelection(org.eclipse.jface.text.IDocument document)
          Returns the new selection after the proposal has been applied to the given document in absolute document coordinates.
 int getSelectionLength()
           
 int getSelectionStart()
           
 org.eclipse.jface.viewers.StyledString getStyledDisplayString()
          Returns the styled string used to display this proposal in the list of completion proposals.
 ConfigurableCompletionProposal.IReplacementTextApplier getTextApplier()
           
 int hashCode()
           
 boolean isAutoInsertable()
          Returns true if the proposal may be automatically inserted, false otherwise.
 void selected(org.eclipse.jface.text.ITextViewer viewer, boolean smartToggle)
          Called when the proposal is selected.
 void setAdditionalProposalInfo(java.lang.Object additionalProposalInfo)
           
 void setAutoInsertable(boolean autoInsertable)
           
 void setContextInformation(org.eclipse.jface.text.contentassist.IContextInformation contextInformation)
           
 void setCursorPosition(int cursorPosition)
           
 void setDisplayString(java.lang.String displayString)
           
 void setDisplayString(org.eclipse.jface.viewers.StyledString displayString)
           
 void setHover(IEObjectHover hover)
           
 void setImage(org.eclipse.swt.graphics.Image image)
           
 void setMatcher(PrefixMatcher matcher)
           
 void setPriority(int priority)
           
 void setReplaceContextLength(int replaceContextLength)
           
 void setReplacementLength(int replacementLength)
           
 void setReplacementOffset(int replacementOffset)
           
 void setReplacementString(java.lang.String replacementString)
           
 void setSelectionLength(int selectionLength)
           
 void setSelectionStart(int selectionStart)
           
 void setSimpleLinkedMode(org.eclipse.jface.text.ITextViewer viewer, char... exitChars)
           
 void setTextApplier(ConfigurableCompletionProposal.IReplacementTextApplier textApplier)
           
protected  void setUpLinkedMode(org.eclipse.jface.text.IDocument document)
          Sets up a simple linked mode at getCursorPosition() and an exit policy that will exit the mode when closingCharacter is typed and an exit position at getCursorPosition() + 1.
 java.lang.String toString()
           
 void unselected(org.eclipse.jface.text.ITextViewer viewer)
          Called when the proposal is unselected.
 boolean validate(org.eclipse.jface.text.IDocument document, int offset, org.eclipse.jface.text.DocumentEvent event)
          Requests the proposal to be validated with respect to the document event.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConfigurableCompletionProposal

public ConfigurableCompletionProposal(java.lang.String replacementString,
                                      int replacementOffset,
                                      int replacementLength,
                                      int cursorPosition)
Creates a new completion proposal based on the provided information. The replacement string is considered being the display string too. All remaining fields are set to null.

Parameters:
replacementString - the actual string to be inserted into the document
replacementOffset - the offset of the text to be replaced
replacementLength - the length of the text to be replaced
cursorPosition - the position of the cursor following the insert relative to replacementOffset

ConfigurableCompletionProposal

public ConfigurableCompletionProposal(java.lang.String replacementString,
                                      int replacementOffset,
                                      int replacementLength,
                                      int cursorPosition,
                                      org.eclipse.swt.graphics.Image image,
                                      org.eclipse.jface.viewers.StyledString displayString,
                                      org.eclipse.jface.text.contentassist.IContextInformation contextInformation,
                                      java.lang.String additionalProposalInfo)
Creates a new completion proposal. All fields are initialized based on the provided information.

Parameters:
replacementString - the actual string to be inserted into the document
replacementOffset - the offset of the text to be replaced
replacementLength - the length of the text to be replaced
cursorPosition - the position of the cursor following the insert relative to replacementOffset
image - the image to display for this proposal
displayString - the string to be displayed for the proposal
contextInformation - the context information associated with this proposal
additionalProposalInfo - the additional information associated with this proposal
Method Detail

apply

public void apply(org.eclipse.jface.text.IDocument document)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Inserts the proposed completion into the given document.

Specified by:
apply in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Parameters:
document - the document into which to insert the proposed completion

getSelection

public org.eclipse.swt.graphics.Point getSelection(org.eclipse.jface.text.IDocument document)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Returns the new selection after the proposal has been applied to the given document in absolute document coordinates. If it returns null, no new selection is set. A document change can trigger other document changes, which have to be taken into account when calculating the new selection. Typically, this would be done by installing a document listener or by using a document position during ICompletionProposal.apply(IDocument).

Specified by:
getSelection in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Parameters:
document - the document into which the proposed completion has been inserted
Returns:
the new selection in absolute document coordinates

getContextInformation

public org.eclipse.jface.text.contentassist.IContextInformation getContextInformation()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Returns optional context information associated with this proposal. The context information will automatically be shown if the proposal has been applied.

Specified by:
getContextInformation in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Returns:
the context information for this proposal or null

getImage

public org.eclipse.swt.graphics.Image getImage()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Returns the image to be displayed in the list of completion proposals. The image would typically be shown to the left of the display string.

Specified by:
getImage in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Returns:
the image to be shown or null if no image is desired

getDisplayString

public java.lang.String getDisplayString()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Returns the string to be displayed in the list of completion proposals.

Specified by:
getDisplayString in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Returns:
the string to be displayed
See Also:
ICompletionProposalExtension6.getStyledDisplayString()

getStyledDisplayString

public org.eclipse.jface.viewers.StyledString getStyledDisplayString()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension6
Returns the styled string used to display this proposal in the list of completion proposals. This can for example be used to draw mixed colored labels.

Note: ICompletionProposal.getDisplayString() still needs to be correctly implemented as this method might be ignored in case of uninstalled owner draw support.

Specified by:
getStyledDisplayString in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension6
Returns:
the string builder used to display this proposal

getAdditionalProposalInfo

public java.lang.String getAdditionalProposalInfo()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposal
Returns optional additional information about the proposal. The additional information will be presented to assist the user in deciding if the selected proposal is the desired choice.

If ICompletionProposalExtension5 is implemented, this method should not be called any longer. This method may be deprecated in a future release.

Specified by:
getAdditionalProposalInfo in interface org.eclipse.jface.text.contentassist.ICompletionProposal
Returns:
the additional information or null

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isAutoInsertable

public boolean isAutoInsertable()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension4
Returns true if the proposal may be automatically inserted, false otherwise. Automatic insertion can happen if the proposal is the only one being proposed, in which case the content assistant may decide to not prompt the user with a list of proposals, but simply insert the single proposal. A proposal may veto this behavior by returning false to a call to this method.

Specified by:
isAutoInsertable in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension4
Returns:
true if the proposal may be inserted automatically, false if not

setAutoInsertable

public void setAutoInsertable(boolean autoInsertable)

getReplacementString

public java.lang.String getReplacementString()

getReplacementOffset

public int getReplacementOffset()

getReplacementLength

public int getReplacementLength()

getCursorPosition

public int getCursorPosition()

setDisplayString

public void setDisplayString(java.lang.String displayString)

setDisplayString

public void setDisplayString(org.eclipse.jface.viewers.StyledString displayString)

setReplacementString

public void setReplacementString(java.lang.String replacementString)

setReplacementOffset

public void setReplacementOffset(int replacementOffset)

setReplacementLength

public void setReplacementLength(int replacementLength)

setCursorPosition

public void setCursorPosition(int cursorPosition)

setImage

public void setImage(org.eclipse.swt.graphics.Image image)

setContextInformation

public void setContextInformation(org.eclipse.jface.text.contentassist.IContextInformation contextInformation)

setAdditionalProposalInfo

public void setAdditionalProposalInfo(java.lang.Object additionalProposalInfo)

getSelectionStart

public int getSelectionStart()

getSelectionLength

public int getSelectionLength()

setSelectionLength

public void setSelectionLength(int selectionLength)

setSelectionStart

public void setSelectionStart(int selectionStart)

setSimpleLinkedMode

public void setSimpleLinkedMode(org.eclipse.jface.text.ITextViewer viewer,
                                char... exitChars)

apply

public void apply(org.eclipse.jface.text.ITextViewer viewer,
                  char trigger,
                  int stateMask,
                  int offset)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Applies the proposed completion to the given document. The insertion has been triggered by entering the given character with a modifier at the given offset. This method assumes that ICompletionProposalExtension2.validate(IDocument, int, DocumentEvent) returns true if called for offset.

Specified by:
apply in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Parameters:
viewer - the text viewer into which to insert the proposed completion
trigger - the trigger to apply the completion
stateMask - the state mask of the modifiers
offset - the offset at which the trigger has been activated

selected

public void selected(org.eclipse.jface.text.ITextViewer viewer,
                     boolean smartToggle)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Called when the proposal is selected.

Specified by:
selected in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Parameters:
viewer - the text viewer.
smartToggle - the smart toggle key was pressed

unselected

public void unselected(org.eclipse.jface.text.ITextViewer viewer)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Called when the proposal is unselected.

Specified by:
unselected in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Parameters:
viewer - the text viewer.

validate

public boolean validate(org.eclipse.jface.text.IDocument document,
                        int offset,
                        org.eclipse.jface.text.DocumentEvent event)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Requests the proposal to be validated with respect to the document event. If the proposal cannot be validated, the methods returns false. If the document event was null, only the caret offset was changed, but not the document. This method replaces ICompletionProposalExtension.isValidFor(IDocument, int)

Specified by:
validate in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension2
Parameters:
document - the document
offset - the caret offset
event - the document event, may be null
Returns:
boolean

setMatcher

public void setMatcher(PrefixMatcher matcher)

getMatcher

public PrefixMatcher getMatcher()

setReplaceContextLength

public void setReplaceContextLength(int replaceContextLength)

getReplaceContextLength

public int getReplaceContextLength()

setPriority

public void setPriority(int priority)

getPriority

public int getPriority()

compareTo

public int compareTo(ConfigurableCompletionProposal other)
Specified by:
compareTo in interface java.lang.Comparable<ConfigurableCompletionProposal>

setUpLinkedMode

protected void setUpLinkedMode(org.eclipse.jface.text.IDocument document)
Sets up a simple linked mode at getCursorPosition() and an exit policy that will exit the mode when closingCharacter is typed and an exit position at getCursorPosition() + 1.

Parameters:
document - the document
closingCharacter - the exit character

setTextApplier

public void setTextApplier(ConfigurableCompletionProposal.IReplacementTextApplier textApplier)

getTextApplier

public ConfigurableCompletionProposal.IReplacementTextApplier getTextApplier()

getInformationControlCreator

public org.eclipse.jface.text.IInformationControlCreator getInformationControlCreator()
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Returns the information control creator of this completion proposal.

Specified by:
getInformationControlCreator in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Returns:
the information control creator, or null if no custom control creator is available

getPrefixCompletionText

public java.lang.CharSequence getPrefixCompletionText(org.eclipse.jface.text.IDocument document,
                                                      int completionOffset)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Returns the string that would be inserted at the position returned from ICompletionProposalExtension3.getPrefixCompletionStart(IDocument, int) if this proposal was applied. If the replacement string cannot be determined, null may be returned.

Specified by:
getPrefixCompletionText in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Parameters:
document - the document that the receiver applies to
completionOffset - the offset into document where the completion takes place
Returns:
the replacement string or null if it cannot be determined

getPrefixCompletionStart

public int getPrefixCompletionStart(org.eclipse.jface.text.IDocument document,
                                    int completionOffset)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Returns the document offset at which the receiver would insert its proposal.

Specified by:
getPrefixCompletionStart in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension3
Parameters:
document - the document that the receiver applies to
completionOffset - the offset into document where the completion takes place
Returns:
the offset at which the proposal would insert its proposal

setHover

public void setHover(IEObjectHover hover)

getAdditionalProposalInfo

public java.lang.Object getAdditionalProposalInfo(org.eclipse.core.runtime.IProgressMonitor monitor)
Description copied from interface: org.eclipse.jface.text.contentassist.ICompletionProposalExtension5
Returns additional information about the proposal. The additional information will be presented to assist the user in deciding if the selected proposal is the desired choice.

This method may be called on a non-UI thread.

By default, the returned information is converted to a string and displayed as text; if ICompletionProposalExtension3.getInformationControlCreator() is implemented, the information will be passed to a custom information control for display.

Specified by:
getAdditionalProposalInfo in interface org.eclipse.jface.text.contentassist.ICompletionProposalExtension5
Parameters:
monitor - a monitor to report progress and to watch for cancelation.
Returns:
the additional information, null for no information

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object