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.PopupCloser;
|
|
14
|
131
|
15 import dwtx.jface.text.contentassist.ContentAssistEvent; // packageimport
|
|
16 import dwtx.jface.text.contentassist.Helper; // packageimport
|
|
17 import dwtx.jface.text.contentassist.IContentAssistant; // packageimport
|
|
18 import dwtx.jface.text.contentassist.CompletionProposal; // packageimport
|
|
19 import dwtx.jface.text.contentassist.ICompletionProposalExtension5; // packageimport
|
|
20 import dwtx.jface.text.contentassist.IContextInformationValidator; // packageimport
|
|
21 import dwtx.jface.text.contentassist.IContentAssistListener; // packageimport
|
|
22 import dwtx.jface.text.contentassist.ICompletionProposalExtension6; // packageimport
|
|
23 import dwtx.jface.text.contentassist.ICompletionListener; // packageimport
|
|
24 import dwtx.jface.text.contentassist.ICompletionProposalExtension2; // packageimport
|
|
25 import dwtx.jface.text.contentassist.IContentAssistantExtension4; // packageimport
|
|
26 import dwtx.jface.text.contentassist.ContextInformation; // packageimport
|
|
27 import dwtx.jface.text.contentassist.ICompletionProposalExtension3; // packageimport
|
|
28 import dwtx.jface.text.contentassist.ContextInformationValidator; // packageimport
|
|
29 import dwtx.jface.text.contentassist.ICompletionProposal; // packageimport
|
|
30 import dwtx.jface.text.contentassist.IContentAssistProcessor; // packageimport
|
|
31 import dwtx.jface.text.contentassist.AdditionalInfoController; // 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 import dwt.DWT;
|
|
53 import dwt.events.FocusEvent;
|
|
54 import dwt.events.FocusListener;
|
|
55 import dwt.events.SelectionEvent;
|
|
56 import dwt.events.SelectionListener;
|
|
57 import dwt.events.ShellAdapter;
|
|
58 import dwt.events.ShellEvent;
|
|
59 import dwt.widgets.Control;
|
|
60 import dwt.widgets.Display;
|
|
61 import dwt.widgets.Event;
|
|
62 import dwt.widgets.Listener;
|
|
63 import dwt.widgets.ScrollBar;
|
|
64 import dwt.widgets.Shell;
|
|
65 import dwt.widgets.Table;
|
|
66 import dwtx.jface.internal.text.DelayedInputChangeListener;
|
|
67 import dwtx.jface.internal.text.InformationControlReplacer;
|
|
68 import dwtx.jface.text.IDelayedInputChangeProvider;
|
|
69 import dwtx.jface.text.IInformationControl;
|
|
70 import dwtx.jface.text.IInformationControlExtension5;
|
|
71 import dwtx.jface.text.IInputChangedListener;
|
|
72
|
|
73
|
|
74 /**
|
|
75 * A generic closer class used to monitor various
|
|
76 * interface events in order to determine whether
|
|
77 * a content assistant should be terminated and all
|
|
78 * associated windows be closed.
|
|
79 */
|
|
80 class PopupCloser : ShellAdapter , FocusListener, SelectionListener, Listener {
|
|
81
|
|
82 /** The content assistant to be monitored. */
|
|
83 private ContentAssistant fContentAssistant;
|
|
84 /** The table of a selector popup opened by the content assistant. */
|
|
85 private Table fTable;
|
|
86 /** The scroll bar of the table for the selector popup. */
|
|
87 private ScrollBar fScrollbar;
|
|
88 /** Indicates whether the scroll bar thumb has been grabbed. */
|
|
89 private bool fScrollbarClicked= false;
|
|
90 /**
|
|
91 * The shell on which some listeners are registered.
|
|
92 * @since 3.1
|
|
93 */
|
|
94 private Shell fShell;
|
|
95 /**
|
|
96 * The display on which some filters are registered.
|
|
97 * @since 3.4
|
|
98 */
|
|
99 private Display fDisplay;
|
|
100 /**
|
|
101 * The additional info controller, or <code>null</code>.
|
|
102 * @since 3.4
|
|
103 */
|
|
104 private AdditionalInfoController fAdditionalInfoController;
|
|
105
|
|
106 /**
|
|
107 * Installs this closer on the given table opened by the given content assistant.
|
|
108 *
|
|
109 * @param contentAssistant the content assistant
|
|
110 * @param table the table to be tracked
|
|
111 */
|
|
112 public void install(ContentAssistant contentAssistant, Table table) {
|
|
113 install(contentAssistant, table, null);
|
|
114 }
|
|
115
|
|
116 /**
|
|
117 * Installs this closer on the given table opened by the given content assistant.
|
|
118 *
|
|
119 * @param contentAssistant the content assistant
|
|
120 * @param table the table to be tracked
|
|
121 * @param additionalInfoController the additional info controller, or <code>null</code>
|
|
122 * @since 3.4
|
|
123 */
|
|
124 public void install(ContentAssistant contentAssistant, Table table, AdditionalInfoController additionalInfoController) {
|
|
125 fContentAssistant= contentAssistant;
|
|
126 fTable= table;
|
|
127 fAdditionalInfoController= additionalInfoController;
|
|
128
|
|
129 if (Helper.okToUse(fTable)) {
|
|
130 fShell= fTable.getShell();
|
|
131 fDisplay= fShell.getDisplay();
|
|
132
|
|
133 fShell.addShellListener(this);
|
|
134 fTable.addFocusListener(this);
|
|
135 fScrollbar= fTable.getVerticalBar();
|
|
136 if (fScrollbar !is null)
|
|
137 fScrollbar.addSelectionListener(this);
|
|
138
|
|
139 fDisplay.addFilter(DWT.Activate, this);
|
|
140 fDisplay.addFilter(DWT.MouseWheel, this);
|
|
141
|
|
142 fDisplay.addFilter(DWT.Deactivate, this);
|
|
143
|
|
144 fDisplay.addFilter(DWT.MouseUp, this);
|
|
145 }
|
|
146 }
|
|
147
|
|
148 /**
|
|
149 * Uninstalls this closer if previously installed.
|
|
150 */
|
|
151 public void uninstall() {
|
|
152 fContentAssistant= null;
|
|
153 if (Helper.okToUse(fShell))
|
|
154 fShell.removeShellListener(this);
|
|
155 fShell= null;
|
|
156 if (Helper.okToUse(fScrollbar))
|
|
157 fScrollbar.removeSelectionListener(this);
|
|
158 if (Helper.okToUse(fTable))
|
|
159 fTable.removeFocusListener(this);
|
|
160 if (fDisplay !is null && ! fDisplay.isDisposed()) {
|
|
161 fDisplay.removeFilter(DWT.Activate, this);
|
|
162 fDisplay.removeFilter(DWT.MouseWheel, this);
|
|
163
|
|
164 fDisplay.removeFilter(DWT.Deactivate, this);
|
|
165
|
|
166 fDisplay.removeFilter(DWT.MouseUp, this);
|
|
167 }
|
|
168 }
|
|
169
|
|
170 /*
|
|
171 * @see dwt.events.SelectionListener#widgetSelected(dwt.events.SelectionEvent)
|
|
172 */
|
|
173 public void widgetSelected(SelectionEvent e) {
|
|
174 fScrollbarClicked= true;
|
|
175 }
|
|
176
|
|
177 /*
|
|
178 * @see dwt.events.SelectionListener#widgetDefaultSelected(dwt.events.SelectionEvent)
|
|
179 */
|
|
180 public void widgetDefaultSelected(SelectionEvent e) {
|
|
181 fScrollbarClicked= true;
|
|
182 }
|
|
183
|
|
184 /*
|
|
185 * @see dwt.events.FocusListener#focusGained(dwt.events.FocusEvent)
|
|
186 */
|
|
187 public void focusGained(FocusEvent e) {
|
|
188 }
|
|
189
|
|
190 /*
|
|
191 * @see dwt.events.FocusListener#focusLost(dwt.events.FocusEvent)
|
|
192 */
|
|
193 public void focusLost(final FocusEvent e) {
|
|
194 fScrollbarClicked= false;
|
|
195 Display d= fTable.getDisplay();
|
|
196 d.asyncExec(new Runnable() {
|
|
197 public void run() {
|
|
198 if (Helper.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked && fContentAssistant !is null)
|
|
199 fContentAssistant.popupFocusLost(e);
|
|
200 }
|
|
201 });
|
|
202 }
|
|
203
|
|
204 /*
|
|
205 * @see dwt.events.ShellAdapter#shellDeactivated(dwt.events.ShellEvent)
|
|
206 * @since 3.1
|
|
207 */
|
|
208 public void shellDeactivated(ShellEvent e) {
|
|
209 if (fContentAssistant !is null && ! fContentAssistant.hasProposalPopupFocus())
|
|
210 fContentAssistant.hide();
|
|
211 }
|
|
212
|
|
213
|
|
214 /*
|
|
215 * @see dwt.events.ShellAdapter#shellClosed(dwt.events.ShellEvent)
|
|
216 * @since 3.1
|
|
217 */
|
|
218 public void shellClosed(ShellEvent e) {
|
|
219 if (fContentAssistant !is null)
|
|
220 fContentAssistant.hide();
|
|
221 }
|
|
222
|
|
223 /*
|
|
224 * @see dwt.widgets.Listener#handleEvent(dwt.widgets.Event)
|
|
225 * @since 3.4
|
|
226 */
|
|
227 public void handleEvent(Event event) {
|
|
228 switch (event.type) {
|
|
229 case DWT.Activate:
|
|
230 case DWT.MouseWheel:
|
|
231 if (fAdditionalInfoController is null)
|
|
232 return;
|
|
233 if (event.widget is fShell || event.widget is fTable || event.widget is fScrollbar)
|
|
234 return;
|
|
235
|
|
236 if (fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer() is null)
|
|
237 fAdditionalInfoController.hideInformationControl();
|
|
238 else if (!fAdditionalInfoController.getInternalAccessor().isReplaceInProgress()) {
|
|
239 IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2();
|
|
240 // During isReplaceInProgress(), events can come from the replacing information control
|
|
241 if (event.widget instanceof Control && infoControl instanceof IInformationControlExtension5) {
|
134
|
242 Control control= cast(Control) event.widget;
|
|
243 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) infoControl;
|
129
|
244 if (!(iControl5.containsControl(control)))
|
|
245 fAdditionalInfoController.hideInformationControl();
|
|
246 else if (event.type is DWT.MouseWheel)
|
|
247 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(false);
|
|
248 } else if (infoControl !is null && infoControl.isFocusControl()) {
|
|
249 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true);
|
|
250 }
|
|
251 }
|
|
252 break;
|
|
253
|
|
254 case DWT.MouseUp:
|
|
255 if (fAdditionalInfoController is null || fAdditionalInfoController.getInternalAccessor().isReplaceInProgress())
|
|
256 break;
|
|
257 if (event.widget instanceof Control) {
|
134
|
258 Control control= cast(Control) event.widget;
|
129
|
259 IInformationControl infoControl= fAdditionalInfoController.getCurrentInformationControl2();
|
|
260 if (infoControl instanceof IInformationControlExtension5) {
|
134
|
261 final IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) infoControl;
|
129
|
262 if (iControl5.containsControl(control)) {
|
|
263 if (infoControl instanceof IDelayedInputChangeProvider) {
|
134
|
264 final IDelayedInputChangeProvider delayedICP= cast(IDelayedInputChangeProvider) infoControl;
|
129
|
265 final IInputChangedListener inputChangeListener= new DelayedInputChangeListener(delayedICP, fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer());
|
|
266 delayedICP.setDelayedInputChangeListener(inputChangeListener);
|
|
267 // cancel automatic input updating after a small timeout:
|
|
268 control.getShell().getDisplay().timerExec(1000, new Runnable() {
|
|
269 public void run() {
|
|
270 delayedICP.setDelayedInputChangeListener(null);
|
|
271 }
|
|
272 });
|
|
273 }
|
|
274
|
|
275 // XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=212392 :
|
|
276 control.getShell().getDisplay().asyncExec(new Runnable() {
|
|
277 public void run() {
|
|
278 fAdditionalInfoController.getInternalAccessor().replaceInformationControl(true);
|
|
279 }
|
|
280 });
|
|
281 }
|
|
282 }
|
|
283 }
|
|
284 break;
|
|
285
|
|
286 case DWT.Deactivate:
|
|
287 if (fAdditionalInfoController is null)
|
|
288 break;
|
|
289 InformationControlReplacer replacer= fAdditionalInfoController.getInternalAccessor().getInformationControlReplacer();
|
|
290 if (replacer !is null && fContentAssistant !is null) {
|
|
291 IInformationControl iControl= replacer.getCurrentInformationControl2();
|
|
292 if (event.widget instanceof Control && iControl instanceof IInformationControlExtension5) {
|
134
|
293 Control control= cast(Control) event.widget;
|
|
294 IInformationControlExtension5 iControl5= cast(IInformationControlExtension5) iControl;
|
129
|
295 if (iControl5.containsControl(control)) {
|
|
296 control.getDisplay().asyncExec(new Runnable() {
|
|
297 public void run() {
|
|
298 if (fContentAssistant !is null && ! fContentAssistant.hasProposalPopupFocus())
|
|
299 fContentAssistant.hide();
|
|
300 }
|
|
301 });
|
|
302 }
|
|
303 }
|
|
304 }
|
|
305 break;
|
|
306 }
|
|
307 }
|
|
308 }
|