*/
private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {
fInserting= true;
IRewriteTarget target= null;
IEditingSupportRegistry registry= null;
try {
IDocument document= fViewer.getDocument();
if (fViewer instanceof ITextViewerExtension) {
ITextViewerExtension extension= (ITextViewerExtension) fViewer;
target= extension.getRewriteTarget();
}
if (target != null)
target.beginCompoundChange();
if (fViewer instanceof IEditingSupportRegistry) {
registry= (IEditingSupportRegistry) fViewer;
registry.register(fModificationEditingSupport);
}
if (p instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
e.apply(fViewer, trigger, stateMask, offset);
} else if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e= (ICompletionProposalExtension) p;
e.apply(document, trigger, offset);
} else {
p.apply(document);
}
Point selection= p.getSelection(document);
if (selection != null) {
fViewer.setSelectedRange(selection.x, selection.y);
fViewer.revealRange(selection.x, selection.y);
}
IContextInformation info= p.getContextInformation();
if (info != null) {
int position;
if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e= (ICompletionProposalExtension) p;
position= e.getContextInformationPosition();
} else {
if (selection == null)
selection= fViewer.getSelectedRange();
position= selection.x + selection.y;
}
fContentAssistant.showContextInformation(info, position);
}
fContentAssistant.fireProposalChosen(p);
} finally {
if (target != null)
target.endCompoundChange();
if (registry != null)
registry.unregister(fModificationEditingSupport);
fInserting= false;
}
}