public class TemplateProposal extends Object implements ICompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3
Clients may subclass.
Constructor and Description |
---|
TemplateProposal(Template template,
TemplateContext context,
IRegion region,
Image image)
Creates a template proposal with a template and its context.
|
TemplateProposal(Template template,
TemplateContext context,
IRegion region,
Image image,
int relevance)
Creates a template proposal with a template and its context.
|
Modifier and Type | Method and Description |
---|---|
void |
apply(IDocument document)
Deprecated.
This method is no longer called by the framework and clients should overwrite
apply(ITextViewer, char, int, int) instead |
void |
apply(IDocument document,
char trigger,
int offset)
Deprecated.
This method is no longer called by the framework and clients should overwrite
apply(ITextViewer, char, int, int) instead |
void |
apply(ITextViewer viewer,
char trigger,
int stateMask,
int offset)
Inserts the template offered by this proposal into the viewer's document
and sets up a
LinkedModeUI on the viewer to edit any of
the template's unresolved variables. |
String |
getAdditionalProposalInfo()
Returns optional additional information about the proposal.
|
protected TemplateContext |
getContext()
Returns the context in which the template was requested.
|
IContextInformation |
getContextInformation()
Returns optional context information associated with this proposal.
|
int |
getContextInformationPosition()
Returns the position to which the computed context information refers to or
-1 if no context information can be provided by this completion proposal. |
String |
getDisplayString()
Returns the string to be displayed in the list of completion proposals.
|
Image |
getImage()
Returns the image to be displayed in the list of completion proposals.
|
IInformationControlCreator |
getInformationControlCreator()
Returns the information control creator of this completion proposal.
|
int |
getPrefixCompletionStart(IDocument document,
int completionOffset)
Returns the document offset at which the receiver would insert its
proposal.
|
CharSequence |
getPrefixCompletionText(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 |
getRelevance()
Returns the relevance.
|
protected int |
getReplaceEndOffset()
Returns the end offset of the range in the document that will be replaced
by applying this template.
|
protected int |
getReplaceOffset()
Returns the offset of the range in the document that will be replaced by
applying this template.
|
Point |
getSelection(IDocument document)
Returns the new selection after the proposal has been applied to
the given document in absolute document coordinates.
|
protected Template |
getTemplate()
Returns the template of this proposal.
|
char[] |
getTriggerCharacters()
Returns the characters which trigger the application of this completion proposal.
|
boolean |
isValidFor(IDocument document,
int offset)
Returns whether this completion proposal is valid for the given
position in the given document.
|
void |
selected(ITextViewer viewer,
boolean smartToggle)
Called when the proposal is selected.
|
void |
setInformationControlCreator(IInformationControlCreator informationControlCreator)
Sets the information control creator for this completion proposal.
|
void |
unselected(ITextViewer viewer)
Called when the proposal is unselected.
|
boolean |
validate(IDocument document,
int offset,
DocumentEvent event)
Requests the proposal to be validated with respect to the document event.
|
public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image)
template
- the templatecontext
- the context in which the template was requested.region
- the region this proposal is applied toimage
- the icon of the proposal.public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance)
template
- the templatecontext
- the context in which the template was requested.image
- the icon of the proposal.region
- the region this proposal is applied torelevance
- the relevance of the proposalpublic final void setInformationControlCreator(IInformationControlCreator informationControlCreator)
informationControlCreator
- the information control creatorprotected final Template getTemplate()
protected final TemplateContext getContext()
public final void apply(IDocument document)
apply(ITextViewer, char, int, int)
insteadapply
in interface ICompletionProposal
document
- the document into which to insert the proposed completionpublic void apply(ITextViewer viewer, char trigger, int stateMask, int offset)
LinkedModeUI
on the viewer to edit any of
the template's unresolved variables.apply
in interface ICompletionProposalExtension2
viewer
- the text viewer into which to insert the proposed completiontrigger
- the trigger to apply the completionstateMask
- the state mask of the modifiersoffset
- the offset at which the trigger has been activatedprotected final int getReplaceOffset()
protected final int getReplaceEndOffset()
public Point getSelection(IDocument document)
ICompletionProposal
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)
.getSelection
in interface ICompletionProposal
document
- the document into which the proposed completion has been insertedpublic String getAdditionalProposalInfo()
ICompletionProposal
If ICompletionProposalExtension5
is implemented, this method should not be called any
longer. This method may be deprecated in a future release.
getAdditionalProposalInfo
in interface ICompletionProposal
null
public String getDisplayString()
ICompletionProposal
getDisplayString
in interface ICompletionProposal
ICompletionProposalExtension6.getStyledDisplayString()
public Image getImage()
ICompletionProposal
getImage
in interface ICompletionProposal
null
if no image is desiredpublic IContextInformation getContextInformation()
ICompletionProposal
getContextInformation
in interface ICompletionProposal
null
public int getRelevance()
public IInformationControlCreator getInformationControlCreator()
ICompletionProposalExtension3
getInformationControlCreator
in interface ICompletionProposalExtension3
null
if no custom control creator is availablepublic void selected(ITextViewer viewer, boolean smartToggle)
ICompletionProposalExtension2
selected
in interface ICompletionProposalExtension2
viewer
- the text viewer.smartToggle
- the smart toggle key was pressedpublic void unselected(ITextViewer viewer)
ICompletionProposalExtension2
unselected
in interface ICompletionProposalExtension2
viewer
- the text viewer.public boolean validate(IDocument document, int offset, DocumentEvent event)
ICompletionProposalExtension2
false
.
If the document event was null
, only the caret offset was changed, but not the document.
This method replaces ICompletionProposalExtension.isValidFor(IDocument, int)
validate
in interface ICompletionProposalExtension2
document
- the documentoffset
- the caret offsetevent
- the document event, may be null
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset)
ICompletionProposalExtension3
ICompletionProposalExtension3.getPrefixCompletionStart(IDocument, int)
if this proposal was
applied. If the replacement string cannot be determined,
null
may be returned.getPrefixCompletionText
in interface ICompletionProposalExtension3
document
- the document that the receiver applies tocompletionOffset
- the offset into document
where the
completion takes placenull
if it cannot be
determinedpublic int getPrefixCompletionStart(IDocument document, int completionOffset)
ICompletionProposalExtension3
getPrefixCompletionStart
in interface ICompletionProposalExtension3
document
- the document that the receiver applies tocompletionOffset
- the offset into document
where the
completion takes placepublic void apply(IDocument document, char trigger, int offset)
apply(ITextViewer, char, int, int)
insteadICompletionProposalExtension.isValidFor(IDocument, int)
returns
true
if called for offset
.apply
in interface ICompletionProposalExtension
document
- the document into which to insert the proposed completiontrigger
- the trigger to apply the completionoffset
- the offset at which the trigger has been activatedpublic boolean isValidFor(IDocument document, int offset)
ICompletionProposalExtension
isValidFor
in interface ICompletionProposalExtension
document
- the document for which the proposal is testedoffset
- the offset for which the proposal is testedtrue
iff validpublic char[] getTriggerCharacters()
ICompletionProposalExtension
getTriggerCharacters
in interface ICompletionProposalExtension
null
if no completion other than the new line character is possiblepublic int getContextInformationPosition()
ICompletionProposalExtension
-1
if no context information can be provided by this completion proposal.getContextInformationPosition
in interface ICompletionProposalExtension
-1
for no information
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.