Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 226052 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/ui/dialogs/DeferredFetchFilteredTree.java (-32 / +56 lines)
Lines 10-15 Link Here
10
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentListener;
10
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentListener;
11
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentProvider;
11
import org.eclipse.equinox.internal.provisional.p2.ui.viewers.DeferredQueryContentProvider;
12
import org.eclipse.jface.action.MenuManager;
12
import org.eclipse.jface.action.MenuManager;
13
import org.eclipse.jface.dialogs.ControlEnableState;
13
import org.eclipse.jface.dialogs.PopupDialog;
14
import org.eclipse.jface.dialogs.PopupDialog;
14
import org.eclipse.jface.resource.JFaceResources;
15
import org.eclipse.jface.resource.JFaceResources;
15
import org.eclipse.jface.viewers.TreeViewer;
16
import org.eclipse.jface.viewers.TreeViewer;
Lines 34-40 Link Here
34
 *
35
 *
35
 */
36
 */
36
public class DeferredFetchFilteredTree extends FilteredTree {
37
public class DeferredFetchFilteredTree extends FilteredTree {
37
	private static final long FILTER_DELAY_TIME = 200;
38
	private static final String WAIT_STRING = ProvUIMessages.DeferredFetchFilteredTree_RetrievingList;
38
	private static final String WAIT_STRING = ProvUIMessages.DeferredFetchFilteredTree_RetrievingList;
39
39
40
	ToolBar toolBar;
40
	ToolBar toolBar;
Lines 49-54 Link Here
49
	String savedFilterText;
49
	String savedFilterText;
50
	Job loadJob;
50
	Job loadJob;
51
	WorkbenchJob filterJob;
51
	WorkbenchJob filterJob;
52
	ControlEnableState enableState;
52
53
53
	class InputSchedulingRule implements ISchedulingRule {
54
	class InputSchedulingRule implements ISchedulingRule {
54
		Object input;
55
		Object input;
Lines 175-182 Link Here
175
				contentProvider.setSynchronous(false);
176
				contentProvider.setSynchronous(false);
176
177
177
				if (showFilterControls && filterText != null && !filterText.isDisposed()) {
178
				if (showFilterControls && filterText != null && !filterText.isDisposed()) {
178
					filterText.setText(getInitialText());
179
					// We cancelled the load and if it was in progress the filter
179
					filterText.selectAll();
180
					// would have been disabled.  
181
					restoreAfterLoading(getInitialText());
180
				}
182
				}
181
			}
183
			}
182
184
Lines 192-197 Link Here
192
		filterJob = super.doCreateRefreshJob();
194
		filterJob = super.doCreateRefreshJob();
193
		filterJob.addJobChangeListener(new JobChangeAdapter() {
195
		filterJob.addJobChangeListener(new JobChangeAdapter() {
194
			public void aboutToRun(final IJobChangeEvent event) {
196
			public void aboutToRun(final IJobChangeEvent event) {
197
				final boolean[] shouldLoad = new boolean[1];
198
				shouldLoad[0] = false;
195
				display.syncExec(new Runnable() {
199
				display.syncExec(new Runnable() {
196
					public void run() {
200
					public void run() {
197
						String text = getFilterString();
201
						String text = getFilterString();
Lines 202-250 Link Here
202
						// load job to complete before continuing with filtering.
206
						// load job to complete before continuing with filtering.
203
						if (text == null || (initialText != null && initialText.equals(text)))
207
						if (text == null || (initialText != null && initialText.equals(text)))
204
							return;
208
							return;
205
						if (!contentProvider.getSynchronous()) {
209
						if (!contentProvider.getSynchronous() && loadJob == null) {
206
							if (filterText != null && !filterText.isDisposed()) {
210
							if (filterText != null && !filterText.isDisposed()) {
207
								filterText.setEnabled(false);
211
								disableWhileLoading();
208
								filterText.setCursor(display.getSystemCursor(SWT.CURSOR_WAIT));
212
								shouldLoad[0] = true;
209
								savedFilterText = filterText.getText();
210
								filterText.setText(WAIT_STRING);
211
							}
213
							}
212
							event.getJob().sleep();
213
							scheduleLoadJob();
214
							event.getJob().wakeUp(FILTER_DELAY_TIME);
215
							contentProvider.setSynchronous(true);
216
						}
214
						}
217
					}
215
					}
218
				});
216
				});
219
			}
217
				if (shouldLoad[0]) {
220
218
					event.getJob().sleep();
221
			public void done(IJobChangeEvent event) {
219
					scheduleLoadJob();
222
				display.asyncExec(new Runnable() {
220
				}
223
					public void run() {
224
						restoreFilterText();
225
					}
226
				});
227
			}
228
221
229
			public void awake(IJobChangeEvent event) {
230
				display.asyncExec(new Runnable() {
231
					public void run() {
232
						restoreFilterText();
233
					}
234
				});
235
			}
222
			}
236
		});
223
		});
237
		filterJob.setRule(getFilterJobSchedulingRule());
224
		filterJob.setRule(getFilterJobSchedulingRule());
238
		return filterJob;
225
		return filterJob;
239
	}
226
	}
240
227
241
	void restoreFilterText() {
228
	void disableWhileLoading() {
229
		// We already disabled.
230
		if (enableState != null)
231
			return;
232
		// TODO Knowledge of our client's parent structure is cheating
233
		// but for now our only usage is in one particular widget tree and
234
		// we want to disable at the right place.
235
		if (parent != null && !parent.isDisposed()) {
236
			enableState = ControlEnableState.disable(parent.getParent());
237
		}
238
		if (filterText != null && !filterText.isDisposed()) {
239
			filterText.setCursor(display.getSystemCursor(SWT.CURSOR_WAIT));
240
			savedFilterText = filterText.getText();
241
			filterText.setText(WAIT_STRING);
242
		}
243
244
	}
245
246
	void restoreAfterLoading(String filterTextToRestore) {
242
		if (filterText != null && !filterText.isDisposed() && !filterText.isEnabled()) {
247
		if (filterText != null && !filterText.isDisposed() && !filterText.isEnabled()) {
243
			filterText.setText(savedFilterText);
248
			filterText.setText(filterTextToRestore);
244
			filterText.setEnabled(true);
245
			filterText.setCursor(null);
249
			filterText.setCursor(null);
246
			filterText.setFocus();
250
			filterText.setFocus();
247
			filterText.setSelection(savedFilterText.length(), savedFilterText.length());
251
			filterText.setSelection(filterTextToRestore.length(), filterTextToRestore.length());
252
		}
253
		if (enableState != null && parent != null && !parent.isDisposed()) {
254
			enableState.restore();
255
			enableState = null;
248
		}
256
		}
249
	}
257
	}
250
258
Lines 259-265 Link Here
259
	}
267
	}
260
268
261
	void scheduleLoadJob() {
269
	void scheduleLoadJob() {
262
		cancelLoadJob();
270
		if (loadJob != null)
271
			return;
263
		loadJob = new Job(WAIT_STRING) {
272
		loadJob = new Job(WAIT_STRING) {
264
			protected IStatus run(IProgressMonitor monitor) {
273
			protected IStatus run(IProgressMonitor monitor) {
265
				if (this.getRule() instanceof InputSchedulingRule) {
274
				if (this.getRule() instanceof InputSchedulingRule) {
Lines 275-280 Link Here
275
				return Status.OK_STATUS;
284
				return Status.OK_STATUS;
276
			}
285
			}
277
		};
286
		};
287
		loadJob.addJobChangeListener(new JobChangeAdapter() {
288
			public void done(IJobChangeEvent event) {
289
				if (event.getResult().isOK()) {
290
					contentProvider.setSynchronous(true);
291
					display.asyncExec(new Runnable() {
292
						public void run() {
293
							restoreAfterLoading(savedFilterText);
294
						}
295
					});
296
					if (filterJob != null)
297
						filterJob.wakeUp();
298
				}
299
				loadJob = null;
300
			}
301
		});
278
		loadJob.setSystem(true);
302
		loadJob.setSystem(true);
279
		loadJob.setUser(false);
303
		loadJob.setUser(false);
280
		loadJob.setRule(getFilterJobSchedulingRule());
304
		loadJob.setRule(getFilterJobSchedulingRule());

Return to bug 226052