Mercurial > projects > dwt-addons
annotate dwtx/jface/text/contentassist/AdditionalInfoController.d @ 147:000f9136b8f7
final
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 24 Aug 2008 22:35:05 +0200 |
parents | 75302ef3f92f |
children | 7926b636c282 |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 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.AdditionalInfoController; | |
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.IContextInformationPresenter; // packageimport | |
33 import dwtx.jface.text.contentassist.ICompletionProposalExtension4; // packageimport | |
34 import dwtx.jface.text.contentassist.ICompletionListenerExtension; // packageimport | |
35 import dwtx.jface.text.contentassist.ContextInformationPopup; // packageimport | |
36 import dwtx.jface.text.contentassist.IContextInformationExtension; // packageimport | |
37 import dwtx.jface.text.contentassist.IContentAssistantExtension2; // packageimport | |
38 import dwtx.jface.text.contentassist.ContentAssistSubjectControlAdapter; // 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 import dwt.events.SelectionEvent; | |
54 import dwt.events.SelectionListener; | |
55 import dwt.graphics.Point; | |
56 import dwt.graphics.Rectangle; | |
57 import dwt.widgets.Control; | |
58 import dwt.widgets.Display; | |
59 import dwt.widgets.Shell; | |
60 import dwt.widgets.Table; | |
61 import dwt.widgets.TableItem; | |
62 import dwtx.core.runtime.Assert; | |
63 import dwtx.core.runtime.IProgressMonitor; | |
64 import dwtx.core.runtime.IStatus; | |
65 import dwtx.core.runtime.Status; | |
66 import dwtx.core.runtime.jobs.Job; | |
67 import dwtx.jface.internal.text.InformationControlReplacer; | |
68 import dwtx.jface.text.AbstractInformationControlManager; | |
69 import dwtx.jface.text.AbstractReusableInformationControlCreator; | |
70 import dwtx.jface.text.DefaultInformationControl; | |
71 import dwtx.jface.text.IInformationControl; | |
72 import dwtx.jface.text.IInformationControlCreator; | |
73 import dwtx.jface.text.IInformationControlExtension3; | |
74 | |
75 | |
76 /** | |
77 * Displays the additional information available for a completion proposal. | |
78 * | |
79 * @since 2.0 | |
80 */ | |
81 class AdditionalInfoController : AbstractInformationControlManager { | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
82 |
129 | 83 /** |
84 * A timer thread. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
85 * |
129 | 86 * @since 3.2 |
87 */ | |
88 private static abstract class Timer { | |
147 | 89 private static const int DELAY_UNTIL_JOB_IS_SCHEDULED= 50; |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
90 |
129 | 91 /** |
92 * A <code>Task</code> is {@link Task#run() run} when {@link #delay()} milliseconds have | |
93 * elapsed after it was scheduled without a {@link #reset(ICompletionProposal) reset} | |
94 * to occur. | |
95 */ | |
96 private abstract class Task : Runnable { | |
97 /** | |
98 * @return the delay in milliseconds before this task should be run | |
99 */ | |
100 public abstract long delay(); | |
101 /** | |
102 * Runs this task. | |
103 */ | |
104 public abstract void run(); | |
105 /** | |
106 * @return the task to be scheduled after this task has been run | |
107 */ | |
108 public abstract Task nextTask(); | |
109 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
110 |
129 | 111 /** |
112 * IDLE: the initial task, and active whenever the info has been shown. It cannot be run, | |
113 * but specifies an infinite delay. | |
114 */ | |
135 | 115 private final Task IDLE= new class() Task { |
129 | 116 public void run() { |
117 Assert.isTrue(false); | |
118 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
119 |
129 | 120 public Task nextTask() { |
121 Assert.isTrue(false); | |
122 return null; | |
123 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
124 |
129 | 125 public long delay() { |
126 return Long.MAX_VALUE; | |
127 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
128 |
129 | 129 public String toString() { |
130 return "IDLE"; //$NON-NLS-1$ | |
131 } | |
132 }; | |
133 /** | |
134 * FIRST_WAIT: Schedules a platform {@link Job} to fetch additional info from an {@link ICompletionProposalExtension5}. | |
135 */ | |
135 | 136 private final Task FIRST_WAIT= new class() Task { |
129 | 137 public void run() { |
138 final ICompletionProposalExtension5 proposal= getCurrentProposalEx(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
139 Job job= new class(JFaceTextMessages.getString("AdditionalInfoController.job_name")) Job { //$NON-NLS-1$ |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
140 this( String txt ){ |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
141 super( txt ); |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
142 } |
129 | 143 protected IStatus run(IProgressMonitor monitor) { |
144 Object info; | |
145 try { | |
146 info= proposal.getAdditionalProposalInfo(monitor); | |
147 } catch (RuntimeException x) { | |
148 /* | |
149 * XXX: This is the safest fix at this point so close to end of 3.2. | |
150 * Will be revisited when fixing https://bugs.eclipse.org/bugs/show_bug.cgi?id=101033 | |
151 */ | |
152 return new Status(IStatus.WARNING, "dwtx.jface.text", IStatus.OK, "", x); //$NON-NLS-1$ //$NON-NLS-2$ | |
153 } | |
134 | 154 setInfo(cast(ICompletionProposal) proposal, info); |
129 | 155 return new Status(IStatus.OK, "dwtx.jface.text", IStatus.OK, "", null); //$NON-NLS-1$ //$NON-NLS-2$ |
156 } | |
157 }; | |
158 job.schedule(); | |
159 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
160 |
129 | 161 public Task nextTask() { |
162 return SECOND_WAIT; | |
163 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
164 |
129 | 165 public long delay() { |
166 return DELAY_UNTIL_JOB_IS_SCHEDULED; | |
167 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
168 |
129 | 169 public String toString() { |
170 return "FIRST_WAIT"; //$NON-NLS-1$ | |
171 } | |
172 }; | |
173 /** | |
174 * SECOND_WAIT: Allows display of additional info obtained from an | |
175 * {@link ICompletionProposalExtension5}. | |
176 */ | |
135 | 177 private final Task SECOND_WAIT= new class() Task { |
129 | 178 public void run() { |
179 // show the info | |
180 allowShowing(); | |
181 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
182 |
129 | 183 public Task nextTask() { |
184 return IDLE; | |
185 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
186 |
129 | 187 public long delay() { |
188 return fDelay - DELAY_UNTIL_JOB_IS_SCHEDULED; | |
189 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
190 |
129 | 191 public String toString() { |
192 return "SECOND_WAIT"; //$NON-NLS-1$ | |
193 } | |
194 }; | |
195 /** | |
196 * LEGACY_WAIT: Posts a runnable into the display thread to fetch additional info from non-{@link ICompletionProposalExtension5}s. | |
197 */ | |
135 | 198 private final Task LEGACY_WAIT= new class() Task { |
129 | 199 public void run() { |
200 final ICompletionProposal proposal= getCurrentProposal(); | |
201 if (!fDisplay.isDisposed()) { | |
135 | 202 fDisplay.asyncExec(new class() Runnable { |
129 | 203 public void run() { |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
204 synchronized (this.outer) { |
129 | 205 if (proposal is getCurrentProposal()) { |
206 Object info= proposal.getAdditionalProposalInfo(); | |
207 showInformation(proposal, info); | |
208 } | |
209 } | |
210 } | |
211 }); | |
212 } | |
213 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
214 |
129 | 215 public Task nextTask() { |
216 return IDLE; | |
217 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
218 |
129 | 219 public long delay() { |
220 return fDelay; | |
221 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
222 |
129 | 223 public String toString() { |
224 return "LEGACY_WAIT"; //$NON-NLS-1$ | |
225 } | |
226 }; | |
227 /** | |
228 * EXIT: The task that triggers termination of the timer thread. | |
229 */ | |
135 | 230 private final Task EXIT= new class() Task { |
129 | 231 public long delay() { |
232 return 1; | |
233 } | |
234 | |
235 public Task nextTask() { | |
236 Assert.isTrue(false); | |
237 return EXIT; | |
238 } | |
239 | |
240 public void run() { | |
241 Assert.isTrue(false); | |
242 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
243 |
129 | 244 public String toString() { |
245 return "EXIT"; //$NON-NLS-1$ | |
246 } | |
247 }; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
248 |
129 | 249 /** The timer thread. */ |
146 | 250 private const Thread fThread; |
129 | 251 |
252 /** The currently waiting / active task. */ | |
253 private Task fTask; | |
254 /** The next wake up time. */ | |
255 private long fNextWakeup; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
256 |
129 | 257 private ICompletionProposal fCurrentProposal= null; |
258 private Object fCurrentInfo= null; | |
259 private bool fAllowShowing= false; | |
260 | |
146 | 261 private const Display fDisplay; |
262 private const int fDelay; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
263 |
129 | 264 /** |
265 * Creates a new timer. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
266 * |
129 | 267 * @param display the display to use for display thread posting. |
268 * @param delay the delay until to show additional info | |
269 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
270 public this(Display display, int delay) { |
129 | 271 fDisplay= display; |
272 fDelay= delay; | |
273 long current= System.currentTimeMillis(); | |
274 schedule(IDLE, current); | |
275 | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
276 void threadrun() { |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
277 try { |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
278 loop(); |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
279 } catch (InterruptedException x) { |
129 | 280 } |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
281 } |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
282 fThread= new Thread( &threadrun ); |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
283 fThread.name = JFaceTextMessages.getString("InfoPopup.info_delay_timer_name"); //$NON-NLS-1$ |
129 | 284 fThread.start(); |
285 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
286 |
129 | 287 /** |
288 * Terminates the timer thread. | |
289 */ | |
290 public synchronized final void terminate() { | |
291 schedule(EXIT, System.currentTimeMillis()); | |
292 notifyAll(); | |
293 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
294 |
129 | 295 /** |
296 * Resets the timer thread as the selection has changed to a new proposal. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
297 * |
129 | 298 * @param p the new proposal |
299 */ | |
300 public final synchronized void reset(ICompletionProposal p) { | |
301 if (fCurrentProposal !is p) { | |
302 fCurrentProposal= p; | |
303 fCurrentInfo= null; | |
304 fAllowShowing= false; | |
305 | |
306 long oldWakeup= fNextWakeup; | |
307 Task task= taskOnReset(p); | |
308 schedule(task, System.currentTimeMillis()); | |
309 if (fNextWakeup < oldWakeup) | |
310 notifyAll(); | |
311 } | |
312 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
313 |
129 | 314 private Task taskOnReset(ICompletionProposal p) { |
315 if (p is null) | |
316 return IDLE; | |
317 if (isExt5(p)) | |
318 return FIRST_WAIT; | |
319 return LEGACY_WAIT; | |
320 } | |
321 | |
136
6dcb0baaa031
Regex removal of throws decls, some instanceof
Frank Benoit <benoit@tionex.de>
parents:
135
diff
changeset
|
322 private synchronized void loop() { |
129 | 323 long current= System.currentTimeMillis(); |
324 Task task= currentTask(); | |
325 | |
326 while (task !is EXIT) { | |
327 long delay= fNextWakeup - current; | |
328 if (delay <= 0) { | |
329 task.run(); | |
330 task= task.nextTask(); | |
331 schedule(task, current); | |
332 } else { | |
333 wait(delay); | |
334 current= System.currentTimeMillis(); | |
335 task= currentTask(); | |
336 } | |
337 } | |
338 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
339 |
129 | 340 private Task currentTask() { |
341 return fTask; | |
342 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
343 |
129 | 344 private void schedule(Task task, long current) { |
345 fTask= task; | |
346 long nextWakeup= current + task.delay(); | |
347 if (nextWakeup <= current) | |
348 fNextWakeup= Long.MAX_VALUE; | |
349 else | |
350 fNextWakeup= nextWakeup; | |
351 } | |
352 | |
353 private bool isExt5(ICompletionProposal p) { | |
139
93a6ec48fd28
Regexp throws removal in interfaces
Frank Benoit <benoit@tionex.de>
parents:
138
diff
changeset
|
354 return cast(ICompletionProposalExtension5)p; |
129 | 355 } |
356 | |
357 ICompletionProposal getCurrentProposal() { | |
358 return fCurrentProposal; | |
359 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
360 |
129 | 361 ICompletionProposalExtension5 getCurrentProposalEx() { |
138 | 362 Assert.isTrue( cast(ICompletionProposalExtension5)fCurrentProposal ); |
134 | 363 return cast(ICompletionProposalExtension5) fCurrentProposal; |
129 | 364 } |
365 | |
366 synchronized void setInfo(ICompletionProposal proposal, Object info) { | |
367 if (proposal is fCurrentProposal) { | |
368 fCurrentInfo= info; | |
369 if (fAllowShowing) { | |
370 triggerShowing(); | |
371 } | |
372 } | |
373 } | |
374 | |
375 private void triggerShowing() { | |
376 final Object info= fCurrentInfo; | |
377 if (!fDisplay.isDisposed()) { | |
135 | 378 fDisplay.asyncExec(new class() Runnable { |
129 | 379 public void run() { |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
380 synchronized (this.outer) { |
129 | 381 if (info is fCurrentInfo) { |
382 showInformation(fCurrentProposal, info); | |
383 } | |
384 } | |
385 } | |
386 }); | |
387 } | |
388 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
389 |
129 | 390 /** |
391 * Called in the display thread to show additional info. | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
392 * |
129 | 393 * @param proposal the proposal to show information about |
394 * @param info the information about <code>proposal</code> | |
395 */ | |
396 protected abstract void showInformation(ICompletionProposal proposal, Object info); | |
397 | |
398 void allowShowing() { | |
399 fAllowShowing= true; | |
400 triggerShowing(); | |
401 } | |
402 } | |
403 /** | |
404 * Internal table selection listener. | |
405 */ | |
406 private class TableSelectionListener : SelectionListener { | |
407 | |
408 /* | |
409 * @see SelectionListener#widgetSelected(SelectionEvent) | |
410 */ | |
411 public void widgetSelected(SelectionEvent e) { | |
412 handleTableSelectionChanged(); | |
413 } | |
414 | |
415 /* | |
416 * @see SelectionListener#widgetDefaultSelected(SelectionEvent) | |
417 */ | |
418 public void widgetDefaultSelected(SelectionEvent e) { | |
419 } | |
420 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
421 |
129 | 422 /** |
423 * Default control creator for the information control replacer. | |
424 * @since 3.4 | |
425 */ | |
426 private static class DefaultPresenterControlCreator : AbstractReusableInformationControlCreator { | |
427 public IInformationControl doCreateInformationControl(Shell shell) { | |
428 return new DefaultInformationControl(shell, true); | |
429 } | |
430 } | |
431 | |
432 /** The proposal table. */ | |
433 private Table fProposalTable; | |
434 /** The table selection listener */ | |
435 private SelectionListener fSelectionListener= new TableSelectionListener(); | |
436 /** The delay after which additional information is displayed */ | |
146 | 437 private const int fDelay; |
129 | 438 /** |
439 * The timer thread. | |
440 * @since 3.2 | |
441 */ | |
442 private Timer fTimer; | |
443 /** | |
444 * The proposal most recently set by {@link #showInformation(ICompletionProposal, Object)}, | |
445 * possibly <code>null</code>. | |
446 * @since 3.2 | |
447 */ | |
448 private ICompletionProposal fProposal; | |
449 /** | |
450 * The information most recently set by {@link #showInformation(ICompletionProposal, Object)}, | |
451 * possibly <code>null</code>. | |
452 * @since 3.2 | |
453 */ | |
454 private Object fInformation; | |
455 | |
456 /** | |
457 * Creates a new additional information controller. | |
458 * | |
459 * @param creator the information control creator to be used by this controller | |
460 * @param delay time in milliseconds after which additional info should be displayed | |
461 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
462 this(IInformationControlCreator creator, int delay) { |
129 | 463 super(creator); |
464 fDelay= delay; | |
465 setAnchor(ANCHOR_RIGHT); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
466 setFallbackAnchors([ ANCHOR_RIGHT, ANCHOR_LEFT, ANCHOR_BOTTOM ]); |
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
467 |
129 | 468 /* |
469 * Adjust the location by one pixel towards the proposal popup, so that the single pixel | |
470 * border of the additional info popup overlays with the border of the popup. This avoids | |
471 * having a double black line. | |
472 */ | |
473 int spacing= -1; | |
474 setMargins(spacing, spacing); // see also adjustment in #computeLocation | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
475 |
129 | 476 InformationControlReplacer replacer= new InformationControlReplacer(new DefaultPresenterControlCreator()); |
477 getInternalAccessor().setInformationControlReplacer(replacer); | |
478 } | |
479 | |
480 /* | |
481 * @see AbstractInformationControlManager#install(Control) | |
482 */ | |
483 public void install(Control control) { | |
484 | |
485 if (fProposalTable is control) { | |
486 // already installed | |
487 return; | |
488 } | |
489 | |
490 super.install(control.getShell()); | |
491 | |
138 | 492 Assert.isTrue( cast(Table)control ); |
134 | 493 fProposalTable= cast(Table) control; |
129 | 494 fProposalTable.addSelectionListener(fSelectionListener); |
495 getInternalAccessor().getInformationControlReplacer().install(fProposalTable); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
496 |
135 | 497 fTimer= new class(fProposalTable.getDisplay(), fDelay) Timer { |
129 | 498 protected void showInformation(ICompletionProposal proposal, Object info) { |
499 InformationControlReplacer replacer= getInternalAccessor().getInformationControlReplacer(); | |
500 if (replacer !is null) | |
501 replacer.hideInformationControl(); | |
137 | 502 this.outer.showInformation(proposal, info); |
129 | 503 } |
504 }; | |
505 } | |
506 | |
507 /* | |
508 * @see AbstractInformationControlManager#disposeInformationControl() | |
509 */ | |
510 public void disposeInformationControl() { | |
511 | |
512 if (fTimer !is null) { | |
513 fTimer.terminate(); | |
514 fTimer= null; | |
515 } | |
516 | |
517 fProposal= null; | |
518 fInformation= null; | |
519 | |
520 if (fProposalTable !is null && !fProposalTable.isDisposed()) { | |
521 fProposalTable.removeSelectionListener(fSelectionListener); | |
522 fProposalTable= null; | |
523 } | |
524 | |
525 super.disposeInformationControl(); | |
526 } | |
527 | |
528 /** | |
529 *Handles a change of the line selected in the associated selector. | |
530 */ | |
531 public void handleTableSelectionChanged() { | |
532 | |
533 if (fProposalTable !is null && !fProposalTable.isDisposed() && fProposalTable.isVisible()) { | |
534 TableItem[] selection= fProposalTable.getSelection(); | |
535 if (selection !is null && selection.length > 0) { | |
536 | |
537 TableItem item= selection[0]; | |
538 | |
539 Object d= item.getData(); | |
138 | 540 if ( cast(ICompletionProposal)d ) { |
134 | 541 ICompletionProposal p= cast(ICompletionProposal) d; |
129 | 542 fTimer.reset(p); |
543 } | |
544 } | |
545 } | |
546 } | |
547 | |
548 void showInformation(ICompletionProposal proposal, Object info) { | |
549 if (fProposalTable is null || fProposalTable.isDisposed()) | |
550 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
551 |
129 | 552 if (fProposal is proposal && ((info is null && fInformation is null) || (info !is null && info.equals(fInformation)))) |
553 return; | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
554 |
129 | 555 fInformation= info; |
556 fProposal= proposal; | |
557 showInformation(); | |
558 } | |
559 | |
560 /* | |
561 * @see AbstractInformationControlManager#computeInformation() | |
562 */ | |
563 protected void computeInformation() { | |
138 | 564 if ( cast(ICompletionProposalExtension3)fProposal ) |
134 | 565 setCustomInformationControlCreator((cast(ICompletionProposalExtension3) fProposal).getInformationControlCreator()); |
129 | 566 else |
567 setCustomInformationControlCreator(null); | |
568 | |
569 // compute subject area | |
570 Point size= fProposalTable.getShell().getSize(); | |
571 | |
572 // set information & subject area | |
573 setInformation(fInformation, new Rectangle(0, 0, size.x, size.y)); | |
574 } | |
575 | |
576 /* | |
577 * @see dwtx.jface.text.AbstractInformationControlManager#computeLocation(dwt.graphics.Rectangle, dwt.graphics.Point, dwtx.jface.text.AbstractInformationControlManager.Anchor) | |
578 */ | |
579 protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) { | |
580 Point location= super.computeLocation(subjectArea, controlSize, anchor); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
581 |
129 | 582 /* |
583 * The location is computed using subjectControl.toDisplay(), which does not include the | |
584 * trim of the subject control. As we want the additional info popup aligned with the outer | |
585 * coordinates of the proposal popup, adjust this here | |
586 */ | |
587 Rectangle trim= fProposalTable.getShell().computeTrim(0, 0, 0, 0); | |
588 location.x += trim.x; | |
589 location.y += trim.y; | |
590 | |
591 return location; | |
592 } | |
593 | |
594 /* | |
595 * @see dwtx.jface.text.AbstractInformationControlManager#computeSizeConstraints(Control, IInformationControl) | |
596 */ | |
597 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) { | |
598 // at least as big as the proposal table | |
599 Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl); | |
600 Point size= subjectControl.getShell().getSize(); | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
601 |
129 | 602 // AbstractInformationControlManager#internalShowInformationControl(Rectangle, Object) adds trims |
603 // to the computed constraints. Need to remove them here, to make the outer bounds of the additional | |
604 // info shell fit the bounds of the proposal shell: | |
138 | 605 if ( cast(IInformationControlExtension3)fInformationControl ) { |
134 | 606 Rectangle shellTrim= (cast(IInformationControlExtension3) fInformationControl).computeTrim(); |
129 | 607 size.x -= shellTrim.width; |
608 size.y -= shellTrim.height; | |
609 } | |
610 | |
611 if (sizeConstraint.x < size.x) | |
612 sizeConstraint.x= size.x; | |
613 if (sizeConstraint.y < size.y) | |
614 sizeConstraint.y= size.y; | |
615 return sizeConstraint; | |
616 } | |
140
26688fec6d23
Following dsss compile errors
Frank Benoit <benoit@tionex.de>
parents:
139
diff
changeset
|
617 |
129 | 618 /* |
619 * @see dwtx.jface.text.AbstractInformationControlManager#hideInformationControl() | |
620 */ | |
621 protected void hideInformationControl() { | |
622 super.hideInformationControl(); | |
623 } | |
624 | |
625 /** | |
626 * @return the current information control, or <code>null</code> if none available | |
627 */ | |
628 public IInformationControl getCurrentInformationControl2() { | |
629 return getInternalAccessor().getCurrentInformationControl(); | |
630 } | |
631 } | |
632 | |
633 |