use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method insertProposal.
/**
* Applies the given proposal at the given offset. The given character is the
* one that triggered the insertion of this proposal.
*
* @param p the completion proposal
* @param trigger the trigger character
* @param stateMask the state mask of the keyboard event triggering the insertion
* @param offset the offset
* @since 2.1
*/
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;
}
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.
protected ContentAssistProcessorTestBuilder appendAndApplyProposal(ICompletionProposal proposal, ISourceViewer sourceViewer, String model, int position) throws Exception {
IDocument document = sourceViewer.getDocument();
int offset = position;
if (model != null) {
document.set(getModel() + model);
offset += model.length();
}
if (proposal instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 proposalExtension2 = (ICompletionProposalExtension2) proposal;
proposalExtension2.apply(sourceViewer, (char) 0, SWT.NONE, offset);
} else if (proposal instanceof ICompletionProposalExtension) {
ICompletionProposalExtension proposalExtension = (ICompletionProposalExtension) proposal;
proposalExtension.apply(document, (char) 0, offset);
} else {
proposal.apply(document);
}
return reset().append(document.get());
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project xtext-eclipse by eclipse.
the class ContentAssistProcessorTestBuilder method appendAndApplyProposal.
protected ContentAssistProcessorTestBuilder appendAndApplyProposal(ICompletionProposal proposal, ISourceViewer sourceViewer, String model, int position) throws Exception {
IDocument document = sourceViewer.getDocument();
int offset = position;
if (model != null) {
document.set(getModel() + model);
offset += model.length();
}
if (proposal instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 proposalExtension2 = (ICompletionProposalExtension2) proposal;
proposalExtension2.apply(sourceViewer, (char) 0, SWT.NONE, offset);
} else if (proposal instanceof ICompletionProposalExtension) {
ICompletionProposalExtension proposalExtension = (ICompletionProposalExtension) proposal;
proposalExtension.apply(document, (char) 0, offset);
} else {
proposal.apply(document);
}
return reset().append(document.get());
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project webtools.sourceediting by eclipse.
the class TestXMLContentAssistComputers method testXMLLinkedPositions.
public void testXMLLinkedPositions() throws Exception {
IFile file = getFile("test1.xml");
StructuredTextEditor editor = getEditor(file);
StructuredTextViewer viewer = editor.getTextViewer();
int offset = viewer.getDocument().getLineOffset(13);
ICompletionProposal[][] pages = getProposals(viewer, offset, 4);
assertNotNull("No proposals returned.", pages);
assertTrue("Not enough pages.", pages.length > 0);
assertTrue("Not enough proposals.", pages[0].length > 0);
ICompletionProposalExtension2 proposal = null;
// Check for the member proposal
for (int i = 0; i < pages[0].length; i++) {
if ("Member".equals(pages[0][i].getDisplayString())) {
assertTrue("Proposal not of the proper type", pages[0][i] instanceof ICompletionProposalExtension2);
proposal = (ICompletionProposalExtension2) pages[0][i];
break;
}
}
assertNotNull("No appropriate proposal found.", proposal);
proposal.apply(viewer, (char) 0, 0, offset);
String[] categories = viewer.getDocument().getPositionCategories();
String category = null;
for (int i = 0; i < categories.length; i++) {
if (categories[i].startsWith("org.eclipse.jface.text.link.LinkedModeModel")) {
category = categories[i];
}
}
assertNotNull("Could not find the linked model position category.", category);
assertTrue("No linked positions were generated.", viewer.getDocument().getPositions(category).length > 0);
}
Aggregations