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