comparison dwtx/jface/text/contentassist/AdditionalInfoController.d @ 159:7926b636c282

...
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 01:57:58 +0200
parents 000f9136b8f7
children 3678e4f1a766
comparison
equal deleted inserted replaced
158:25f1f92fa3df 159:7926b636c282
42 import dwtx.jface.text.contentassist.IContentAssistantExtension3; // packageimport 42 import dwtx.jface.text.contentassist.IContentAssistantExtension3; // packageimport
43 import dwtx.jface.text.contentassist.ContentAssistant; // packageimport 43 import dwtx.jface.text.contentassist.ContentAssistant; // packageimport
44 import dwtx.jface.text.contentassist.IContentAssistantExtension; // packageimport 44 import dwtx.jface.text.contentassist.IContentAssistantExtension; // packageimport
45 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport 45 import dwtx.jface.text.contentassist.JFaceTextMessages; // packageimport
46 46
47
48 import dwt.dwthelper.utils; 47 import dwt.dwthelper.utils;
49 48 import tango.core.Thread;
50
51
52 49
53 import dwt.events.SelectionEvent; 50 import dwt.events.SelectionEvent;
54 import dwt.events.SelectionListener; 51 import dwt.events.SelectionListener;
55 import dwt.graphics.Point; 52 import dwt.graphics.Point;
56 import dwt.graphics.Rectangle; 53 import dwt.graphics.Rectangle;
110 107
111 /** 108 /**
112 * IDLE: the initial task, and active whenever the info has been shown. It cannot be run, 109 * IDLE: the initial task, and active whenever the info has been shown. It cannot be run,
113 * but specifies an infinite delay. 110 * but specifies an infinite delay.
114 */ 111 */
115 private final Task IDLE= new class() Task { 112 private Task IDLE;
116 public void run() { 113 private void IDLE_init(){
117 Assert.isTrue(false); 114 IDLE = new class() Task {
118 } 115 public void run() {
119 116 Assert.isTrue(false);
120 public Task nextTask() { 117 }
121 Assert.isTrue(false); 118
122 return null; 119 public Task nextTask() {
123 } 120 Assert.isTrue(false);
124 121 return null;
125 public long delay() { 122 }
126 return Long.MAX_VALUE; 123
127 } 124 public long delay() {
128 125 return Long.MAX_VALUE;
129 public String toString() { 126 }
130 return "IDLE"; //$NON-NLS-1$ 127
131 } 128 public String toString() {
132 }; 129 return "IDLE"; //$NON-NLS-1$
130 }
131 };
132 }
133 /** 133 /**
134 * FIRST_WAIT: Schedules a platform {@link Job} to fetch additional info from an {@link ICompletionProposalExtension5}. 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 { 136 private Task FIRST_WAIT;
137 public void run() { 137 private void FIRST_WAIT_init() {
138 final ICompletionProposalExtension5 proposal= getCurrentProposalEx(); 138 FIRST_WAIT = new class() Task {
139 Job job= new class(JFaceTextMessages.getString("AdditionalInfoController.job_name")) Job { //$NON-NLS-1$ 139 public void run() {
140 this( String txt ){ 140 final ICompletionProposalExtension5 proposal= getCurrentProposalEx();
141 super( txt ); 141 Job job= new class(JFaceTextMessages.getString("AdditionalInfoController.job_name")) Job { //$NON-NLS-1$
142 } 142 this( String txt ){
143 protected IStatus run(IProgressMonitor monitor) { 143 super( txt );
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 } 144 }
154 setInfo(cast(ICompletionProposal) proposal, info); 145 protected IStatus run(IProgressMonitor monitor) {
155 return new Status(IStatus.OK, "dwtx.jface.text", IStatus.OK, "", null); //$NON-NLS-1$ //$NON-NLS-2$ 146 Object info;
156 } 147 try {
157 }; 148 info= proposal.getAdditionalProposalInfo(monitor);
158 job.schedule(); 149 } catch (RuntimeException x) {
159 } 150 /*
160 151 * XXX: This is the safest fix at this point so close to end of 3.2.
161 public Task nextTask() { 152 * Will be revisited when fixing https://bugs.eclipse.org/bugs/show_bug.cgi?id=101033
162 return SECOND_WAIT; 153 */
163 } 154 return new Status(IStatus.WARNING, "dwtx.jface.text", IStatus.OK, "", x); //$NON-NLS-1$ //$NON-NLS-2$
164 155 }
165 public long delay() { 156 setInfo(cast(ICompletionProposal) proposal, info);
166 return DELAY_UNTIL_JOB_IS_SCHEDULED; 157 return new Status(IStatus.OK, "dwtx.jface.text", IStatus.OK, "", null); //$NON-NLS-1$ //$NON-NLS-2$
167 } 158 }
168 159 };
169 public String toString() { 160 job.schedule();
170 return "FIRST_WAIT"; //$NON-NLS-1$ 161 }
171 } 162
172 }; 163 public Task nextTask() {
164 return SECOND_WAIT;
165 }
166
167 public long delay() {
168 return DELAY_UNTIL_JOB_IS_SCHEDULED;
169 }
170
171 public String toString() {
172 return "FIRST_WAIT"; //$NON-NLS-1$
173 }
174 };
175 }
173 /** 176 /**
174 * SECOND_WAIT: Allows display of additional info obtained from an 177 * SECOND_WAIT: Allows display of additional info obtained from an
175 * {@link ICompletionProposalExtension5}. 178 * {@link ICompletionProposalExtension5}.
176 */ 179 */
177 private final Task SECOND_WAIT= new class() Task { 180 private Task SECOND_WAIT;
178 public void run() { 181 private void SECOND_WAIT_init() {
179 // show the info 182 SECOND_WAIT = new class() Task {
180 allowShowing(); 183 public void run() {
181 } 184 // show the info
182 185 allowShowing();
183 public Task nextTask() { 186 }
184 return IDLE; 187
185 } 188 public Task nextTask() {
186 189 return IDLE;
187 public long delay() { 190 }
188 return fDelay - DELAY_UNTIL_JOB_IS_SCHEDULED; 191
189 } 192 public long delay() {
190 193 return fDelay - DELAY_UNTIL_JOB_IS_SCHEDULED;
191 public String toString() { 194 }
192 return "SECOND_WAIT"; //$NON-NLS-1$ 195
193 } 196 public String toString() {
194 }; 197 return "SECOND_WAIT"; //$NON-NLS-1$
198 }
199 };
200 }
195 /** 201 /**
196 * LEGACY_WAIT: Posts a runnable into the display thread to fetch additional info from non-{@link ICompletionProposalExtension5}s. 202 * LEGACY_WAIT: Posts a runnable into the display thread to fetch additional info from non-{@link ICompletionProposalExtension5}s.
197 */ 203 */
198 private final Task LEGACY_WAIT= new class() Task { 204 private Task LEGACY_WAIT;
199 public void run() { 205 private void LEGACY_WAIT_init() {
200 final ICompletionProposal proposal= getCurrentProposal(); 206 LEGACY_WAIT = new class() Task {
201 if (!fDisplay.isDisposed()) { 207 public void run() {
202 fDisplay.asyncExec(new class() Runnable { 208 final ICompletionProposal proposal= getCurrentProposal();
203 public void run() { 209 if (!fDisplay.isDisposed()) {
204 synchronized (this.outer) { 210 fDisplay.asyncExec(new class() Runnable {
205 if (proposal is getCurrentProposal()) { 211 public void run() {
206 Object info= proposal.getAdditionalProposalInfo(); 212 synchronized (this.outer) {
207 showInformation(proposal, info); 213 if (proposal is getCurrentProposal()) {
214 Object info= proposal.getAdditionalProposalInfo();
215 showInformation(proposal, info);
216 }
208 } 217 }
209 } 218 }
210 } 219 });
211 }); 220 }
212 } 221 }
213 } 222
214 223 public Task nextTask() {
215 public Task nextTask() { 224 return IDLE;
216 return IDLE; 225 }
217 } 226
218 227 public long delay() {
219 public long delay() { 228 return fDelay;
220 return fDelay; 229 }
221 } 230
222 231 public String toString() {
223 public String toString() { 232 return "LEGACY_WAIT"; //$NON-NLS-1$
224 return "LEGACY_WAIT"; //$NON-NLS-1$ 233 }
225 } 234 };
226 }; 235 }
227 /** 236 /**
228 * EXIT: The task that triggers termination of the timer thread. 237 * EXIT: The task that triggers termination of the timer thread.
229 */ 238 */
230 private final Task EXIT= new class() Task { 239 private Task EXIT;
231 public long delay() { 240 private void EXIT_init() {
232 return 1; 241 EXIT = new class() Task {
233 } 242 public long delay() {
234 243 return 1;
235 public Task nextTask() { 244 }
236 Assert.isTrue(false); 245
237 return EXIT; 246 public Task nextTask() {
238 } 247 Assert.isTrue(false);
239 248 return EXIT;
240 public void run() { 249 }
241 Assert.isTrue(false); 250
242 } 251 public void run() {
243 252 Assert.isTrue(false);
244 public String toString() { 253 }
245 return "EXIT"; //$NON-NLS-1$ 254
246 } 255 public String toString() {
247 }; 256 return "EXIT"; //$NON-NLS-1$
257 }
258 };
259 }
248 260
249 /** The timer thread. */ 261 /** The timer thread. */
250 private const Thread fThread; 262 private const Thread fThread;
251 263
252 /** The currently waiting / active task. */ 264 /** The currently waiting / active task. */
266 * 278 *
267 * @param display the display to use for display thread posting. 279 * @param display the display to use for display thread posting.
268 * @param delay the delay until to show additional info 280 * @param delay the delay until to show additional info
269 */ 281 */
270 public this(Display display, int delay) { 282 public this(Display display, int delay) {
283 // DWT instance init
284 IDLE_init();
285 FIRST_WAIT_init();
286 SECOND_WAIT_init();
287 LEGACY_WAIT_init();
288 EXIT_init();
289
271 fDisplay= display; 290 fDisplay= display;
272 fDelay= delay; 291 fDelay= delay;
273 long current= System.currentTimeMillis(); 292 long current= System.currentTimeMillis();
274 schedule(IDLE, current); 293 schedule(IDLE, current);
275 294
430 } 449 }
431 450
432 /** The proposal table. */ 451 /** The proposal table. */
433 private Table fProposalTable; 452 private Table fProposalTable;
434 /** The table selection listener */ 453 /** The table selection listener */
435 private SelectionListener fSelectionListener= new TableSelectionListener(); 454 private SelectionListener fSelectionListener;
436 /** The delay after which additional information is displayed */ 455 /** The delay after which additional information is displayed */
437 private const int fDelay; 456 private const int fDelay;
438 /** 457 /**
439 * The timer thread. 458 * The timer thread.
440 * @since 3.2 459 * @since 3.2
458 * 477 *
459 * @param creator the information control creator to be used by this controller 478 * @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 479 * @param delay time in milliseconds after which additional info should be displayed
461 */ 480 */
462 this(IInformationControlCreator creator, int delay) { 481 this(IInformationControlCreator creator, int delay) {
482
483 fSelectionListener= new TableSelectionListener();
484
463 super(creator); 485 super(creator);
464 fDelay= delay; 486 fDelay= delay;
465 setAnchor(ANCHOR_RIGHT); 487 setAnchor(ANCHOR_RIGHT);
466 setFallbackAnchors([ ANCHOR_RIGHT, ANCHOR_LEFT, ANCHOR_BOTTOM ]); 488 setFallbackAnchors([ ANCHOR_RIGHT, ANCHOR_LEFT, ANCHOR_BOTTOM ]);
467 489