Search in sources :

Example 6 with IContextInformation

use of org.eclipse.jface.text.contentassist.IContextInformation 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 IContextInformation

use of org.eclipse.jface.text.contentassist.IContextInformation in project eclipse.platform.text by eclipse.

the class ContentAssistant2 method computeContextInformation.

/**
 * Returns an array of context information objects computed based
 * on the specified document position. The position is used to determine
 * the appropriate content assist processor to invoke.
 *
 * @param viewer the viewer for which to compute the context information
 * @param position a document position
 * @return an array of context information objects
 *
 * @see IContentAssistProcessor#computeContextInformation
 */
IContextInformation[] computeContextInformation(ITextViewer viewer, int position) {
    fLastErrorMessage = null;
    IContextInformation[] result = null;
    IContentAssistProcessor p = getProcessor(viewer, position);
    if (p != null) {
        result = p.computeContextInformation(viewer, position);
        fLastErrorMessage = p.getErrorMessage();
    }
    return result;
}
Also used : IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation)

Aggregations

IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)7 IDocument (org.eclipse.jface.text.IDocument)3 ContextInformation (org.eclipse.jface.text.contentassist.ContextInformation)3 BadLocationException (org.eclipse.jface.text.BadLocationException)2 LinkedList (java.util.LinkedList)1 IEditingSupportRegistry (org.eclipse.jface.text.IEditingSupportRegistry)1 IRegion (org.eclipse.jface.text.IRegion)1 IRewriteTarget (org.eclipse.jface.text.IRewriteTarget)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)1 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)1 ICompletionProposalExtension (org.eclipse.jface.text.contentassist.ICompletionProposalExtension)1 ICompletionProposalExtension2 (org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)1 IContentAssistProcessor (org.eclipse.jface.text.contentassist.IContentAssistProcessor)1 IContextInformationValidator (org.eclipse.jface.text.contentassist.IContextInformationValidator)1 Point (org.eclipse.swt.graphics.Point)1 TableItem (org.eclipse.swt.widgets.TableItem)1