Search in sources :

Example 1 with IContextInformation

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

the class BundleClassCompletionProposalComputer method computeContextInformation.

public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<IContextInformation> result = new LinkedList<IContextInformation>();
    result.add(new ContextInformation("contextDisplayString", "informationDisplayString"));
    return result;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) LinkedList(java.util.LinkedList)

Example 2 with IContextInformation

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

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

the class BarContentAssistProcessor method computeContextInformation.

/**
 * Creates context info "idx= <word index in #PROPOSAL>" at the end of a word.
 */
@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
    try {
        IDocument document = viewer.getDocument();
        int begin = offset;
        while (begin > 0 && Character.isLetterOrDigit(document.getChar(begin - 1))) {
            begin--;
        }
        if (begin < offset) {
            String word = document.get(begin, offset - begin);
            int idx = Arrays.asList(completeString.split("\\W")).indexOf(word);
            if (idx >= 0) {
                return new IContextInformation[] { new ContextInformation(word, "idx= " + idx) };
            }
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 4 with IContextInformation

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

the class ContextInformationPopup2 method setContexts.

/**
 * Sets the contexts in the context selector to the given set.
 *
 * @param contexts the possible contexts
 */
private void setContexts(IContextInformation[] contexts) {
    if (Helper2.okToUse(fContextSelectorTable)) {
        fContextSelectorInput = contexts;
        fContextSelectorTable.setRedraw(false);
        fContextSelectorTable.removeAll();
        TableItem item;
        IContextInformation t;
        for (IContextInformation context : contexts) {
            t = context;
            item = new TableItem(fContextSelectorTable, SWT.NULL);
            if (t.getImage() != null)
                item.setImage(t.getImage());
            item.setText(t.getContextDisplayString());
        }
        fContextSelectorTable.select(0);
        fContextSelectorTable.setRedraw(true);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation)

Example 5 with IContextInformation

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

the class JavaCompletionProcessor method computeCompletionProposals.

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
    ICompletionProposal[] result = new ICompletionProposal[fgProposals.length];
    for (int i = 0; i < fgProposals.length; i++) {
        // $NON-NLS-1$
        IContextInformation info = new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] }));
        // $NON-NLS-1$
        result[i] = new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i] }));
    }
    return result;
}
Also used : IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) 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