Mercurial > projects > dwt-win
annotate dwt/custom/BusyIndicator.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | 184ab53b7785 |
children | fd9c62a2998e |
rev | line source |
---|---|
155 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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 dwt.custom.BusyIndicator; | |
14 | |
15 | |
16 | |
17 import dwt.DWT; | |
18 import dwt.graphics.Cursor; | |
19 import dwt.widgets.Display; | |
20 import dwt.widgets.Shell; | |
197
184ab53b7785
Changes and fixes for jface
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
21 import dwt.dwthelper.utils; |
155 | 22 import dwt.dwthelper.Runnable; |
23 | |
24 /** | |
25 * Support for showing a Busy Cursor during a long running process. | |
26 */ | |
27 public class BusyIndicator { | |
28 | |
29 static int nextBusyId = 1; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
30 static const String BUSYID_NAME = "DWT BusyIndicator"; //$NON-NLS-1$ |
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
31 static const String BUSY_CURSOR = "DWT BusyIndicator Cursor"; //$NON-NLS-1$ |
155 | 32 |
33 /** | |
34 * Runs the given <code>Runnable</code> while providing | |
35 * busy feedback using this busy indicator. | |
36 * | |
37 * @param display the display on which the busy feedback should be | |
38 * displayed. If the display is null, the Display for the current | |
39 * thread will be used. If there is no Display for the current thread, | |
40 * the runnable code will be executed and no busy feedback will be displayed. | |
41 * @param runnable the runnable for which busy feedback is to be shown. | |
42 * Must not be null. | |
43 * | |
44 * @exception IllegalArgumentException <ul> | |
45 * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> | |
46 * </ul> | |
47 */ | |
48 | |
49 public static void showWhile(Display display, Runnable runnable) { | |
50 if (runnable is null) | |
51 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
52 if (display is null) { | |
53 display = Display.getCurrent(); | |
54 if (display is null) { | |
55 runnable.run(); | |
56 return; | |
57 } | |
58 } | |
59 | |
60 Integer busyId = new Integer(nextBusyId); | |
61 nextBusyId++; | |
62 Cursor cursor = display.getSystemCursor(DWT.CURSOR_WAIT); | |
63 Shell[] shells = display.getShells(); | |
64 for (int i = 0; i < shells.length; i++) { | |
65 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME); | |
66 if (id is null) { | |
67 shells[i].setCursor(cursor); | |
68 shells[i].setData(BUSYID_NAME, busyId); | |
69 } | |
70 } | |
71 | |
72 try { | |
73 runnable.run(); | |
74 } finally { | |
75 shells = display.getShells(); | |
76 for (int i = 0; i < shells.length; i++) { | |
77 Integer id = cast(Integer)shells[i].getData(BUSYID_NAME); | |
78 if ( id !is null && id == busyId) { | |
79 shells[i].setCursor(null); | |
80 shells[i].setData(BUSYID_NAME, null); | |
81 } | |
82 } | |
83 } | |
84 } | |
85 } |