Mercurial > projects > dwt2
comparison org.eclipse.jface/src/org/eclipse/jface/window/ApplicationWindow.d @ 12:bc29606a740c
Added dwt-addons in original directory structure of eclipse.org
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 14 Mar 2009 18:23:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
11:43904fec5dca | 12:bc29606a740c |
---|---|
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 * Roman Dawydkin - bug 55116 | |
11 * Port to the D programming language: | |
12 * Frank Benoit <benoit@tionex.de> | |
13 *******************************************************************************/ | |
14 | |
15 module org.eclipse.jface.window.ApplicationWindow; | |
16 | |
17 import org.eclipse.jface.window.Window; | |
18 | |
19 import java.lang.reflect.InvocationTargetException; | |
20 | |
21 import org.eclipse.swt.SWT; | |
22 import org.eclipse.swt.custom.BusyIndicator; | |
23 import org.eclipse.swt.graphics.Font; | |
24 import org.eclipse.swt.graphics.Point; | |
25 import org.eclipse.swt.graphics.Rectangle; | |
26 import org.eclipse.swt.widgets.Composite; | |
27 import org.eclipse.swt.widgets.Control; | |
28 import org.eclipse.swt.widgets.CoolBar; | |
29 import org.eclipse.swt.widgets.Decorations; | |
30 import org.eclipse.swt.widgets.Display; | |
31 import org.eclipse.swt.widgets.Label; | |
32 import org.eclipse.swt.widgets.Layout; | |
33 import org.eclipse.swt.widgets.Menu; | |
34 import org.eclipse.swt.widgets.Shell; | |
35 import org.eclipse.swt.widgets.ToolBar; | |
36 import org.eclipse.core.runtime.NullProgressMonitor; | |
37 import org.eclipse.jface.action.CoolBarManager; | |
38 import org.eclipse.jface.action.ICoolBarManager; | |
39 import org.eclipse.jface.action.IToolBarManager; | |
40 import org.eclipse.jface.action.MenuManager; | |
41 import org.eclipse.jface.action.StatusLineManager; | |
42 import org.eclipse.jface.action.ToolBarManager; | |
43 import org.eclipse.jface.internal.provisional.action.ICoolBarManager2; | |
44 import org.eclipse.jface.internal.provisional.action.IToolBarManager2; | |
45 import org.eclipse.jface.operation.IRunnableContext; | |
46 import org.eclipse.jface.operation.IRunnableWithProgress; | |
47 import org.eclipse.jface.operation.ModalContext; | |
48 import org.eclipse.jface.resource.JFaceResources; | |
49 | |
50 import java.lang.all; | |
51 import java.util.Set; | |
52 | |
53 /** | |
54 * An application window is a high-level "main window", with built-in | |
55 * support for an optional menu bar with standard menus, an optional toolbar, | |
56 * and an optional status line. | |
57 * <p> | |
58 * Creating an application window involves the following steps: | |
59 * <ul> | |
60 * <li>creating an instance of <code>ApplicationWindow</code> | |
61 * </li> | |
62 * <li>assigning the window to a window manager (optional) | |
63 * </li> | |
64 * <li>opening the window by calling <code>open</code> | |
65 * </li> | |
66 * </ul> | |
67 * Only on the last step, when the window is told to open, are | |
68 * the window's shell and widget tree created. When the window is | |
69 * closed, the shell and widget tree are disposed of and are no longer | |
70 * referenced, and the window is automatically removed from its window | |
71 * manager. Like all windows, an application window may be reopened. | |
72 * </p> | |
73 * <p> | |
74 * An application window is also a suitable context in which to perform | |
75 * long-running operations (that is, it implements <code>IRunnableContext</code>). | |
76 * </p> | |
77 */ | |
78 public class ApplicationWindow : Window, IRunnableContext { | |
79 | |
80 /** | |
81 * Menu bar manager, or <code>null</code> if none (default). | |
82 * | |
83 * @see #addMenuBar | |
84 */ | |
85 private MenuManager menuBarManager = null; | |
86 | |
87 /** | |
88 * Tool bar manager, or <code>null</code> if none (default). | |
89 * | |
90 * @see #addToolBar | |
91 */ | |
92 private IToolBarManager toolBarManager = null; | |
93 | |
94 /** | |
95 * Status line manager, or <code>null</code> if none (default). | |
96 * | |
97 * @see #addStatusLine | |
98 */ | |
99 private StatusLineManager statusLineManager = null; | |
100 | |
101 /** | |
102 * Cool bar manager, or <code>null</code> if none (default). | |
103 * | |
104 * @see #addCoolBar | |
105 * @since 3.0 | |
106 */ | |
107 private ICoolBarManager coolBarManager = null; | |
108 | |
109 /** | |
110 * The seperator between the menu bar and the rest of the window. | |
111 */ | |
112 protected Label seperator1; | |
113 | |
114 /** | |
115 * A flag indicating that an operation is running. | |
116 */ | |
117 private bool operationInProgress = false; | |
118 | |
119 /** | |
120 * Internal application window layout class. | |
121 * This vertical layout supports a tool bar area (fixed size), | |
122 * a separator line, the content area (variable size), and a | |
123 * status line (fixed size). | |
124 */ | |
125 /*package*/class ApplicationWindowLayout : Layout { | |
126 | |
127 static final int VGAP = 2; | |
128 | |
129 static final int BAR_SIZE = 23; | |
130 | |
131 protected override Point computeSize(Composite composite, int wHint, int hHint, | |
132 bool flushCache) { | |
133 if (wHint !is SWT.DEFAULT && hHint !is SWT.DEFAULT) { | |
134 return new Point(wHint, hHint); | |
135 } | |
136 | |
137 Point result = new Point(0, 0); | |
138 Control[] ws = composite.getChildren(); | |
139 for (int i = 0; i < ws.length; i++) { | |
140 Control w = ws[i]; | |
141 | |
142 bool hide = false; | |
143 if (getToolBarControl() is w) { | |
144 if (!toolBarChildrenExist()) { | |
145 hide = true; | |
146 result.y += BAR_SIZE; // REVISIT | |
147 } | |
148 } else if (getCoolBarControl() is w) { | |
149 if (!coolBarChildrenExist()) { | |
150 hide = true; | |
151 result.y += BAR_SIZE; | |
152 } | |
153 } else if (statusLineManager !is null | |
154 && statusLineManager.getControl() is w) { | |
155 } else if (i > 0) { /* we assume this window is contents */ | |
156 hide = false; | |
157 } | |
158 | |
159 if (!hide) { | |
160 Point e = w.computeSize(wHint, hHint, flushCache); | |
161 result.x = Math.max(result.x, e.x); | |
162 result.y += e.y + VGAP; | |
163 } | |
164 } | |
165 | |
166 if (wHint !is SWT.DEFAULT) { | |
167 result.x = wHint; | |
168 } | |
169 if (hHint !is SWT.DEFAULT) { | |
170 result.y = hHint; | |
171 } | |
172 return result; | |
173 } | |
174 | |
175 protected override void layout(Composite composite, bool flushCache) { | |
176 Rectangle clientArea = composite.getClientArea(); | |
177 | |
178 Control[] ws = composite.getChildren(); | |
179 | |
180 // Lay out the separator, the tool bar control, the cool bar control, the status line, and the page composite. | |
181 // The following code assumes that the page composite is the last child, and that there are no unexpected other controls. | |
182 | |
183 for (int i = 0; i < ws.length; i++) { | |
184 Control w = ws[i]; | |
185 | |
186 if (w is seperator1) { // Separator | |
187 Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT, | |
188 flushCache); | |
189 w.setBounds(clientArea.x, clientArea.y, clientArea.width, | |
190 e.y); | |
191 clientArea.y += e.y; | |
192 clientArea.height -= e.y; | |
193 } else if (getToolBarControl() is w) { | |
194 if (toolBarChildrenExist()) { | |
195 Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT, | |
196 flushCache); | |
197 w.setBounds(clientArea.x, clientArea.y, | |
198 clientArea.width, e.y); | |
199 clientArea.y += e.y + VGAP; | |
200 clientArea.height -= e.y + VGAP; | |
201 } | |
202 } else if (getCoolBarControl() is w) { | |
203 if (coolBarChildrenExist()) { | |
204 Point e = w.computeSize(clientArea.width, SWT.DEFAULT, | |
205 flushCache); | |
206 w.setBounds(clientArea.x, clientArea.y, | |
207 clientArea.width, e.y); | |
208 clientArea.y += e.y + VGAP; | |
209 clientArea.height -= e.y + VGAP; | |
210 } | |
211 } else if (statusLineManager !is null | |
212 && statusLineManager.getControl() is w) { | |
213 Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT, | |
214 flushCache); | |
215 w.setBounds(clientArea.x, clientArea.y + clientArea.height | |
216 - e.y, clientArea.width, e.y); | |
217 clientArea.height -= e.y + VGAP; | |
218 } else { | |
219 w.setBounds(clientArea.x, clientArea.y + VGAP, | |
220 clientArea.width, clientArea.height - VGAP); | |
221 } | |
222 } | |
223 } | |
224 } | |
225 | |
226 /** | |
227 * Return the top seperator. | |
228 * @return Label | |
229 */ | |
230 protected Label getSeperator1() { | |
231 return seperator1; | |
232 } | |
233 | |
234 /** | |
235 * Create an application window instance, whose shell will be created under the | |
236 * given parent shell. | |
237 * Note that the window will have no visual representation (no widgets) | |
238 * until it is told to open. By default, <code>open</code> does not block. | |
239 * | |
240 * @param parentShell the parent shell, or <code>null</code> to create a top-level shell | |
241 */ | |
242 public this(Shell parentShell) { | |
243 super(parentShell); | |
244 } | |
245 | |
246 /** | |
247 * Configures this window to have a menu bar. | |
248 * Does nothing if it already has one. | |
249 * This method must be called before this window's shell is created. | |
250 */ | |
251 protected void addMenuBar() { | |
252 if ((getShell() is null) && (menuBarManager is null)) { | |
253 menuBarManager = createMenuManager(); | |
254 } | |
255 } | |
256 | |
257 /** | |
258 * Configures this window to have a status line. | |
259 * Does nothing if it already has one. | |
260 * This method must be called before this window's shell is created. | |
261 */ | |
262 protected void addStatusLine() { | |
263 if ((getShell() is null) && (statusLineManager is null)) { | |
264 statusLineManager = createStatusLineManager(); | |
265 } | |
266 } | |
267 | |
268 /** | |
269 * Configures this window to have a tool bar. | |
270 * Does nothing if it already has one. | |
271 * This method must be called before this window's shell is created. | |
272 * @param style swt style bits used to create the Toolbar | |
273 * @see ToolBarManager#ToolBarManager(int) | |
274 * @see ToolBar for style bits | |
275 */ | |
276 protected void addToolBar(int style) { | |
277 if ((getShell() is null) && (toolBarManager is null) | |
278 && (coolBarManager is null)) { | |
279 toolBarManager = createToolBarManager2(style); | |
280 } | |
281 } | |
282 | |
283 /** | |
284 * Configures this window to have a cool bar. | |
285 * Does nothing if it already has one. | |
286 * This method must be called before this window's shell is created. | |
287 * | |
288 * @param style the cool bar style | |
289 * @since 3.0 | |
290 */ | |
291 protected void addCoolBar(int style) { | |
292 if ((getShell() is null) && (toolBarManager is null) | |
293 && (coolBarManager is null)) { | |
294 coolBarManager = createCoolBarManager2(style); | |
295 } | |
296 } | |
297 | |
298 /* (non-Javadoc) | |
299 * Method declared on Window. | |
300 */ | |
301 protected override bool canHandleShellCloseEvent() { | |
302 return super.canHandleShellCloseEvent() && !operationInProgress; | |
303 } | |
304 | |
305 /* (non-Javadoc) | |
306 * Method declared on Window. | |
307 */ | |
308 public override bool close() { | |
309 if (operationInProgress) { | |
310 return false; | |
311 } | |
312 | |
313 if (super.close()) { | |
314 if (menuBarManager !is null) { | |
315 menuBarManager.dispose(); | |
316 menuBarManager = null; | |
317 } | |
318 if (toolBarManager !is null) { | |
319 if (cast(IToolBarManager2)toolBarManager ) { | |
320 (cast(IToolBarManager2) toolBarManager).dispose(); | |
321 } else if (cast(ToolBarManager)toolBarManager ) { | |
322 (cast(ToolBarManager) toolBarManager).dispose(); | |
323 } | |
324 toolBarManager = null; | |
325 } | |
326 if (statusLineManager !is null) { | |
327 statusLineManager.dispose(); | |
328 statusLineManager = null; | |
329 } | |
330 if (coolBarManager !is null) { | |
331 if (cast(ICoolBarManager2)coolBarManager ) { | |
332 (cast(ICoolBarManager2) coolBarManager).dispose(); | |
333 } else if (cast(CoolBarManager)coolBarManager ) { | |
334 (cast(CoolBarManager) coolBarManager).dispose(); | |
335 } | |
336 coolBarManager = null; | |
337 } | |
338 return true; | |
339 } | |
340 return false; | |
341 } | |
342 | |
343 /** | |
344 * Extends the super implementation by creating the trim widgets using <code>createTrimWidgets</code>. | |
345 */ | |
346 protected override void configureShell(Shell shell) { | |
347 | |
348 super.configureShell(shell); | |
349 | |
350 createTrimWidgets(shell); | |
351 } | |
352 | |
353 /** | |
354 * Creates the trim widgets around the content area. | |
355 * | |
356 * @param shell the shell | |
357 * @since 3.0 | |
358 */ | |
359 protected void createTrimWidgets(Shell shell) { | |
360 if (menuBarManager !is null) { | |
361 menuBarManager.updateAll(true); | |
362 shell.setMenuBar(menuBarManager.createMenuBar(cast(Decorations) shell)); | |
363 } | |
364 | |
365 if (showTopSeperator()) { | |
366 seperator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL); | |
367 } | |
368 | |
369 // will create either a cool bar or a tool bar | |
370 createToolBarControl(shell); | |
371 createCoolBarControl(shell); | |
372 createStatusLine(shell); | |
373 } | |
374 | |
375 /* (non-Javadoc) | |
376 * @see org.eclipse.jface.window.Window#getLayout() | |
377 */ | |
378 protected override Layout getLayout() { | |
379 return new ApplicationWindowLayout(); | |
380 } | |
381 | |
382 /** | |
383 * Returns whether to show a top separator line between the menu bar | |
384 * and the rest of the window contents. On some platforms such as the Mac, | |
385 * the menu is separated from the main window already, so a separator line | |
386 * is not desired. | |
387 * | |
388 * @return <code>true</code> to show the top separator, <code>false</code> | |
389 * to not show it | |
390 * @since 3.0 | |
391 */ | |
392 protected bool showTopSeperator() { | |
393 return !"carbon".equals(SWT.getPlatform()); //$NON-NLS-1$ | |
394 } | |
395 | |
396 /** | |
397 * Create the status line if required. | |
398 * @param shell | |
399 */ | |
400 protected void createStatusLine(Shell shell) { | |
401 if (statusLineManager !is null) { | |
402 statusLineManager.createControl(shell, SWT.NONE); | |
403 } | |
404 } | |
405 | |
406 /** | |
407 * Returns a new menu manager for the window. | |
408 * <p> | |
409 * Subclasses may override this method to customize the menu manager. | |
410 * </p> | |
411 * @return a menu manager | |
412 */ | |
413 protected MenuManager createMenuManager() { | |
414 return new MenuManager(); | |
415 } | |
416 | |
417 /** | |
418 * Returns a new status line manager for the window. | |
419 * <p> | |
420 * Subclasses may override this method to customize the status line manager. | |
421 * </p> | |
422 * @return a status line manager | |
423 */ | |
424 protected StatusLineManager createStatusLineManager() { | |
425 return new StatusLineManager(); | |
426 } | |
427 | |
428 /** | |
429 * Returns a new tool bar manager for the window. | |
430 * <p> | |
431 * Subclasses may override this method to customize the tool bar manager. | |
432 * </p> | |
433 * @param style swt style bits used to create the Toolbar | |
434 * | |
435 * @return a tool bar manager | |
436 * @see ToolBarManager#ToolBarManager(int) | |
437 * @see ToolBar for style bits | |
438 */ | |
439 protected ToolBarManager createToolBarManager(int style) { | |
440 return new ToolBarManager(style); | |
441 } | |
442 | |
443 /** | |
444 * Returns a new tool bar manager for the window. | |
445 * <p> | |
446 * By default this method calls <code>createToolBarManager</code>. Subclasses | |
447 * may override this method to provide an alternative implementation for the | |
448 * tool bar manager. | |
449 * </p> | |
450 * | |
451 * @param style swt style bits used to create the Toolbar | |
452 * | |
453 * @return a tool bar manager | |
454 * @since 3.2 | |
455 * @see #createToolBarManager(int) | |
456 */ | |
457 protected IToolBarManager createToolBarManager2(int style) { | |
458 return createToolBarManager(style); | |
459 } | |
460 | |
461 /** | |
462 * Returns a new cool bar manager for the window. | |
463 * <p> | |
464 * Subclasses may override this method to customize the cool bar manager. | |
465 * </p> | |
466 * | |
467 * @param style swt style bits used to create the Coolbar | |
468 * | |
469 * @return a cool bar manager | |
470 * @since 3.0 | |
471 * @see CoolBarManager#CoolBarManager(int) | |
472 * @see CoolBar for style bits | |
473 */ | |
474 protected CoolBarManager createCoolBarManager(int style) { | |
475 return new CoolBarManager(style); | |
476 } | |
477 | |
478 /** | |
479 * Returns a new cool bar manager for the window. | |
480 * <p> | |
481 * By default this method calls <code>createCoolBarManager</code>. Subclasses | |
482 * may override this method to provide an alternative implementation for the | |
483 * cool bar manager. | |
484 * </p> | |
485 * | |
486 * @param style swt style bits used to create the Coolbar | |
487 * | |
488 * @return a cool bar manager | |
489 * @since 3.2 | |
490 * @see #createCoolBarManager(int) | |
491 */ | |
492 protected ICoolBarManager createCoolBarManager2(int style) { | |
493 return createCoolBarManager(style); | |
494 } | |
495 | |
496 /** | |
497 * Creates the control for the tool bar manager. | |
498 * <p> | |
499 * Subclasses may override this method to customize the tool bar manager. | |
500 * </p> | |
501 * @param parent the parent used for the control | |
502 * @return a Control | |
503 */ | |
504 protected Control createToolBarControl(Composite parent) { | |
505 if (toolBarManager !is null) { | |
506 if (cast(IToolBarManager2)toolBarManager ) { | |
507 return (cast(IToolBarManager2) toolBarManager).createControl2(parent); | |
508 } | |
509 if (cast(ToolBarManager)toolBarManager ) { | |
510 return (cast(ToolBarManager) toolBarManager).createControl(parent); | |
511 } | |
512 } | |
513 return null; | |
514 } | |
515 | |
516 /** | |
517 * Creates the control for the cool bar manager. | |
518 * <p> | |
519 * Subclasses may override this method to customize the cool bar manager. | |
520 * </p> | |
521 * @param composite the parent used for the control | |
522 * | |
523 * @return an instance of <code>CoolBar</code> | |
524 * @since 3.0 | |
525 */ | |
526 protected Control createCoolBarControl(Composite composite) { | |
527 if (coolBarManager !is null) { | |
528 if (cast(ICoolBarManager2)coolBarManager ) { | |
529 return (cast(ICoolBarManager2) coolBarManager).createControl2(composite); | |
530 } | |
531 if (cast(CoolBarManager)coolBarManager ) { | |
532 return (cast(CoolBarManager) coolBarManager).createControl(composite); | |
533 } | |
534 } | |
535 return null; | |
536 } | |
537 | |
538 /** | |
539 * Returns the default font used for this window. | |
540 * <p> | |
541 * The default implementation of this framework method | |
542 * obtains the symbolic name of the font from the | |
543 * <code>getSymbolicFontName</code> framework method | |
544 * and retrieves this font from JFace's font | |
545 * registry using <code>JFaceResources.getFont</code>. | |
546 * Subclasses may override to use a different registry, | |
547 * etc. | |
548 * </p> | |
549 * | |
550 * @return the default font, or <code>null</code> if none | |
551 */ | |
552 protected Font getFont() { | |
553 return JFaceResources.getFont(getSymbolicFontName()); | |
554 } | |
555 | |
556 /** | |
557 * Returns the menu bar manager for this window (if it has one). | |
558 * | |
559 * @return the menu bar manager, or <code>null</code> if | |
560 * this window does not have a menu bar | |
561 * @see #addMenuBar() | |
562 */ | |
563 public MenuManager getMenuBarManager() { | |
564 return menuBarManager; | |
565 } | |
566 | |
567 /** | |
568 * Returns the status line manager for this window (if it has one). | |
569 * | |
570 * @return the status line manager, or <code>null</code> if | |
571 * this window does not have a status line | |
572 * @see #addStatusLine | |
573 */ | |
574 protected StatusLineManager getStatusLineManager() { | |
575 return statusLineManager; | |
576 } | |
577 | |
578 /** | |
579 * Returns the symbolic font name of the font to be | |
580 * used to display text in this window. | |
581 * This is not recommended and is included for backwards | |
582 * compatability. | |
583 * It is recommended to use the default font provided by | |
584 * SWT (that is, do not set the font). | |
585 * | |
586 * @return the symbolic font name | |
587 */ | |
588 public String getSymbolicFontName() { | |
589 return JFaceResources.TEXT_FONT; | |
590 } | |
591 | |
592 /** | |
593 * Returns the tool bar manager for this window (if it has one). | |
594 * | |
595 * @return the tool bar manager, or <code>null</code> if | |
596 * this window does not have a tool bar | |
597 * @see #addToolBar(int) | |
598 */ | |
599 public ToolBarManager getToolBarManager() { | |
600 if (cast(ToolBarManager)toolBarManager ) { | |
601 return cast(ToolBarManager)toolBarManager; | |
602 } | |
603 return null; | |
604 } | |
605 | |
606 /** | |
607 * Returns the tool bar manager for this window (if it has one). | |
608 * | |
609 * @return the tool bar manager, or <code>null</code> if | |
610 * this window does not have a tool bar | |
611 * @see #addToolBar(int) | |
612 * @since 3.2 | |
613 */ | |
614 public IToolBarManager getToolBarManager2() { | |
615 return toolBarManager; | |
616 } | |
617 | |
618 /** | |
619 * Returns the cool bar manager for this window. | |
620 * | |
621 * @return the cool bar manager, or <code>null</code> if | |
622 * this window does not have a cool bar | |
623 * @see #addCoolBar(int) | |
624 * @since 3.0 | |
625 */ | |
626 public CoolBarManager getCoolBarManager() { | |
627 if (cast(CoolBarManager)coolBarManager ) { | |
628 return cast(CoolBarManager)coolBarManager; | |
629 } | |
630 return null; | |
631 } | |
632 | |
633 /** | |
634 * Returns the cool bar manager for this window. | |
635 * | |
636 * @return the cool bar manager, or <code>null</code> if | |
637 * this window does not have a cool bar | |
638 * @see #addCoolBar(int) | |
639 * @since 3.2 | |
640 */ | |
641 public ICoolBarManager getCoolBarManager2() { | |
642 return coolBarManager; | |
643 } | |
644 | |
645 /** | |
646 * Returns the control for the window's toolbar. | |
647 * <p> | |
648 * Subclasses may override this method to customize the tool bar manager. | |
649 * </p> | |
650 * @return a Control | |
651 */ | |
652 protected Control getToolBarControl() { | |
653 if (toolBarManager !is null) { | |
654 if (cast(IToolBarManager2)toolBarManager ) { | |
655 return (cast(IToolBarManager2) toolBarManager).getControl2(); | |
656 } | |
657 if (cast(ToolBarManager)toolBarManager ) { | |
658 return (cast(ToolBarManager) toolBarManager).getControl(); | |
659 } | |
660 } | |
661 return null; | |
662 } | |
663 | |
664 /** | |
665 * Returns the control for the window's cool bar. | |
666 * <p> | |
667 * Subclasses may override this method to customize the cool bar manager. | |
668 * </p> | |
669 * | |
670 * @return an instance of <code>CoolBar</code> | |
671 * @since 3.0 | |
672 */ | |
673 protected Control getCoolBarControl() { | |
674 if (coolBarManager !is null) { | |
675 if (cast(ICoolBarManager2)coolBarManager ) { | |
676 return (cast(ICoolBarManager2) coolBarManager).getControl2(); | |
677 } | |
678 if (cast(CoolBarManager)coolBarManager ) { | |
679 return (cast(CoolBarManager) coolBarManager).getControl(); | |
680 } | |
681 } | |
682 return null; | |
683 } | |
684 | |
685 /** | |
686 * This implementation of IRunnableContext#run(bool, bool, | |
687 * IRunnableWithProgress) blocks until the runnable has been run, | |
688 * regardless of the value of <code>fork</code>. | |
689 * It is recommended that <code>fork</code> is set to | |
690 * true in most cases. If <code>fork</code> is set to <code>false</code>, | |
691 * the runnable will run in the UI thread and it is the runnable's | |
692 * responsibility to call <code>Display.readAndDispatch()</code> | |
693 * to ensure UI responsiveness. | |
694 */ | |
695 public void run(bool fork, bool cancelable, | |
696 IRunnableWithProgress runnable) { | |
697 try { | |
698 operationInProgress = true; | |
699 StatusLineManager mgr = getStatusLineManager(); | |
700 if (mgr is null) { | |
701 runnable.run(new NullProgressMonitor()); | |
702 return; | |
703 } | |
704 bool cancelWasEnabled = mgr.isCancelEnabled(); | |
705 | |
706 Control contents = getContents(); | |
707 Display display = contents.getDisplay(); | |
708 Shell shell = getShell(); | |
709 bool contentsWasEnabled = contents.getEnabled(); | |
710 MenuManager manager = getMenuBarManager(); | |
711 Menu menuBar = null; | |
712 if (manager !is null) { | |
713 menuBar = manager.getMenu(); | |
714 manager = null; | |
715 } | |
716 bool menuBarWasEnabled = false; | |
717 if (menuBar !is null) { | |
718 menuBarWasEnabled = menuBar.getEnabled(); | |
719 } | |
720 | |
721 Control toolbarControl = getToolBarControl(); | |
722 bool toolbarWasEnabled = false; | |
723 if (toolbarControl !is null) { | |
724 toolbarWasEnabled = toolbarControl.getEnabled(); | |
725 } | |
726 | |
727 Control coolbarControl = getCoolBarControl(); | |
728 bool coolbarWasEnabled = false; | |
729 if (coolbarControl !is null) { | |
730 coolbarWasEnabled = coolbarControl.getEnabled(); | |
731 } | |
732 | |
733 // Disable the rest of the shells on the current display | |
734 Shell[] shells = display.getShells(); | |
735 bool[] enabled = new bool[shells.length]; | |
736 for (int i = 0; i < shells.length; i++) { | |
737 Shell current = shells[i]; | |
738 if (current is shell) { | |
739 continue; | |
740 } | |
741 if (current !is null && !current.isDisposed()) { | |
742 enabled[i] = current.getEnabled(); | |
743 current.setEnabled(false); | |
744 } | |
745 } | |
746 | |
747 Control currentFocus = display.getFocusControl(); | |
748 try { | |
749 contents.setEnabled(false); | |
750 if (menuBar !is null) { | |
751 menuBar.setEnabled(false); | |
752 } | |
753 if (toolbarControl !is null) { | |
754 toolbarControl.setEnabled(false); | |
755 } | |
756 if (coolbarControl !is null) { | |
757 coolbarControl.setEnabled(false); | |
758 } | |
759 mgr.setCancelEnabled(cancelable); | |
760 Exception[1] holder; | |
761 BusyIndicator.showWhile(display, new class(fork,runnable,mgr,display) Runnable { | |
762 bool fork_; | |
763 IRunnableWithProgress runnable_; | |
764 StatusLineManager mgr_; | |
765 Display display_; | |
766 this(bool f,IRunnableWithProgress a,StatusLineManager b,Display c){ | |
767 fork_=f; | |
768 runnable_=a; | |
769 mgr_=b; | |
770 display_=c; | |
771 } | |
772 public void run() { | |
773 try { | |
774 ModalContext.run(runnable_, fork_, mgr_ | |
775 .getProgressMonitor(), display_); | |
776 } catch (InvocationTargetException ite) { | |
777 holder[0] = ite; | |
778 } catch (InterruptedException ie) { | |
779 holder[0] = ie; | |
780 } | |
781 } | |
782 }); | |
783 | |
784 if (holder[0] !is null) { | |
785 if (cast(InvocationTargetException)holder[0] ) { | |
786 throw cast(InvocationTargetException) holder[0]; | |
787 } else if (cast(InterruptedException)holder[0] ) { | |
788 throw cast(InterruptedException) holder[0]; | |
789 } | |
790 } | |
791 } finally { | |
792 operationInProgress = false; | |
793 // Enable the rest of the shells on the current display | |
794 for (int i = 0; i < shells.length; i++) { | |
795 Shell current = shells[i]; | |
796 if (current is shell) { | |
797 continue; | |
798 } | |
799 if (current !is null && !current.isDisposed()) { | |
800 current.setEnabled(enabled[i]); | |
801 } | |
802 } | |
803 if (!contents.isDisposed()) { | |
804 contents.setEnabled(contentsWasEnabled); | |
805 } | |
806 if (menuBar !is null && !menuBar.isDisposed()) { | |
807 menuBar.setEnabled(menuBarWasEnabled); | |
808 } | |
809 if (toolbarControl !is null && !toolbarControl.isDisposed()) { | |
810 toolbarControl.setEnabled(toolbarWasEnabled); | |
811 } | |
812 if (coolbarControl !is null && !coolbarControl.isDisposed()) { | |
813 coolbarControl.setEnabled(coolbarWasEnabled); | |
814 } | |
815 mgr.setCancelEnabled(cancelWasEnabled); | |
816 if (currentFocus !is null && !currentFocus.isDisposed()) { | |
817 // It's necessary to restore focus after reenabling the controls | |
818 // because disabling them causes focus to jump elsewhere. | |
819 // Use forceFocus rather than setFocus to avoid SWT's | |
820 // search for children which can take focus, so focus | |
821 // ends up back on the actual control that previously had it. | |
822 currentFocus.forceFocus(); | |
823 } | |
824 } | |
825 } finally { | |
826 operationInProgress = false; | |
827 } | |
828 } | |
829 | |
830 /** | |
831 * Sets or clears the message displayed in this window's status | |
832 * line (if it has one). This method has no effect if the | |
833 * window does not have a status line. | |
834 * | |
835 * @param message the status message, or <code>null</code> to clear it | |
836 */ | |
837 public void setStatus(String message) { | |
838 if (statusLineManager !is null) { | |
839 statusLineManager.setMessage(message); | |
840 } | |
841 } | |
842 | |
843 /** | |
844 * Returns whether or not children exist for the Application Window's | |
845 * toolbar control. | |
846 * <p> | |
847 * @return bool true if children exist, false otherwise | |
848 */ | |
849 protected bool toolBarChildrenExist() { | |
850 Control toolControl = getToolBarControl(); | |
851 if (cast(ToolBar)toolControl ) { | |
852 return (cast(ToolBar) toolControl).getItemCount() > 0; | |
853 } | |
854 return false; | |
855 } | |
856 | |
857 /** | |
858 * Returns whether or not children exist for this application window's | |
859 * cool bar control. | |
860 * | |
861 * @return bool true if children exist, false otherwise | |
862 * @since 3.0 | |
863 */ | |
864 protected bool coolBarChildrenExist() { | |
865 Control coolControl = getCoolBarControl(); | |
866 if (cast(CoolBar)coolControl ) { | |
867 return (cast(CoolBar) coolControl).getItemCount() > 0; | |
868 } | |
869 return false; | |
870 } | |
871 | |
872 } |