Mercurial > projects > dwt-addons
annotate dwtx/jface/internal/text/link/contentassist/AdditionalInfoController2.d @ 200:eb3414669eb0 default tip
fix for dmd 1.041 and tango 0.99.8
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 28 Mar 2009 03:09:57 +0100 |
parents | cef27f663573 |
children |
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 | |
131 | 14 |
151 | 15 module dwtx.jface.internal.text.link.contentassist.AdditionalInfoController2; |
16 | |
131 | 17 import dwtx.jface.internal.text.link.contentassist.IProposalListener; // packageimport |
18 import dwtx.jface.internal.text.link.contentassist.LineBreakingReader; // packageimport | |
19 import dwtx.jface.internal.text.link.contentassist.CompletionProposalPopup2; // packageimport | |
20 import dwtx.jface.internal.text.link.contentassist.ContextInformationPopup2; // packageimport | |
21 import dwtx.jface.internal.text.link.contentassist.ContentAssistMessages; // packageimport | |
22 import dwtx.jface.internal.text.link.contentassist.Helper2; // packageimport | |
23 import dwtx.jface.internal.text.link.contentassist.PopupCloser2; // packageimport | |
24 import dwtx.jface.internal.text.link.contentassist.IContentAssistListener2; // packageimport | |
25 import dwtx.jface.internal.text.link.contentassist.ContentAssistant2; // packageimport | |
26 | |
129 | 27 import dwt.dwthelper.utils; |
167 | 28 import dwtx.dwtxhelper.JThread; |
168 | 29 import tango.core.sync.Mutex; |
30 import tango.core.sync.Condition; | |
129 | 31 |
32 import dwt.events.SelectionEvent; | |
33 import dwt.events.SelectionListener; | |
34 import dwt.graphics.Point; | |
35 import dwt.graphics.Rectangle; | |
36 import dwt.widgets.Control; | |
37 import dwt.widgets.Table; | |
38 import dwt.widgets.TableItem; | |
39 import dwtx.core.runtime.Assert; | |
40 import dwtx.jface.text.AbstractInformationControlManager; | |
41 import dwtx.jface.text.IInformationControl; | |
42 import dwtx.jface.text.IInformationControlCreator; | |
43 import dwtx.jface.text.contentassist.ICompletionProposal; | |
44 import dwtx.jface.text.contentassist.ICompletionProposalExtension3; | |
45 | |
46 | |
47 /** | |
48 * Displays the additional information available for a completion proposal. | |
49 * | |
50 * @since 2.0 | |
51 */ | |
52 class AdditionalInfoController2 : AbstractInformationControlManager , Runnable { | |
53 | |
54 /** | |
55 * Internal table selection listener. | |
56 */ | |
57 private class TableSelectionListener : SelectionListener { | |
58 | |
59 /* | |
60 * @see SelectionListener#widgetSelected(SelectionEvent) | |
61 */ | |
62 public void widgetSelected(SelectionEvent e) { | |
63 handleTableSelectionChanged(); | |
64 } | |
65 | |
66 /* | |
67 * @see SelectionListener#widgetDefaultSelected(SelectionEvent) | |
68 */ | |
69 public void widgetDefaultSelected(SelectionEvent e) { | |
70 } | |
71 } | |
72 | |
73 | |
74 /** The proposal table */ | |
75 private Table fProposalTable; | |
76 /** The thread controlling the delayed display of the additional info */ | |
167 | 77 private JThread fThread; |
129 | 78 /** Indicates whether the display delay has been reset */ |
79 private bool fIsReset= false; | |
80 /** Object to synchronize display thread and table selection changes */ | |
168 | 81 private const Mutex fMutex; |
82 private const Condition fMutex_cond; | |
129 | 83 /** Thread access lock. */ |
159 | 84 private const Object fThreadAccess; |
129 | 85 /** Object to synchronize initial display of additional info */ |
168 | 86 private Mutex fStartSignal; |
87 private Condition fStartSignal_cond; | |
129 | 88 /** The table selection listener */ |
159 | 89 private SelectionListener fSelectionListener; |
129 | 90 /** The delay after which additional information is displayed */ |
91 private int fDelay; | |
92 | |
93 | |
94 /** | |
95 * Creates a new additional information controller. | |
96 * | |
97 * @param creator the information control creator to be used by this controller | |
98 * @param delay time in milliseconds after which additional info should be displayed | |
99 */ | |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
100 this(IInformationControlCreator creator, int delay) { |
159 | 101 fSelectionListener= new TableSelectionListener(); |
102 fThreadAccess= new Object(); | |
168 | 103 fMutex= new Mutex(); |
104 fMutex_cond= new Condition(fMutex); | |
129 | 105 super(creator); |
106 fDelay= delay; | |
107 setAnchor(ANCHOR_RIGHT); | |
130 | 108 setFallbackAnchors([ANCHOR_RIGHT, ANCHOR_LEFT, ANCHOR_BOTTOM ]); |
129 | 109 } |
110 | |
111 /* | |
112 * @see AbstractInformationControlManager#install(Control) | |
113 */ | |
114 public void install(Control control) { | |
115 | |
116 if (fProposalTable is control) { | |
117 // already installed | |
118 return; | |
119 } | |
120 | |
121 super.install(control); | |
122 | |
162 | 123 Assert.isTrue( null !is cast(Table)control ); |
134 | 124 fProposalTable= cast(Table) control; |
129 | 125 fProposalTable.addSelectionListener(fSelectionListener); |
126 synchronized (fThreadAccess) { | |
127 if (fThread !is null) | |
128 fThread.interrupt(); | |
167 | 129 fThread= new JThread(this, ContentAssistMessages.getString("InfoPopup.info_delay_timer_name")); //$NON-NLS-1$ |
129 | 130 |
168 | 131 fStartSignal= new Mutex(); |
132 fStartSignal_cond= new Condition(fStartSignal); | |
129 | 133 synchronized (fStartSignal) { |
134 fThread.start(); | |
135 try { | |
136 // wait until thread is ready | |
168 | 137 fStartSignal_cond.wait(); |
129 | 138 } catch (InterruptedException x) { |
139 } | |
140 } | |
141 } | |
142 } | |
143 | |
144 /* | |
145 * @see AbstractInformationControlManager#disposeInformationControl() | |
146 */ | |
147 public void disposeInformationControl() { | |
148 | |
149 synchronized (fThreadAccess) { | |
150 if (fThread !is null) { | |
151 fThread.interrupt(); | |
152 fThread= null; | |
153 } | |
154 } | |
155 | |
156 if (fProposalTable !is null && !fProposalTable.isDisposed()) { | |
157 fProposalTable.removeSelectionListener(fSelectionListener); | |
158 fProposalTable= null; | |
159 } | |
160 | |
161 super.disposeInformationControl(); | |
162 } | |
163 | |
164 /* | |
165 * @see java.lang.Runnable#run() | |
166 */ | |
167 public void run() { | |
168 try { | |
169 while (true) { | |
170 | |
171 synchronized (fMutex) { | |
172 | |
173 if (fStartSignal !is null) { | |
174 synchronized (fStartSignal) { | |
168 | 175 fStartSignal_cond.notifyAll(); |
129 | 176 fStartSignal= null; |
168 | 177 fStartSignal_cond = null; |
129 | 178 } |
179 } | |
180 | |
181 // Wait for a selection event to occur. | |
168 | 182 fMutex_cond.wait(); |
129 | 183 |
184 while (true) { | |
185 fIsReset= false; | |
186 // Delay before showing the popup. | |
168 | 187 fMutex_cond.wait(fDelay); |
129 | 188 if (!fIsReset) |
189 break; | |
190 } | |
191 } | |
192 | |
193 if (fProposalTable !is null && !fProposalTable.isDisposed()) { | |
135 | 194 fProposalTable.getDisplay().asyncExec(new class() Runnable { |
129 | 195 public void run() { |
196 if (!fIsReset) | |
197 showInformation(); | |
198 } | |
199 }); | |
200 } | |
201 | |
202 } | |
203 } catch (InterruptedException e) { | |
204 } | |
205 | |
206 synchronized (fThreadAccess) { | |
207 // only null fThread if it is us! | |
167 | 208 if (JThread.currentThread() is fThread) |
129 | 209 fThread= null; |
210 } | |
211 } | |
212 | |
213 /** | |
214 *Handles a change of the line selected in the associated selector. | |
215 */ | |
216 public void handleTableSelectionChanged() { | |
217 | |
218 if (fProposalTable !is null && !fProposalTable.isDisposed() && fProposalTable.isVisible()) { | |
219 synchronized (fMutex) { | |
220 fIsReset= true; | |
168 | 221 fMutex_cond.notifyAll(); |
129 | 222 } |
223 } | |
224 } | |
225 | |
226 /* | |
227 * @see AbstractInformationControlManager#computeInformation() | |
228 */ | |
229 protected void computeInformation() { | |
230 | |
231 if (fProposalTable is null || fProposalTable.isDisposed()) | |
232 return; | |
233 | |
234 TableItem[] selection= fProposalTable.getSelection(); | |
235 if (selection !is null && selection.length > 0) { | |
236 | |
237 TableItem item= selection[0]; | |
238 | |
239 // compute information | |
240 String information= null; | |
241 Object d= item.getData(); | |
242 | |
138 | 243 if ( cast(ICompletionProposal)d ) { |
134 | 244 ICompletionProposal p= cast(ICompletionProposal) d; |
129 | 245 information= p.getAdditionalProposalInfo(); |
246 } | |
247 | |
138 | 248 if ( cast(ICompletionProposalExtension3)d ) |
134 | 249 setCustomInformationControlCreator((cast(ICompletionProposalExtension3) d).getInformationControlCreator()); |
129 | 250 else |
251 setCustomInformationControlCreator(null); | |
252 | |
253 // compute subject area | |
254 setMargins(4, -1); | |
255 Rectangle area= fProposalTable.getBounds(); | |
256 area.x= 0; // subject area is the whole subject control | |
257 area.y= 0; | |
258 | |
259 // set information & subject area | |
260 setInformation(information, area); | |
261 } | |
262 } | |
263 | |
264 /* | |
265 * @see dwtx.jface.text.AbstractInformationControlManager#computeSizeConstraints(Control, IInformationControl) | |
266 */ | |
267 protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) { | |
268 // at least as big as the proposal table | |
269 Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl); | |
270 Point size= subjectControl.getSize(); | |
271 if (sizeConstraint.x < size.x) | |
272 sizeConstraint.x= size.x; | |
273 if (sizeConstraint.y < size.y) | |
274 sizeConstraint.y= size.y; | |
275 return sizeConstraint; | |
276 } | |
277 } | |
278 | |
279 |