Search in sources :

Example 1 with IContextInformationValidator

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

the class BarContentAssistProcessor method getContextInformationValidator.

@Override
public IContextInformationValidator getContextInformationValidator() {
    return new IContextInformationValidator() {

        ITextViewer viewer;

        int offset;

        @Override
        public void install(IContextInformation info, ITextViewer viewer, int offset) {
            this.viewer = viewer;
            this.offset = offset;
        }

        @Override
        public boolean isContextInformationValid(int offset) {
            try {
                IDocument document = viewer.getDocument();
                IRegion line = document.getLineInformationOfOffset(this.offset);
                int end = line.getOffset() + line.getLength();
                return (offset >= this.offset && offset < end);
            } catch (BadLocationException e) {
                return false;
            }
        }
    };
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) IContextInformationValidator(org.eclipse.jface.text.contentassist.IContextInformationValidator) IDocument(org.eclipse.jface.text.IDocument) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 2 with IContextInformationValidator

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

the class ContextInformationPopup2 method internalShowContextInfo.

/**
 * Displays the given context information for the given offset.
 *
 * @param information the context information
 * @param offset the offset
 * @since 2.0
 */
private void internalShowContextInfo(IContextInformation information, int offset) {
    IContextInformationValidator validator = fContentAssistant.getContextInformationValidator(fViewer, offset);
    if (validator != null) {
        ContextFrame current = new ContextFrame();
        current.fInformation = information;
        current.fBeginOffset = (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information).getContextInformationPosition() : offset;
        if (current.fBeginOffset == -1)
            current.fBeginOffset = offset;
        current.fOffset = offset;
        current.fVisibleOffset = fViewer.getTextWidget().getSelectionRange().x - (offset - current.fBeginOffset);
        current.fValidator = validator;
        current.fPresenter = fContentAssistant.getContextInformationPresenter(fViewer, offset);
        fContextFrameStack.push(current);
        internalShowContextFrame(current, fContextFrameStack.size() == 1);
    }
}
Also used : IContextInformationValidator(org.eclipse.jface.text.contentassist.IContextInformationValidator) IContextInformationExtension(org.eclipse.jface.text.contentassist.IContextInformationExtension)

Aggregations

IContextInformationValidator (org.eclipse.jface.text.contentassist.IContextInformationValidator)2 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 IRegion (org.eclipse.jface.text.IRegion)1 ITextViewer (org.eclipse.jface.text.ITextViewer)1 IContextInformation (org.eclipse.jface.text.contentassist.IContextInformation)1 IContextInformationExtension (org.eclipse.jface.text.contentassist.IContextInformationExtension)1