129
|
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.ContentAssistSubjectControlAdapter;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18
|
|
19
|
|
20
|
|
21 import dwt.custom.StyledText;
|
|
22 import dwt.custom.VerifyKeyListener;
|
|
23 import dwt.events.KeyListener;
|
|
24 import dwt.events.SelectionListener;
|
|
25 import dwt.graphics.Point;
|
|
26 import dwt.widgets.Control;
|
|
27 import dwtx.core.runtime.Assert;
|
|
28 import dwtx.jface.contentassist.IContentAssistSubjectControl;
|
|
29 import dwtx.jface.contentassist.ISubjectControlContextInformationPresenter;
|
|
30 import dwtx.jface.contentassist.ISubjectControlContextInformationValidator;
|
|
31 import dwtx.jface.text.IDocument;
|
|
32 import dwtx.jface.text.IEventConsumer;
|
|
33 import dwtx.jface.text.ITextViewer;
|
|
34 import dwtx.jface.text.ITextViewerExtension;
|
|
35 import dwtx.jface.text.contentassist.ContextInformationPopup.ContextFrame;
|
|
36
|
|
37
|
|
38 /**
|
|
39 * This content assist adapter delegates the calls either to
|
|
40 * a text viewer or to a content assist subject control.
|
|
41 *
|
|
42 * @since 3.0
|
|
43 */
|
|
44 final class ContentAssistSubjectControlAdapter : IContentAssistSubjectControl {
|
|
45
|
|
46 /**
|
|
47 * The text viewer which is used as content assist subject control.
|
|
48 */
|
|
49 private ITextViewer fViewer;
|
|
50
|
|
51 /**
|
|
52 * The content assist subject control.
|
|
53 */
|
|
54 private IContentAssistSubjectControl fContentAssistSubjectControl;
|
|
55
|
|
56
|
|
57 /**
|
|
58 * Creates an adapter for the given content assist subject control.
|
|
59 *
|
|
60 * @param contentAssistSubjectControl the content assist subject control
|
|
61 */
|
|
62 ContentAssistSubjectControlAdapter(IContentAssistSubjectControl contentAssistSubjectControl) {
|
|
63 Assert.isNotNull(contentAssistSubjectControl);
|
|
64 fContentAssistSubjectControl= contentAssistSubjectControl;
|
|
65 }
|
|
66
|
|
67 /**
|
|
68 * Creates an adapter for the given text viewer.
|
|
69 *
|
|
70 * @param viewer the text viewer
|
|
71 */
|
|
72 public ContentAssistSubjectControlAdapter(ITextViewer viewer) {
|
|
73 Assert.isNotNull(viewer);
|
|
74 fViewer= viewer;
|
|
75 }
|
|
76
|
|
77 /*
|
|
78 * @see IContentAssistSubjectControl#getLineHeight()
|
|
79 */
|
|
80 public int getLineHeight() {
|
|
81 if (fContentAssistSubjectControl !is null)
|
|
82 return fContentAssistSubjectControl.getLineHeight();
|
|
83
|
|
84 return fViewer.getTextWidget().getLineHeight(getCaretOffset());
|
|
85 }
|
|
86
|
|
87 /*
|
|
88 * @see IContentAssistSubjectControl#getControl()
|
|
89 */
|
|
90 public Control getControl() {
|
|
91 if (fContentAssistSubjectControl !is null)
|
|
92 return fContentAssistSubjectControl.getControl();
|
|
93 return fViewer.getTextWidget();
|
|
94 }
|
|
95
|
|
96 /*
|
|
97 * @see IContentAssistSubjectControl#getLocationAtOffset(int)
|
|
98 */
|
|
99 public Point getLocationAtOffset(int offset) {
|
|
100 if (fContentAssistSubjectControl !is null)
|
|
101 return fContentAssistSubjectControl.getLocationAtOffset(offset);
|
|
102 return fViewer.getTextWidget().getLocationAtOffset(offset);
|
|
103 }
|
|
104
|
|
105 /*
|
|
106 * @see IContentAssistSubjectControl#getWidgetSelectionRange()
|
|
107 */
|
|
108 public Point getWidgetSelectionRange() {
|
|
109 if (fContentAssistSubjectControl !is null)
|
|
110 return fContentAssistSubjectControl.getWidgetSelectionRange();
|
|
111 return fViewer.getTextWidget().getSelectionRange();
|
|
112 }
|
|
113
|
|
114 /*
|
|
115 * @see IContentAssistSubjectControl#getSelectedRange()
|
|
116 */
|
|
117 public Point getSelectedRange() {
|
|
118 if (fContentAssistSubjectControl !is null)
|
|
119 return fContentAssistSubjectControl.getSelectedRange();
|
|
120 return fViewer.getSelectedRange();
|
|
121 }
|
|
122
|
|
123 /*
|
|
124 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getCaretOffset()
|
|
125 */
|
|
126 public int getCaretOffset() {
|
|
127 if (fContentAssistSubjectControl !is null)
|
|
128 return fContentAssistSubjectControl.getCaretOffset();
|
|
129 return fViewer.getTextWidget().getCaretOffset();
|
|
130 }
|
|
131
|
|
132 /*
|
|
133 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getLineDelimiter()
|
|
134 */
|
|
135 public String getLineDelimiter() {
|
|
136 if (fContentAssistSubjectControl !is null)
|
|
137 return fContentAssistSubjectControl.getLineDelimiter();
|
|
138 return fViewer.getTextWidget().getLineDelimiter();
|
|
139 }
|
|
140
|
|
141 /*
|
|
142 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#addKeyListener(dwt.events.KeyListener)
|
|
143 */
|
|
144 public void addKeyListener(KeyListener keyListener) {
|
|
145 if (fContentAssistSubjectControl !is null)
|
|
146 fContentAssistSubjectControl.addKeyListener(keyListener);
|
|
147 else
|
|
148 fViewer.getTextWidget().addKeyListener(keyListener);
|
|
149 }
|
|
150
|
|
151 /*
|
|
152 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#removeKeyListener(dwt.events.KeyListener)
|
|
153 */
|
|
154 public void removeKeyListener(KeyListener keyListener) {
|
|
155 if (fContentAssistSubjectControl !is null)
|
|
156 fContentAssistSubjectControl.removeKeyListener(keyListener);
|
|
157 else
|
|
158 fViewer.getTextWidget().removeKeyListener(keyListener);
|
|
159 }
|
|
160
|
|
161 /*
|
|
162 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#getDocument()
|
|
163 */
|
|
164 public IDocument getDocument() {
|
|
165 if (fContentAssistSubjectControl !is null)
|
|
166 return fContentAssistSubjectControl.getDocument();
|
|
167 return fViewer.getDocument();
|
|
168 }
|
|
169
|
|
170 /*
|
|
171 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#prependVerifyKeyListener(VerifyKeyListener)
|
|
172 */
|
|
173 public bool prependVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
|
|
174 if (fContentAssistSubjectControl !is null) {
|
|
175 return fContentAssistSubjectControl.prependVerifyKeyListener(verifyKeyListener);
|
|
176 } else if (fViewer instanceof ITextViewerExtension) {
|
|
177 ITextViewerExtension e= (ITextViewerExtension) fViewer;
|
|
178 e.prependVerifyKeyListener(verifyKeyListener);
|
|
179 return true;
|
|
180 } else {
|
|
181
|
|
182 StyledText textWidget= fViewer.getTextWidget();
|
|
183 if (Helper.okToUse(textWidget)) {
|
|
184 textWidget.addVerifyKeyListener(verifyKeyListener);
|
|
185 return true;
|
|
186 }
|
|
187 }
|
|
188 return false;
|
|
189 }
|
|
190
|
|
191 /*
|
|
192 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#appendVerifyKeyListener(dwt.custom.VerifyKeyListener)
|
|
193 */
|
|
194 public bool appendVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
|
|
195 if (fContentAssistSubjectControl !is null)
|
|
196 return fContentAssistSubjectControl.appendVerifyKeyListener(verifyKeyListener);
|
|
197 else if (fViewer instanceof ITextViewerExtension) {
|
|
198 ITextViewerExtension extension= (ITextViewerExtension)fViewer;
|
|
199 extension.appendVerifyKeyListener(verifyKeyListener);
|
|
200 return true;
|
|
201 } else {
|
|
202 StyledText textWidget= fViewer.getTextWidget();
|
|
203 if (Helper.okToUse(textWidget)) {
|
|
204 textWidget.addVerifyKeyListener(verifyKeyListener);
|
|
205 return true;
|
|
206 }
|
|
207 }
|
|
208 return false;
|
|
209 }
|
|
210
|
|
211 /*
|
|
212 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#removeVerifyKeyListener(dwt.custom.VerifyKeyListener)
|
|
213 */
|
|
214 public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
|
|
215 if (fContentAssistSubjectControl !is null) {
|
|
216 fContentAssistSubjectControl.removeVerifyKeyListener(verifyKeyListener);
|
|
217 } else if (fViewer instanceof ITextViewerExtension) {
|
|
218 ITextViewerExtension extension= (ITextViewerExtension) fViewer;
|
|
219 extension.removeVerifyKeyListener(verifyKeyListener);
|
|
220 } else {
|
|
221 StyledText textWidget= fViewer.getTextWidget();
|
|
222 if (Helper.okToUse(textWidget))
|
|
223 textWidget.removeVerifyKeyListener(verifyKeyListener);
|
|
224 }
|
|
225 }
|
|
226
|
|
227 /*
|
|
228 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#setEventConsumer(dwtx.jface.text.contentassist.ContentAssistant.InternalListener)
|
|
229 */
|
|
230 public void setEventConsumer(IEventConsumer eventConsumer) {
|
|
231 if (fContentAssistSubjectControl !is null)
|
|
232 fContentAssistSubjectControl.setEventConsumer(eventConsumer);
|
|
233 else
|
|
234 fViewer.setEventConsumer(eventConsumer);
|
|
235 }
|
|
236
|
|
237 /*
|
|
238 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#setSelectedRange(int, int)
|
|
239 */
|
|
240 public void setSelectedRange(int i, int j) {
|
|
241 if (fContentAssistSubjectControl !is null)
|
|
242 fContentAssistSubjectControl.setSelectedRange(i, j);
|
|
243 else
|
|
244 fViewer.setSelectedRange(i, j);
|
|
245 }
|
|
246
|
|
247 /*
|
|
248 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#revealRange(int, int)
|
|
249 */
|
|
250 public void revealRange(int i, int j) {
|
|
251 if (fContentAssistSubjectControl !is null)
|
|
252 fContentAssistSubjectControl.revealRange(i, j);
|
|
253 else
|
|
254 fViewer.revealRange(i, j);
|
|
255 }
|
|
256
|
|
257 /*
|
|
258 * @see dwtx.jface.text.contentassist.IContentAssistSubjectControl#canAddVerifyKeyListener()
|
|
259 */
|
|
260 public bool supportsVerifyKeyListener() {
|
|
261 if (fContentAssistSubjectControl !is null)
|
|
262 return fContentAssistSubjectControl.supportsVerifyKeyListener();
|
|
263 return true;
|
|
264 }
|
|
265 /**
|
|
266 * Returns the characters which when typed by the user should automatically
|
|
267 * initiate proposing completions. The position is used to determine the
|
|
268 * appropriate content assist processor to invoke.
|
|
269 *
|
|
270 * @param contentAssistant the content assistant
|
|
271 * @param offset a document offset
|
|
272 * @return the auto activation characters
|
|
273 * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
|
|
274 */
|
|
275 public char[] getCompletionProposalAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
|
|
276 if (fContentAssistSubjectControl !is null)
|
|
277 return contentAssistant.getCompletionProposalAutoActivationCharacters(fContentAssistSubjectControl, offset);
|
|
278 return contentAssistant.getCompletionProposalAutoActivationCharacters(fViewer, offset);
|
|
279 }
|
|
280
|
|
281 /**
|
|
282 * Returns the characters which when typed by the user should automatically
|
|
283 * initiate the presentation of context information. The position is used
|
|
284 * to determine the appropriate content assist processor to invoke.
|
|
285 *
|
|
286 * @param contentAssistant the content assistant
|
|
287 * @param offset a document offset
|
|
288 * @return the auto activation characters
|
|
289 *
|
|
290 * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
|
|
291 */
|
|
292 char[] getContextInformationAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
|
|
293 if (fContentAssistSubjectControl !is null)
|
|
294 return contentAssistant.getContextInformationAutoActivationCharacters(fContentAssistSubjectControl, offset);
|
|
295 return contentAssistant.getContextInformationAutoActivationCharacters(fViewer, offset);
|
|
296 }
|
|
297
|
|
298 /**
|
|
299 * Creates and returns a completion proposal popup for the given content assistant.
|
|
300 *
|
|
301 * @param contentAssistant the content assistant
|
|
302 * @param controller the additional info controller
|
|
303 * @return the completion proposal popup
|
|
304 */
|
|
305 CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) {
|
|
306 if (fContentAssistSubjectControl !is null)
|
|
307 return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
|
|
308 return new CompletionProposalPopup(contentAssistant, fViewer, controller);
|
|
309
|
|
310 }
|
|
311
|
|
312 /**
|
|
313 * Creates and returns a context info popup for the given content assistant.
|
|
314 *
|
|
315 * @param contentAssistant the content assistant
|
|
316 * @return the context info popup or <code>null</code>
|
|
317 */
|
|
318 ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant) {
|
|
319 if (fContentAssistSubjectControl !is null)
|
|
320 return new ContextInformationPopup(contentAssistant, fContentAssistSubjectControl);
|
|
321 return new ContextInformationPopup(contentAssistant, fViewer);
|
|
322
|
|
323 }
|
|
324
|
|
325 /**
|
|
326 * Returns the context information validator that should be used to
|
|
327 * determine when the currently displayed context information should
|
|
328 * be dismissed. The position is used to determine the appropriate
|
|
329 * content assist processor to invoke.
|
|
330 *
|
|
331 * @param contentAssistant the content assistant
|
|
332 * @param offset a document offset
|
|
333 * @return an validator
|
|
334 */
|
|
335 public IContextInformationValidator getContextInformationValidator(ContentAssistant contentAssistant, int offset) {
|
|
336 if (fContentAssistSubjectControl !is null)
|
|
337 return contentAssistant.getContextInformationValidator(fContentAssistSubjectControl, offset);
|
|
338 return contentAssistant.getContextInformationValidator(fViewer, offset);
|
|
339 }
|
|
340
|
|
341 /**
|
|
342 * Returns the context information presenter that should be used to
|
|
343 * display context information. The position is used to determine the
|
|
344 * appropriate content assist processor to invoke.
|
|
345 *
|
|
346 * @param contentAssistant the content assistant
|
|
347 * @param offset a document offset
|
|
348 * @return a presenter
|
|
349 */
|
|
350 public IContextInformationPresenter getContextInformationPresenter(ContentAssistant contentAssistant, int offset) {
|
|
351 if (fContentAssistSubjectControl !is null)
|
|
352 return contentAssistant.getContextInformationPresenter(fContentAssistSubjectControl, offset);
|
|
353 return contentAssistant.getContextInformationPresenter(fViewer, offset);
|
|
354 }
|
|
355
|
|
356 /**
|
|
357 * Installs this adapter's information validator on the given context frame.
|
|
358 *
|
|
359 * @param frame the context frame
|
|
360 */
|
|
361 public void installValidator(ContextFrame frame) {
|
|
362 if (fContentAssistSubjectControl !is null) {
|
|
363 if (frame.fValidator instanceof ISubjectControlContextInformationValidator)
|
|
364 ((ISubjectControlContextInformationValidator)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fOffset);
|
|
365 } else
|
|
366 frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset);
|
|
367 }
|
|
368
|
|
369 /**
|
|
370 * Installs this adapter's information presenter on the given context frame.
|
|
371 *
|
|
372 * @param frame the context frame
|
|
373 */
|
|
374 public void installContextInformationPresenter(ContextFrame frame) {
|
|
375 if (fContentAssistSubjectControl !is null) {
|
|
376 if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter)
|
|
377 ((ISubjectControlContextInformationPresenter)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fBeginOffset);
|
|
378 } else
|
|
379 frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset);
|
|
380 }
|
|
381
|
|
382 /**
|
|
383 * Returns an array of context information objects computed based
|
|
384 * on the specified document position. The position is used to determine
|
|
385 * the appropriate content assist processor to invoke.
|
|
386 *
|
|
387 * @param contentAssistant the content assistant
|
|
388 * @param offset a document offset
|
|
389 * @return an array of context information objects
|
|
390 * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
|
|
391 */
|
|
392 public IContextInformation[] computeContextInformation(ContentAssistant contentAssistant, int offset) {
|
|
393 if (fContentAssistSubjectControl !is null)
|
|
394 return contentAssistant.computeContextInformation(fContentAssistSubjectControl, offset);
|
|
395 return contentAssistant.computeContextInformation(fViewer, offset);
|
|
396 }
|
|
397
|
|
398 /*
|
|
399 * @see IContentAssistSubjectControl#addSelectionListener(SelectionListener)
|
|
400 */
|
|
401 public bool addSelectionListener(SelectionListener selectionListener) {
|
|
402 if (fContentAssistSubjectControl !is null)
|
|
403 return fContentAssistSubjectControl.addSelectionListener(selectionListener);
|
|
404 fViewer.getTextWidget().addSelectionListener(selectionListener);
|
|
405 return true;
|
|
406 }
|
|
407
|
|
408 /*
|
|
409 * @see IContentAssistSubjectControl#removeSelectionListener(SelectionListener)
|
|
410 */
|
|
411 public void removeSelectionListener(SelectionListener selectionListener) {
|
|
412 if (fContentAssistSubjectControl !is null)
|
|
413 fContentAssistSubjectControl.removeSelectionListener(selectionListener);
|
|
414 else
|
|
415 fViewer.getTextWidget().removeSelectionListener(selectionListener);
|
|
416 }
|
|
417 }
|