Search in sources :

Example 1 with ICompletionProposalExtension2

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

the class CompletionProposalPopup2 method unregister.

private void unregister() {
    if (fDocumentListener != null) {
        IDocument document = fViewer.getDocument();
        if (document != null)
            document.removeDocumentListener(fDocumentListener);
        fDocumentListener = null;
    }
    fDocumentEvents.clear();
    StyledText styledText = fViewer.getTextWidget();
    if (fKeyListener != null && styledText != null && !styledText.isDisposed())
        styledText.removeKeyListener(fKeyListener);
    if (fLastProposal != null) {
        if (fLastProposal instanceof ICompletionProposalExtension2) {
            ICompletionProposalExtension2 extension = (ICompletionProposalExtension2) fLastProposal;
            extension.unselected(fViewer);
        }
        fLastProposal = null;
    }
    fFilteredProposals = null;
    fContentAssistant.possibleCompletionsClosed();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with ICompletionProposalExtension2

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

the class CompletionProposalPopup2 method computeFilteredProposals.

/**
 * Computes the subset of already computed propsals that are still valid for
 * the given offset.
 *
 * @param offset the offset
 * @param event the merged document event
 * @return the set of filtered proposals
 * @since 2.0
 */
private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event) {
    if (offset == fInvocationOffset && event == null)
        return fComputedProposals;
    if (offset < fInvocationOffset) {
        return null;
    }
    ICompletionProposal[] proposals = fComputedProposals;
    if (offset > fFilterOffset)
        proposals = fFilteredProposals;
    if (proposals == null)
        return null;
    IDocument document = fViewer.getDocument();
    int length = proposals.length;
    List<Object> filtered = new ArrayList<>(length);
    for (int i = 0; i < length; i++) {
        if (proposals[i] instanceof ICompletionProposalExtension2) {
            ICompletionProposalExtension2 p = (ICompletionProposalExtension2) proposals[i];
            if (p.validate(document, offset, event))
                filtered.add(p);
        } else if (proposals[i] instanceof ICompletionProposalExtension) {
            ICompletionProposalExtension p = (ICompletionProposalExtension) proposals[i];
            if (p.isValidFor(document, offset))
                filtered.add(p);
        } else {
            // restore original behavior
            fInvocationOffset = offset;
            fComputedProposals = computeProposals(fInvocationOffset);
            return fComputedProposals;
        }
    }
    ICompletionProposal[] p = new ICompletionProposal[filtered.size()];
    filtered.toArray(p);
    return p;
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point)

Example 3 with ICompletionProposalExtension2

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

the class CompletionProposalPopup2 method setProposals.

/**
 * Initializes the proposal selector with these given proposals.
 *
 * @param proposals the proposals
 */
private void setProposals(ICompletionProposal[] proposals) {
    if (Helper2.okToUse(fProposalTable)) {
        ICompletionProposal oldProposal = getSelectedProposal();
        if (oldProposal instanceof ICompletionProposalExtension2)
            ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
        fFilteredProposals = proposals;
        int selectionIndex = 0;
        fProposalTable.setRedraw(false);
        try {
            fProposalTable.removeAll();
            Point selection = fViewer.getSelectedRange();
            int endOffset;
            endOffset = selection.x + selection.y;
            IDocument document = fViewer.getDocument();
            boolean validate = false;
            if (selection.y != 0 && document != null)
                validate = true;
            TableItem item;
            ICompletionProposal p;
            for (int i = 0; i < proposals.length; i++) {
                p = proposals[i];
                item = new TableItem(fProposalTable, SWT.NULL);
                if (p.getImage() != null)
                    item.setImage(p.getImage());
                String displayString;
                StyleRange[] styleRanges = null;
                if (fIsColoredLabelsSupportEnabled && p instanceof ICompletionProposalExtension6) {
                    StyledString styledString = ((ICompletionProposalExtension6) p).getStyledDisplayString();
                    displayString = styledString.getString();
                    styleRanges = styledString.getStyleRanges();
                } else
                    displayString = p.getDisplayString();
                item.setText(displayString);
                if (fIsColoredLabelsSupportEnabled)
                    TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
                item.setData(p);
                if (validate && validateProposal(document, p, endOffset, null)) {
                    selectionIndex = i;
                    validate = false;
                }
            }
        } finally {
            fProposalTable.setRedraw(true);
        }
        resizeProposalSelector(false);
        selectProposal(selectionIndex, false);
    }
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) TableItem(org.eclipse.swt.widgets.TableItem) StyleRange(org.eclipse.swt.custom.StyleRange) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) Point(org.eclipse.swt.graphics.Point) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) ICompletionProposalExtension6(org.eclipse.jface.text.contentassist.ICompletionProposalExtension6)

Example 4 with ICompletionProposalExtension2

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

the class CompletionProposalPopup2 method selectProposal.

/**
 * Selects the entry with the given index in the proposal selector and feeds
 * the selection to the additional info controller.
 *
 * @param index the index in the list
 * @param smartToggle <code>true</code> if the smart toogle key has been pressed
 * @since 2.1
 */
private void selectProposal(int index, boolean smartToggle) {
    ICompletionProposal oldProposal = getSelectedProposal();
    if (oldProposal instanceof ICompletionProposalExtension2)
        ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
    ICompletionProposal proposal = fFilteredProposals[index];
    if (proposal instanceof ICompletionProposalExtension2)
        ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
    fLastProposal = proposal;
    fProposalTable.setSelection(index);
    fProposalTable.showSelection();
    if (fAdditionalInfoController != null)
        fAdditionalInfoController.handleTableSelectionChanged();
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2)

Example 5 with ICompletionProposalExtension2

use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project liferay-ide by liferay.

the class LiferayCustomXmlHoverControl method _apply.

private void _apply(ICompletionProposal p, ITextViewer viewer, int offset, boolean multiFix) {
    // Focus needs to be in the text viewer, otherwise linked mode does not
    // work
    dispose();
    IRewriteTarget target = null;
    try {
        IDocument document = viewer.getDocument();
        if (viewer instanceof ITextViewerExtension) {
            ITextViewerExtension extension = (ITextViewerExtension) viewer;
            target = extension.getRewriteTarget();
        }
        if (target != null) {
            target.beginCompoundChange();
        }
        if (p instanceof ICompletionProposalExtension2) {
            ICompletionProposalExtension2 e = (ICompletionProposalExtension2) p;
            e.apply(viewer, (char) 0, multiFix ? SWT.CONTROL : SWT.NONE, offset);
        } else if (p instanceof ICompletionProposalExtension) {
            ICompletionProposalExtension e = (ICompletionProposalExtension) p;
            e.apply(document, (char) 0, offset);
        } else {
            p.apply(document);
        }
        Point selection = p.getSelection(document);
        if (selection != null) {
            viewer.setSelectedRange(selection.x, selection.y);
            viewer.revealRange(selection.x, selection.y);
        }
    } catch (Exception e) {
    } finally {
        if (target != null) {
            target.endCompoundChange();
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ICompletionProposalExtension(org.eclipse.jface.text.contentassist.ICompletionProposalExtension) ICompletionProposalExtension2(org.eclipse.jface.text.contentassist.ICompletionProposalExtension2) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument)

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