KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > sourcelookup > Prompter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.sourcelookup;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.core.runtime.Status;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.IStatusHandler;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
19 import org.eclipse.debug.ui.IDebugUIConstants;
20 import org.eclipse.swt.widgets.Display;
21
22 /**
23  * Prompts the user in the UI (asynchronously), on behalf of a non-UI client,
24  * blocking the calling thread until a response is received.
25  * <p>
26  * This status handler is registered for for the debug UI plug-in,
27  * with a status code of <code>STATUS_HANDLER_PROMPT</code>.
28  * </p>
29  * @since 3.0
30  */

31 public class Prompter implements IStatusHandler {
32     /**
33      * Prompts the user for input based on the given status and source
34      * object, blocking the calling thread until the status is resolved.
35      *
36      * @param status client status code for which a status handler must
37      * be registered
38      * @param source object requesting the status to be resolved
39      * @return result of resolving the given status
40      * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
41      */

42     public Object JavaDoc handleStatus(final IStatus status, final Object JavaDoc source) throws CoreException {
43         DebugPlugin dp = DebugPlugin.getDefault();
44         // on shutdown the debug plug-in can be null
45
if (dp == null) {
46             throw new CoreException(new Status(IStatus.INFO,
47                     IDebugUIConstants.PLUGIN_ID,
48                     IStatus.OK,
49                     SourceLookupUIMessages.Prompter_0,
50                     null));
51         }
52         final IStatusHandler handler = dp.getStatusHandler(status);
53         if (handler == null) {
54             throw new CoreException(new Status(IStatus.ERROR,
55                                     IDebugUIConstants.PLUGIN_ID,
56                                     IStatus.OK,
57                                     SourceLookupUIMessages.Prompter_0,
58                                     null));
59         }
60         Display display = DebugUIPlugin.getStandardDisplay();
61         if (display.getThread().equals(Thread.currentThread())) {
62             return handler.handleStatus(status, source);
63         }
64         final Object JavaDoc[] result = new Object JavaDoc[1];
65         final CoreException[] exception = new CoreException[1];
66         final Object JavaDoc lock = this;
67         Runnable JavaDoc r = new Runnable JavaDoc() {
68             public void run() {
69                 try {
70                     result[0] = handler.handleStatus(status, source);
71                 } catch (CoreException e) {
72                     exception[0] = e;
73                 }
74                 synchronized (lock) {
75                     lock.notifyAll();
76                 }
77             }
78         };
79         DebugUIPlugin.getStandardDisplay().syncExec(r);
80         
81         if (exception[0] != null ) {
82             throw exception[0];
83         }
84         return result[0];
85     }
86 }
87
Popular Tags