Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c2aad191b63e84562d8fce1d99f4fac74f25c696 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.debug.internal.ui.sourcelookup;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IStatusHandler;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.swt.widgets.Display;

/**
 * Prompts the user in the UI (asynchronously), on behalf of a non-UI client,
 * blocking the calling thread until a response is received.
 * <p>
 * This status handler is registered for for the debug UI plug-in,
 * with a status code of <code>STATUS_HANDLER_PROMPT</code>.
 * </p>
 * @since 3.0
 */
public class Prompter implements IStatusHandler {
	/**
	 * Prompts the user for input based on the given status and source
	 * object, blocking the calling thread until the status is resolved.
	 *
	 * @param status client status code for which a status handler must
	 *  be registered
	 * @param source object requesting the status to be resolved
	 * @return result of resolving the given status
	 * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
	 */
	@Override
	public Object handleStatus(final IStatus status, final Object source) throws CoreException {
		DebugPlugin dp = DebugPlugin.getDefault();
		// on shutdown the debug plug-in can be null
		if (dp == null) {
			throw new CoreException(new Status(IStatus.INFO,
					IDebugUIConstants.PLUGIN_ID,
					IStatus.OK,
					SourceLookupUIMessages.Prompter_0,
					null));
		}
		final IStatusHandler handler = dp.getStatusHandler(status);
		if (handler == null) {
			throw new CoreException(new Status(IStatus.ERROR,
									IDebugUIConstants.PLUGIN_ID,
									IStatus.OK,
									SourceLookupUIMessages.Prompter_0,
									null));
		}
		Display display = DebugUIPlugin.getStandardDisplay();
		if (display.getThread().equals(Thread.currentThread())) {
			return handler.handleStatus(status, source);
		}
		final Object[] result = new Object[1];
		final CoreException[] exception = new CoreException[1];
		final Object lock = this;
		Runnable r = new Runnable() {
			@Override
			public void run() {
				try {
					result[0] = handler.handleStatus(status, source);
				} catch (CoreException e) {
					exception[0] = e;
				}
				synchronized (lock) {
					lock.notifyAll();
				}
			}
		};
		DebugUIPlugin.getStandardDisplay().syncExec(r);

		if (exception[0] != null ) {
			throw exception[0];
		}
		return result[0];
	}
}

Back to the top