Mercurial > projects > dwt-addons
annotate dwtx/jface/dialogs/ProgressMonitorDialog.d @ 88:cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 21 Jun 2008 15:29:48 +0200 |
parents | 8d1a6e501ea4 |
children |
rev | line source |
---|---|
23 | 1 /******************************************************************************* |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
23 | 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 dwtx.jface.dialogs.ProgressMonitorDialog; | |
14 | |
15 import dwtx.jface.dialogs.IconAndMessageDialog; | |
16 import dwtx.jface.dialogs.IDialogConstants; | |
17 import dwtx.jface.dialogs.ProgressIndicator; | |
18 | |
19 // import java.lang.reflect.InvocationTargetException; | |
20 | |
21 import dwt.DWT; | |
22 import dwt.graphics.Cursor; | |
23 import dwt.graphics.Image; | |
24 import dwt.graphics.Point; | |
25 import dwt.layout.GridData; | |
26 import dwt.widgets.Button; | |
27 import dwt.widgets.Composite; | |
28 import dwt.widgets.Control; | |
29 import dwt.widgets.Event; | |
30 import dwt.widgets.Label; | |
31 import dwt.widgets.Listener; | |
32 import dwt.widgets.Shell; | |
33 import dwtx.core.runtime.IProgressMonitor; | |
34 import dwtx.core.runtime.IProgressMonitorWithBlocking; | |
35 import dwtx.core.runtime.IStatus; | |
36 import dwtx.jface.operation.IRunnableContext; | |
37 import dwtx.jface.operation.IRunnableWithProgress; | |
38 import dwtx.jface.operation.ModalContext; | |
39 import dwtx.jface.resource.JFaceResources; | |
40 | |
41 import dwt.dwthelper.utils; | |
42 import dwt.dwthelper.Runnable; | |
43 | |
44 /** | |
45 * A modal dialog that displays progress during a long running operation. | |
46 * <p> | |
47 * This concrete dialog class can be instantiated as is, or further subclassed | |
48 * as required. | |
49 * </p> | |
50 * <p> | |
51 * Typical usage is: | |
52 * | |
53 * <pre> | |
54 * | |
55 * | |
56 * try { | |
57 * IRunnableWithProgress op = ...; | |
58 * new ProgressMonitorDialog(activeShell).run(true, true, op); | |
59 * } catch (InvocationTargetException e) { | |
60 * // handle exception | |
61 * } catch (InterruptedException e) { | |
62 * // handle cancelation | |
63 * } | |
64 * | |
65 * | |
66 * </pre> | |
67 * | |
68 * </p> | |
69 * <p> | |
70 * Note that the ProgressMonitorDialog is not intended to be used with multiple | |
71 * runnables - this dialog should be discarded after completion of one | |
72 * IRunnableWithProgress and a new one instantiated for use by a second or | |
73 * sebsequent IRunnableWithProgress to ensure proper initialization. | |
74 * </p> | |
75 * <p> | |
76 * Note that not forking the process will result in it running in the UI which | |
77 * may starve the UI. The most obvious symptom of this problem is non | |
78 * responsiveness of the cancel button. If you are running within the UI Thread | |
79 * you should do the bulk of your work in another Thread to prevent starvation. | |
80 * It is recommended that fork is set to true in most cases. | |
81 * </p> | |
82 */ | |
83 public class ProgressMonitorDialog : IconAndMessageDialog, | |
84 IRunnableContext { | |
85 /** | |
86 * Name to use for task when normal task name is empty string. | |
87 */ | |
88 private static String DEFAULT_TASKNAME; | |
89 | |
90 static this() { | |
91 DEFAULT_TASKNAME = JFaceResources | |
92 .getString("ProgressMonitorDialog.message"); //$NON-NLS-1$ | |
93 } | |
94 /** | |
95 * Constants for label and monitor size | |
96 */ | |
97 private static int LABEL_DLUS = 21; | |
98 | |
99 private static int BAR_DLUS = 9; | |
100 | |
101 /** | |
102 * The progress indicator control. | |
103 */ | |
104 protected ProgressIndicator progressIndicator; | |
105 | |
106 /** | |
107 * The label control for the task. Kept for backwards compatibility. | |
108 */ | |
109 protected Label taskLabel; | |
110 | |
111 /** | |
112 * The label control for the subtask. | |
113 */ | |
114 protected Label subTaskLabel; | |
115 | |
116 /** | |
117 * The Cancel button control. | |
118 */ | |
119 protected Button cancel; | |
120 | |
121 /** | |
122 * Indicates whether the Cancel button is to be shown. | |
123 */ | |
124 protected bool operationCancelableState = false; | |
125 | |
126 /** | |
127 * Indicates whether the Cancel button is to be enabled. | |
128 */ | |
129 protected bool enableCancelButton; | |
130 | |
131 /** | |
132 * The progress monitor. | |
133 */ | |
134 private ProgressMonitor progressMonitor; | |
135 | |
136 /** | |
137 * The name of the current task (used by ProgressMonitor). | |
138 */ | |
139 private String task; | |
140 | |
141 /** | |
142 * The nesting depth of currently running runnables. | |
143 */ | |
144 private int nestingDepth; | |
145 | |
146 /** | |
147 * The cursor used in the cancel button; | |
148 */ | |
149 protected Cursor arrowCursor; | |
150 | |
151 /** | |
152 * The cursor used in the shell; | |
153 */ | |
154 private Cursor waitCursor; | |
155 | |
156 /** | |
157 * Flag indicating whether to open or merely create the dialog before run. | |
158 */ | |
159 private bool openOnRun = true; | |
160 | |
161 /** | |
162 * Internal progress monitor implementation. | |
163 */ | |
164 private class ProgressMonitor : IProgressMonitorWithBlocking { | |
165 private String fSubTask = "";//$NON-NLS-1$ | |
166 | |
167 private bool fIsCanceled; | |
168 | |
169 /** | |
170 * is the process forked | |
171 */ | |
172 protected bool forked = false; | |
173 | |
174 /** | |
175 * is locked | |
176 */ | |
177 protected bool locked = false; | |
178 | |
179 public void beginTask(String name, int totalWork) { | |
180 if (progressIndicator.isDisposed()) { | |
181 return; | |
182 } | |
183 if (name is null) { | |
184 task = "";//$NON-NLS-1$ | |
185 } else { | |
186 task = name; | |
187 } | |
188 String s = task; | |
189 if (s.length <= 0) { | |
190 s = DEFAULT_TASKNAME; | |
191 } | |
192 setMessage(s, false); | |
193 if (!forked) { | |
194 update(); | |
195 } | |
196 if (totalWork is UNKNOWN) { | |
197 progressIndicator.beginAnimatedTask(); | |
198 } else { | |
199 progressIndicator.beginTask(totalWork); | |
200 } | |
201 } | |
202 | |
203 public void done() { | |
204 if (!progressIndicator.isDisposed()) { | |
205 progressIndicator.sendRemainingWork(); | |
206 progressIndicator.done(); | |
207 } | |
208 } | |
209 | |
210 public void setTaskName(String name) { | |
211 if (name is null) { | |
212 task = "";//$NON-NLS-1$ | |
213 } else { | |
214 task = name; | |
215 } | |
216 String s = task; | |
217 if (s.length <= 0) { | |
218 s = DEFAULT_TASKNAME; | |
219 } | |
220 setMessage(s, false); | |
221 if (!forked) { | |
222 update(); | |
223 } | |
224 } | |
225 | |
226 public bool isCanceled() { | |
227 return fIsCanceled; | |
228 } | |
229 | |
230 public void setCanceled(bool b) { | |
231 fIsCanceled = b; | |
232 if (locked) { | |
233 clearBlocked(); | |
234 } | |
235 } | |
236 | |
237 public void subTask(String name) { | |
238 if (subTaskLabel.isDisposed()) { | |
239 return; | |
240 } | |
241 if (name is null) { | |
242 fSubTask = "";//$NON-NLS-1$ | |
243 } else { | |
244 fSubTask = name; | |
245 } | |
246 subTaskLabel.setText(shortenText(fSubTask, subTaskLabel)); | |
247 if (!forked) { | |
248 subTaskLabel.update(); | |
249 } | |
250 } | |
251 | |
252 public void worked(int work) { | |
253 internalWorked(work); | |
254 } | |
255 | |
256 public void internalWorked(double work) { | |
257 if (!progressIndicator.isDisposed()) { | |
258 progressIndicator.worked(work); | |
259 } | |
260 } | |
261 | |
262 /* | |
263 * (non-Javadoc) | |
264 * | |
265 * @see dwtx.core.runtime.IProgressMonitorWithBlocking#clearBlocked() | |
266 */ | |
267 public void clearBlocked() { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
268 if (getShell().isDisposed()) |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
269 return; |
23 | 270 locked = false; |
271 updateForClearBlocked(); | |
272 } | |
273 | |
274 /* | |
275 * (non-Javadoc) | |
276 * | |
277 * @see dwtx.core.runtime.IProgressMonitorWithBlocking#setBlocked(dwtx.core.runtime.IStatus) | |
278 */ | |
279 public void setBlocked(IStatus reason) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
280 if (getShell().isDisposed()) |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
281 return; |
23 | 282 locked = true; |
283 updateForSetBlocked(reason); | |
284 } | |
285 } | |
286 | |
287 /** | |
288 * Clear blocked state from the receiver. | |
289 */ | |
290 protected void updateForClearBlocked() { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
291 progressIndicator.showNormal(); |
23 | 292 setMessage(task, true); |
293 imageLabel.setImage(getImage()); | |
83
028aedd523ad
Fix anon class segfault. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
294 |
23 | 295 } |
296 | |
297 /** | |
298 * Set blocked state from the receiver. | |
299 * | |
300 * @param reason | |
301 * IStatus that gives the details | |
302 */ | |
303 protected void updateForSetBlocked(IStatus reason) { | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
304 progressIndicator.showPaused(); |
23 | 305 setMessage(reason.getMessage(), true); |
306 imageLabel.setImage(getImage()); | |
83
028aedd523ad
Fix anon class segfault. Thanks yidabu for the report.
Frank Benoit <benoit@tionex.de>
parents:
70
diff
changeset
|
307 |
23 | 308 } |
309 | |
310 /** | |
311 * Creates a progress monitor dialog under the given shell. The dialog has a | |
312 * standard title and no image. <code>open</code> is non-blocking. | |
313 * | |
314 * @param parent | |
315 * the parent shell, or <code>null</code> to create a top-level | |
316 * shell | |
317 */ | |
318 public this(Shell parent) { | |
319 progressMonitor = new ProgressMonitor(); | |
320 super(parent); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
321 // no close button on the shell style |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
322 if (isResizable()) { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
323 setShellStyle(getDefaultOrientation() | DWT.BORDER | DWT.TITLE |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
324 | DWT.APPLICATION_MODAL | DWT.RESIZE | DWT.MAX); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
325 } else { |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
326 setShellStyle(getDefaultOrientation() | DWT.BORDER | DWT.TITLE |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
327 | DWT.APPLICATION_MODAL); |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
328 } |
23 | 329 setBlockOnOpen(false); |
330 } | |
331 | |
332 /** | |
333 * Enables the cancel button (asynchronously). | |
334 * | |
335 * @param b | |
336 * The state to set the button to. | |
337 */ | |
338 private void asyncSetOperationCancelButtonEnabled(bool b) { | |
339 if (getShell() !is null) { | |
340 getShell().getDisplay().asyncExec(new class Runnable { | |
341 bool b_; | |
342 this(){ b_=b; } | |
343 public void run() { | |
344 setOperationCancelButtonEnabled(b); | |
345 } | |
346 }); | |
347 } | |
348 } | |
349 | |
350 /** | |
351 * The cancel button has been pressed. | |
352 * | |
353 * @since 3.0 | |
354 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
355 protected override void cancelPressed() { |
23 | 356 // NOTE: this was previously done from a listener installed on the |
357 // cancel button. On GTK, the listener installed by | |
358 // Dialog.createButton is called first and this was throwing an | |
359 // exception because the cancel button was already disposed | |
360 cancel.setEnabled(false); | |
361 progressMonitor.setCanceled(true); | |
362 super.cancelPressed(); | |
363 } | |
364 | |
365 /* | |
366 * (non-Javadoc) Method declared on Window. | |
367 */ | |
368 /** | |
369 * The <code>ProgressMonitorDialog</code> implementation of this method | |
370 * only closes the dialog if there are no currently running runnables. | |
371 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
372 public override bool close() { |
23 | 373 if (getNestingDepth() <= 0) { |
374 clearCursors(); | |
375 return super.close(); | |
376 } | |
377 return false; | |
378 } | |
379 | |
380 /** | |
381 * Clear the cursors in the dialog. | |
382 * | |
383 * @since 3.0 | |
384 */ | |
385 protected void clearCursors() { | |
386 if (cancel !is null && !cancel.isDisposed()) { | |
387 cancel.setCursor(null); | |
388 } | |
389 Shell shell = getShell(); | |
390 if (shell !is null && !shell.isDisposed()) { | |
391 shell.setCursor(null); | |
392 } | |
393 if (arrowCursor !is null) { | |
394 arrowCursor.dispose(); | |
395 } | |
396 if (waitCursor !is null) { | |
397 waitCursor.dispose(); | |
398 } | |
399 arrowCursor = null; | |
400 waitCursor = null; | |
401 } | |
402 | |
403 /* | |
404 * (non-Javadoc) Method declared in Window. | |
405 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
406 protected override void configureShell(Shell shell) { |
23 | 407 super.configureShell(shell); |
408 shell.setText(JFaceResources.getString("ProgressMonitorDialog.title")); //$NON-NLS-1$ | |
409 if (waitCursor is null) { | |
410 waitCursor = new Cursor(shell.getDisplay(), DWT.CURSOR_WAIT); | |
411 } | |
412 shell.setCursor(waitCursor); | |
413 // Add a listener to set the message properly when the dialog becomes | |
414 // visible | |
88
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
415 // DWT FIXME: workaround for DMD 1.028 anon class problem |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
416 shell.addListener(DWT.Show, dgListener( &_handleEvent, shell)); |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
417 } |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
418 |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
419 // DWT FIXME: workaround for DMD 1.028 anon class problem |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
420 private void _handleEvent(Event event, Shell shell_) { |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
421 // We need to async the message update since the Show precedes |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
422 // visibility |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
423 shell_.getDisplay().asyncExec(dgRunnable( &_setMessage )); |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
424 } |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
425 // DWT FIXME: workaround for DMD 1.028 anon class problem |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
426 private void _setMessage() { |
cd18fa3b71f1
fix workaround anon class problem in dmd 1.028
Frank Benoit <benoit@tionex.de>
parents:
87
diff
changeset
|
427 setMessage(message, true); |
23 | 428 } |
429 | |
430 /* | |
431 * (non-Javadoc) Method declared on Dialog. | |
432 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
433 protected override void createButtonsForButtonBar(Composite parent) { |
23 | 434 // cancel button |
435 createCancelButton(parent); | |
436 } | |
437 | |
438 /** | |
439 * Creates the cancel button. | |
440 * | |
441 * @param parent | |
442 * the parent composite | |
443 * @since 3.0 | |
444 */ | |
445 protected void createCancelButton(Composite parent) { | |
446 cancel = createButton(parent, IDialogConstants.CANCEL_ID, | |
447 IDialogConstants.CANCEL_LABEL, true); | |
448 if (arrowCursor is null) { | |
449 arrowCursor = new Cursor(cancel.getDisplay(), DWT.CURSOR_ARROW); | |
450 } | |
451 cancel.setCursor(arrowCursor); | |
452 setOperationCancelButtonEnabled(enableCancelButton); | |
453 } | |
454 | |
455 /* | |
456 * (non-Javadoc) Method declared on Dialog. | |
457 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
458 protected override Control createDialogArea(Composite parent) { |
23 | 459 setMessage(DEFAULT_TASKNAME, false); |
460 createMessageArea(parent); | |
461 // Only set for backwards compatibility | |
462 taskLabel = messageLabel; | |
463 // progress indicator | |
464 progressIndicator = new ProgressIndicator(parent); | |
465 GridData gd = new GridData(); | |
466 gd.heightHint = convertVerticalDLUsToPixels(BAR_DLUS); | |
467 gd.horizontalAlignment = GridData.FILL; | |
468 gd.grabExcessHorizontalSpace = true; | |
469 gd.horizontalSpan = 2; | |
470 progressIndicator.setLayoutData(gd); | |
471 // label showing current task | |
472 subTaskLabel = new Label(parent, DWT.LEFT | DWT.WRAP); | |
473 gd = new GridData(GridData.FILL_HORIZONTAL); | |
474 gd.heightHint = convertVerticalDLUsToPixels(LABEL_DLUS); | |
475 gd.horizontalSpan = 2; | |
476 subTaskLabel.setLayoutData(gd); | |
477 subTaskLabel.setFont(parent.getFont()); | |
478 return parent; | |
479 } | |
480 | |
481 /* | |
482 * (non-Javadoc) | |
483 * | |
484 * @see dwtx.jface.window.Window#getInitialSize() | |
485 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
486 protected override Point getInitialSize() { |
23 | 487 Point calculatedSize = super.getInitialSize(); |
488 if (calculatedSize.x < 450) { | |
489 calculatedSize.x = 450; | |
490 } | |
491 return calculatedSize; | |
492 } | |
493 | |
494 /** | |
495 * Returns the progress monitor to use for operations run in this progress | |
496 * dialog. | |
497 * | |
498 * @return the progress monitor | |
499 */ | |
500 public IProgressMonitor getProgressMonitor() { | |
501 return progressMonitor; | |
502 } | |
503 | |
504 /** | |
505 * This implementation of IRunnableContext#run(bool, bool, | |
506 * IRunnableWithProgress) runs the given <code>IRunnableWithProgress</code> | |
507 * using the progress monitor for this progress dialog and blocks until the | |
508 * runnable has been run, regardless of the value of <code>fork</code>. | |
509 * The dialog is opened before the runnable is run, and closed after it | |
510 * completes. It is recommended that <code>fork</code> is set to true in | |
511 * most cases. If <code>fork</code> is set to <code>false</code>, the | |
512 * runnable will run in the UI thread and it is the runnable's | |
513 * responsibility to call <code>Display.readAndDispatch()</code> to ensure | |
514 * UI responsiveness. | |
515 */ | |
516 public void run(bool fork, bool cancelable, | |
517 IRunnableWithProgress runnable) { | |
518 setCancelable(cancelable); | |
519 try { | |
520 aboutToRun(); | |
521 // Let the progress monitor know if they need to update in UI Thread | |
522 progressMonitor.forked = fork; | |
523 ModalContext.run(runnable, fork, getProgressMonitor(), getShell() | |
524 .getDisplay()); | |
525 } finally { | |
526 finishedRun(); | |
527 } | |
528 } | |
529 | |
530 /** | |
531 * Returns whether the dialog should be opened before the operation is run. | |
532 * Defaults to <code>true</code> | |
533 * | |
534 * @return <code>true</code> to open the dialog before run, | |
535 * <code>false</code> to only create the dialog, but not open it | |
536 * @since 3.0 | |
537 */ | |
538 public bool getOpenOnRun() { | |
539 return openOnRun; | |
540 } | |
541 | |
542 /** | |
543 * Sets whether the dialog should be opened before the operation is run. | |
544 * NOTE: Setting this to false and not forking a process may starve any | |
545 * asyncExec that tries to open the dialog later. | |
546 * | |
547 * @param openOnRun | |
548 * <code>true</code> to open the dialog before run, | |
549 * <code>false</code> to only create the dialog, but not open | |
550 * it | |
551 * @since 3.0 | |
552 */ | |
553 public void setOpenOnRun(bool openOnRun) { | |
554 this.openOnRun = openOnRun; | |
555 } | |
556 | |
557 /** | |
558 * Returns the nesting depth of running operations. | |
559 * | |
560 * @return the nesting depth of running operations | |
561 * @since 3.0 | |
562 */ | |
563 protected int getNestingDepth() { | |
564 return nestingDepth; | |
565 } | |
566 | |
567 /** | |
568 * Increments the nesting depth of running operations. | |
569 * | |
570 * @since 3.0 | |
571 */ | |
572 protected void incrementNestingDepth() { | |
573 nestingDepth++; | |
574 } | |
575 | |
576 /** | |
577 * Decrements the nesting depth of running operations. | |
578 * | |
579 * @since 3.0 | |
580 * | |
581 */ | |
582 protected void decrementNestingDepth() { | |
583 nestingDepth--; | |
584 } | |
585 | |
586 /** | |
587 * Called just before the operation is run. Default behaviour is to open or | |
588 * create the dialog, based on the setting of <code>getOpenOnRun</code>, | |
589 * and increment the nesting depth. | |
590 * | |
591 * @since 3.0 | |
592 */ | |
593 protected void aboutToRun() { | |
594 if (getOpenOnRun()) { | |
595 open(); | |
596 } else { | |
597 create(); | |
598 } | |
599 incrementNestingDepth(); | |
600 } | |
601 | |
602 /** | |
603 * Called just after the operation is run. Default behaviour is to decrement | |
604 * the nesting depth, and close the dialog. | |
605 * | |
606 * @since 3.0 | |
607 */ | |
608 protected void finishedRun() { | |
609 decrementNestingDepth(); | |
610 close(); | |
611 } | |
612 | |
613 /** | |
614 * Sets whether the progress dialog is cancelable or not. | |
615 * | |
616 * @param cancelable | |
617 * <code>true</code> if the end user can cancel this progress | |
618 * dialog, and <code>false</code> if it cannot be canceled | |
619 */ | |
620 public void setCancelable(bool cancelable) { | |
621 if (cancel is null) { | |
622 enableCancelButton = cancelable; | |
623 } else { | |
624 asyncSetOperationCancelButtonEnabled(cancelable); | |
625 } | |
626 } | |
627 | |
628 /** | |
629 * Helper to enable/disable Cancel button for this dialog. | |
630 * | |
631 * @param b | |
632 * <code>true</code> to enable the cancel button, and | |
633 * <code>false</code> to disable it | |
634 * @since 3.0 | |
635 */ | |
636 protected void setOperationCancelButtonEnabled(bool b) { | |
637 operationCancelableState = b; | |
638 cancel.setEnabled(b); | |
639 } | |
640 | |
641 /* | |
642 * (non-Javadoc) | |
643 * | |
644 * @see dwtx.jface.dialogs.IconAndMessageDialog#getImage() | |
645 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
646 protected override Image getImage() { |
23 | 647 return getInfoImage(); |
648 } | |
649 | |
650 /** | |
651 * Set the message in the message label. | |
652 * | |
653 * @param messageString | |
654 * The string for the new message. | |
655 * @param force | |
656 * If force is true then always set the message text. | |
657 */ | |
658 private void setMessage(String messageString, bool force) { | |
659 // must not set null text in a label | |
660 message = messageString is null ? "" : messageString; //$NON-NLS-1$ | |
661 if (messageLabel is null || messageLabel.isDisposed()) { | |
662 return; | |
663 } | |
664 if (force || messageLabel.isVisible()) { | |
665 messageLabel.setToolTipText(message); | |
666 messageLabel.setText(shortenText(message, messageLabel)); | |
667 } | |
668 } | |
669 | |
670 /** | |
671 * Update the message label. Required if the monitor is forked. | |
672 */ | |
673 private void update() { | |
674 if (messageLabel is null || messageLabel.isDisposed()) { | |
675 return; | |
676 } | |
677 messageLabel.update(); | |
678 } | |
679 | |
680 /* | |
681 * (non-Javadoc) | |
682 * | |
683 * @see dwtx.jface.window.Window#open() | |
684 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
23
diff
changeset
|
685 public override int open() { |
23 | 686 // Check to be sure it is not already done. If it is just return OK. |
687 if (!getOpenOnRun()) { | |
688 if (getNestingDepth() is 0) { | |
689 return OK; | |
690 } | |
691 } | |
692 int result = super.open(); | |
70
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
693 // update message label just in case beginTask() has been invoked |
46a6e0e6ccd4
Merge with d-fied sources of 3.4M7
Frank Benoit <benoit@tionex.de>
parents:
43
diff
changeset
|
694 // already |
23 | 695 if (task is null || task.length is 0) |
696 setMessage(DEFAULT_TASKNAME, true); | |
697 else | |
698 setMessage(task, true); | |
699 return result; | |
700 } | |
701 } |