* @since 2.1
*/
private void insertProposal(ICompletionProposal p, char trigger, int stateMask, final int offset) {
inserting= true;
IRewriteTarget target= null;
IEditingSupport helper= new IEditingSupport() {
public boolean isOriginator(DocumentEvent event, IRegion focus) {
return focus.getOffset() <= offset && focus.getOffset() + focus.getLength() >= offset;
}
public boolean ownsFocusShell() {
return false;
}
};
try {
IDocument document= contentAssistSubjectControlAdapter.getDocument();
if (viewer instanceof ITextViewerExtension) {
ITextViewerExtension extension= (ITextViewerExtension) viewer;
target= extension.getRewriteTarget();
}
if (target != null)
target.beginCompoundChange();
if (viewer instanceof IEditingSupportRegistry) {
IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
registry.register(helper);
}
if (p instanceof ICompletionProposalExtension2 && viewer != null) {
ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
e.apply(viewer, trigger, stateMask, offset);
} else if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e= (ICompletionProposalExtension) p;
e.apply(document, trigger, offset);
} else {
p.apply(document);
}
fireAppliedEvent(p);
TextSelection selection= p.getSelection(document);
if (selection != null) {
contentAssistSubjectControlAdapter.setSelectedRange(selection.offset, selection.length);
contentAssistSubjectControlAdapter.revealRange(selection.offset, selection.length);
}
IContextInformation info= p.getContextInformation();
if (info != null) {
int contextInformationOffset;
if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e= (ICompletionProposalExtension) p;
contextInformationOffset= e.getContextInformationPosition();
} else {
if (selection == null)
selection= contentAssistSubjectControlAdapter.getSelectedRange();
contextInformationOffset= selection.offset + selection.length;
}
contentAssistant.showContextInformation(info, contextInformationOffset);
} else
contentAssistant.showContextInformation(null, -1);
} finally {
if (target != null)
target.endCompoundChange();
if (viewer instanceof IEditingSupportRegistry) {
IEditingSupportRegistry registry= (IEditingSupportRegistry) viewer;
registry.unregister(helper);
}