Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 511e4a783e9bc9f67b7de5833f38b9cb51bdc2be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*******************************************************************************
 * Copyright (c) 2015, 2018 Open Analytics NV and others.
 * 
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.linuxtools.internal.docker.editor.assist;

import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;

/**
 * Based on {@link org.eclipse.jface.text.contentassist.CompletionProposal} with
 * added functionality for showing additional information formatted as HTML.
 */
public class CompletionProposal implements ICompletionProposal, ICompletionProposalExtension3 {

	private String fReplacementString;
	private int fReplacementOffset;
	private int fReplacementLength;

	private String fAdditionalProposalInfo;

	public CompletionProposal(String replacementString, int replacementOffset, int replacementLength,
			String additionalProposalInfo) {
		this.fReplacementString = replacementString;
		this.fReplacementOffset = replacementOffset;
		this.fReplacementLength = replacementLength;
		this.fAdditionalProposalInfo = additionalProposalInfo;
	}

	@Override
	public void apply(IDocument document) {
		try {
			document.replace(fReplacementOffset, fReplacementLength, fReplacementString);
		} catch (BadLocationException x) {
			// ignore
		}
	}

	@Override
	public Point getSelection(IDocument document) {
		return new Point(fReplacementOffset + fReplacementString.length(), 0);
	}

	@Override
	public String getDisplayString() {
		return fReplacementString;
	}

	@Override
	public String getAdditionalProposalInfo() {
		return fAdditionalProposalInfo;
	}

	@Override
	public IInformationControlCreator getInformationControlCreator() {
		return shell -> new DefaultInformationControl(shell, true);
	}

	@Override
	public IContextInformation getContextInformation() {
		return null;
	}

	@Override
	public Image getImage() {
		return null;
	}

	@Override
	public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
		return null;
	}

	@Override
	public int getPrefixCompletionStart(IDocument document, int completionOffset) {
		return 0;
	}

}

Back to the top