1 /******************************************************************************* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * Nokia Corporation - initial implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 package org.eclipse.swt.internal.extension; |
|
13 |
|
14 import org.eclipse.swt.internal.qt.UIThreadManager; |
|
15 |
|
16 /** |
|
17 * A class that provides services for transferring the control over the |
|
18 * execution of the UI thread to the application, and services for obtaining |
|
19 * notifications of the state of the UI until the UI thread will return back to the |
|
20 * caller. |
|
21 * |
|
22 * @see InternalUI |
|
23 * @see ApplicationUIListener |
|
24 */ |
|
25 public final class ApplicationUI { |
|
26 |
|
27 /** |
|
28 * Hand over the execution of the UI thread to the application. If the |
|
29 * application has not yet requested the UI thread then it will be waiting |
|
30 * until that happens. The waiting can be aborted by calling |
|
31 * <code>abortWait()</code>. |
|
32 * |
|
33 * The control of the thread will be passed to the application. If the |
|
34 * application allows the UI thread to return then this method will also |
|
35 * return. |
|
36 * |
|
37 * After calling this method and before the method has returned the state of |
|
38 * the UI thread can be tracked by setting an |
|
39 * <code>ApplicationUIListener</code>. |
|
40 */ |
|
41 public static void run() { |
|
42 UIThreadManager.runApplicationUI(); |
|
43 } |
|
44 |
|
45 /** |
|
46 * Aborts waiting the application to request the UI thread. This waiting can |
|
47 * occur after <code>run()</code> has been called if the application has not |
|
48 * yet at that point requested the UI thread and thus has not provided the |
|
49 * Runnable to call back. Aborting the waiting will cause the UI thread to |
|
50 * return from <code>run()</code>. If the application already obtained the |
|
51 * control of the UI thread then this method does nothing. |
|
52 */ |
|
53 public static void abortWait() { |
|
54 UIThreadManager.abortWait(); |
|
55 } |
|
56 |
|
57 /** |
|
58 * Sets the listener that will be notified of the state of the UI during its |
|
59 * life-cycle under the application's control. |
|
60 * |
|
61 * @param listener The listener, or null to disable the notifications |
|
62 */ |
|
63 public static void setListener(ApplicationUIListener listener) { |
|
64 final ApplicationUIListener applicationUIListener = listener; |
|
65 org.eclipse.swt.internal.qt.ApplicationUIListener internalListener; |
|
66 if(listener != null) { |
|
67 internalListener = new org.eclipse.swt.internal.qt.ApplicationUIListener() { |
|
68 public void applicationUIThreadRequest() { |
|
69 applicationUIListener.applicationUIThreadRequest(); |
|
70 } |
|
71 }; |
|
72 } else { |
|
73 internalListener = null; |
|
74 } |
|
75 UIThreadManager.setApplicationUIListener(internalListener); |
|
76 } |
|
77 } |
|