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