comparison dwtx/jface/text/contentassist/CompletionProposal.d @ 129:eb30df5ca28b

Added JFace Text sources
author Frank Benoit <benoit@tionex.de>
date Sat, 23 Aug 2008 19:10:48 +0200
parents
children c4fb132a086c
comparison
equal deleted inserted replaced
128:8df1d4193877 129:eb30df5ca28b
1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module dwtx.jface.text.contentassist.CompletionProposal;
14
15 import dwt.dwthelper.utils;
16
17
18
19
20 import dwt.graphics.Image;
21 import dwt.graphics.Point;
22 import dwtx.core.runtime.Assert;
23 import dwtx.jface.text.BadLocationException;
24 import dwtx.jface.text.IDocument;
25
26
27 /**
28 * The standard implementation of the <code>ICompletionProposal</code> interface.
29 */
30 public final class CompletionProposal : ICompletionProposal {
31
32 /** The string to be displayed in the completion proposal popup. */
33 private String fDisplayString;
34 /** The replacement string. */
35 private String fReplacementString;
36 /** The replacement offset. */
37 private int fReplacementOffset;
38 /** The replacement length. */
39 private int fReplacementLength;
40 /** The cursor position after this proposal has been applied. */
41 private int fCursorPosition;
42 /** The image to be displayed in the completion proposal popup. */
43 private Image fImage;
44 /** The context information of this proposal. */
45 private IContextInformation fContextInformation;
46 /** The additional info of this proposal. */
47 private String fAdditionalProposalInfo;
48
49 /**
50 * Creates a new completion proposal based on the provided information. The replacement string is
51 * considered being the display string too. All remaining fields are set to <code>null</code>.
52 *
53 * @param replacementString the actual string to be inserted into the document
54 * @param replacementOffset the offset of the text to be replaced
55 * @param replacementLength the length of the text to be replaced
56 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
57 */
58 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition) {
59 this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null);
60 }
61
62 /**
63 * Creates a new completion proposal. All fields are initialized based on the provided information.
64 *
65 * @param replacementString the actual string to be inserted into the document
66 * @param replacementOffset the offset of the text to be replaced
67 * @param replacementLength the length of the text to be replaced
68 * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
69 * @param image the image to display for this proposal
70 * @param displayString the string to be displayed for the proposal
71 * @param contextInformation the context information associated with this proposal
72 * @param additionalProposalInfo the additional information associated with this proposal
73 */
74 public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
75 Assert.isNotNull(replacementString);
76 Assert.isTrue(replacementOffset >= 0);
77 Assert.isTrue(replacementLength >= 0);
78 Assert.isTrue(cursorPosition >= 0);
79
80 fReplacementString= replacementString;
81 fReplacementOffset= replacementOffset;
82 fReplacementLength= replacementLength;
83 fCursorPosition= cursorPosition;
84 fImage= image;
85 fDisplayString= displayString;
86 fContextInformation= contextInformation;
87 fAdditionalProposalInfo= additionalProposalInfo;
88 }
89
90 /*
91 * @see ICompletionProposal#apply(IDocument)
92 */
93 public void apply(IDocument document) {
94 try {
95 document.replace(fReplacementOffset, fReplacementLength, fReplacementString);
96 } catch (BadLocationException x) {
97 // ignore
98 }
99 }
100
101 /*
102 * @see ICompletionProposal#getSelection(IDocument)
103 */
104 public Point getSelection(IDocument document) {
105 return new Point(fReplacementOffset + fCursorPosition, 0);
106 }
107
108 /*
109 * @see ICompletionProposal#getContextInformation()
110 */
111 public IContextInformation getContextInformation() {
112 return fContextInformation;
113 }
114
115 /*
116 * @see ICompletionProposal#getImage()
117 */
118 public Image getImage() {
119 return fImage;
120 }
121
122 /*
123 * @see ICompletionProposal#getDisplayString()
124 */
125 public String getDisplayString() {
126 if (fDisplayString !is null)
127 return fDisplayString;
128 return fReplacementString;
129 }
130
131 /*
132 * @see ICompletionProposal#getAdditionalProposalInfo()
133 */
134 public String getAdditionalProposalInfo() {
135 return fAdditionalProposalInfo;
136 }
137 }