org.eclipse.jface.text.link.ProposalPosition Java Examples

The following examples show how to use org.eclipse.jface.text.link.ProposalPosition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AssistAssignCompletionProposal.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void apply(IDocument document) {
    try {
        //default apply
        int lineOfOffset = document.getLineOfOffset(fReplacementOffset);
        document.replace(fReplacementOffset, fReplacementLength, fReplacementString);

        if (SharedCorePlugin.inTestMode()) {
            return;
        }
        int lineOffset = document.getLineOffset(lineOfOffset);
        int lineLength = document.getLineLength(lineOfOffset);
        String lineDelimiter = document.getLineDelimiter(lineOfOffset);
        int lineDelimiterLen = lineDelimiter != null ? lineDelimiter.length() : 0;

        ISourceViewer viewer = sourceViewer;

        LinkedModeModel model = new LinkedModeModel();
        LinkedPositionGroup group = new LinkedPositionGroup();

        //the len-3 is because of the end of the string: " = " because the replacement string is
        //something like "xxx = "
        ProposalPosition proposalPosition = new ProposalPosition(document, fReplacementOffset,
                fReplacementString.length() - 3, 0, new ICompletionProposal[0]);
        group.addPosition(proposalPosition);

        model.addGroup(group);
        model.forceInstall();

        final LinkedModeUI ui = new EditorLinkedModeUI(model, viewer);
        ui.setExitPosition(viewer, lineOffset + lineLength - lineDelimiterLen, 0, Integer.MAX_VALUE);
        Runnable r = new Runnable() {
            @Override
            public void run() {
                ui.enter();
            }
        };
        RunInUiThread.async(r);

    } catch (Throwable x) {
        // ignore
        Log.log(x);
    }
}