Search in sources :

Example 6 with ICompletionProposalExtension2

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;
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) IEditingSupportRegistry(org.eclipse.jface.text.IEditingSupportRegistry) ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point)

Example 7 with ICompletionProposalExtension2

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());
}
Also used : ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) IDocument(org.eclipse.jface.text.IDocument)

Example 8 with ICompletionProposalExtension2

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());
}
Also used : ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with ICompletionProposalExtension2

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Aggregations

ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)9 IDocument (org.eclipse.jface.text.IDocument)7 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)5 Point (org.eclipse.swt.graphics.Point)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)3 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)2 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)2 ArrayList (java.util.ArrayList)1 IFile (org.eclipse.core.resources.IFile)1 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)1 ICompletionProposalExtension6 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension6)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 StyledString (org.eclipse.jface.viewers.StyledString)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 StyledText (org.eclipse.swt.custom.StyledText)1 TableItem (org.eclipse.swt.widgets.TableItem)1 StructuredTextEditor (org.eclipse.wst.sse.ui.StructuredTextEditor)1 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)1