KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > window > ApplicationWindow


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  *******************************************************************************/

12
13 package org.eclipse.jface.window;
14
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.eclipse.jface.action.CoolBarManager;
19 import org.eclipse.jface.action.ICoolBarManager;
20 import org.eclipse.jface.action.IToolBarManager;
21 import org.eclipse.jface.action.MenuManager;
22 import org.eclipse.jface.action.StatusLineManager;
23 import org.eclipse.jface.action.ToolBarManager;
24 import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
25 import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
26 import org.eclipse.jface.operation.IRunnableContext;
27 import org.eclipse.jface.operation.IRunnableWithProgress;
28 import org.eclipse.jface.operation.ModalContext;
29 import org.eclipse.jface.resource.JFaceResources;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.custom.BusyIndicator;
32 import org.eclipse.swt.graphics.Font;
33 import org.eclipse.swt.graphics.Point;
34 import org.eclipse.swt.graphics.Rectangle;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Control;
37 import org.eclipse.swt.widgets.CoolBar;
38 import org.eclipse.swt.widgets.Decorations;
39 import org.eclipse.swt.widgets.Display;
40 import org.eclipse.swt.widgets.Label;
41 import org.eclipse.swt.widgets.Layout;
42 import org.eclipse.swt.widgets.Menu;
43 import org.eclipse.swt.widgets.Shell;
44 import org.eclipse.swt.widgets.ToolBar;
45
46 /**
47  * An application window is a high-level "main window", with built-in
48  * support for an optional menu bar with standard menus, an optional toolbar,
49  * and an optional status line.
50  * <p>
51  * Creating an application window involves the following steps:
52  * <ul>
53  * <li>creating an instance of <code>ApplicationWindow</code>
54  * </li>
55  * <li>assigning the window to a window manager (optional)
56  * </li>
57  * <li>opening the window by calling <code>open</code>
58  * </li>
59  * </ul>
60  * Only on the last step, when the window is told to open, are
61  * the window's shell and widget tree created. When the window is
62  * closed, the shell and widget tree are disposed of and are no longer
63  * referenced, and the window is automatically removed from its window
64  * manager. Like all windows, an application window may be reopened.
65  * </p>
66  * <p>
67  * An application window is also a suitable context in which to perform
68  * long-running operations (that is, it implements <code>IRunnableContext</code>).
69  * </p>
70  */

71 public class ApplicationWindow extends Window implements IRunnableContext {
72
73     /**
74      * Menu bar manager, or <code>null</code> if none (default).
75      *
76      * @see #addMenuBar
77      */

78     private MenuManager menuBarManager = null;
79
80     /**
81      * Tool bar manager, or <code>null</code> if none (default).
82      *
83      * @see #addToolBar
84      */

85     private IToolBarManager toolBarManager = null;
86
87     /**
88      * Status line manager, or <code>null</code> if none (default).
89      *
90      * @see #addStatusLine
91      */

92     private StatusLineManager statusLineManager = null;
93
94     /**
95      * Cool bar manager, or <code>null</code> if none (default).
96      *
97      * @see #addCoolBar
98      * @since 3.0
99      */

100     private ICoolBarManager coolBarManager = null;
101
102     /**
103      * The seperator between the menu bar and the rest of the window.
104      */

105     protected Label seperator1;
106
107     /**
108      * A flag indicating that an operation is running.
109      */

110     private boolean operationInProgress = false;
111
112     /**
113      * Internal application window layout class.
114      * This vertical layout supports a tool bar area (fixed size),
115      * a separator line, the content area (variable size), and a
116      * status line (fixed size).
117      */

118     /*package*/class ApplicationWindowLayout extends Layout {
119
120         static final int VGAP = 2;
121
122         static final int BAR_SIZE = 23;
123
124         protected Point computeSize(Composite composite, int wHint, int hHint,
125                 boolean flushCache) {
126             if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
127                 return new Point(wHint, hHint);
128             }
129
130             Point result = new Point(0, 0);
131             Control[] ws = composite.getChildren();
132             for (int i = 0; i < ws.length; i++) {
133                 Control w = ws[i];
134
135                 boolean hide = false;
136                 if (getToolBarControl() == w) {
137                     if (!toolBarChildrenExist()) {
138                         hide = true;
139                         result.y += BAR_SIZE; // REVISIT
140
}
141                 } else if (getCoolBarControl() == w) {
142                     if (!coolBarChildrenExist()) {
143                         hide = true;
144                         result.y += BAR_SIZE;
145                     }
146                 } else if (statusLineManager != null
147                         && statusLineManager.getControl() == w) {
148                 } else if (i > 0) { /* we assume this window is contents */
149                     hide = false;
150                 }
151
152                 if (!hide) {
153                     Point e = w.computeSize(wHint, hHint, flushCache);
154                     result.x = Math.max(result.x, e.x);
155                     result.y += e.y + VGAP;
156                 }
157             }
158
159             if (wHint != SWT.DEFAULT) {
160                 result.x = wHint;
161             }
162             if (hHint != SWT.DEFAULT) {
163                 result.y = hHint;
164             }
165             return result;
166         }
167
168         protected void layout(Composite composite, boolean flushCache) {
169             Rectangle clientArea = composite.getClientArea();
170
171             Control[] ws = composite.getChildren();
172             
173             // Lay out the separator, the tool bar control, the cool bar control, the status line, and the page composite.
174
// The following code assumes that the page composite is the last child, and that there are no unexpected other controls.
175

176             for (int i = 0; i < ws.length; i++) {
177                 Control w = ws[i];
178
179                 if (w == seperator1) { // Separator
180
Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
181                             flushCache);
182                     w.setBounds(clientArea.x, clientArea.y, clientArea.width,
183                             e.y);
184                     clientArea.y += e.y;
185                     clientArea.height -= e.y;
186                 } else if (getToolBarControl() == w) {
187                     if (toolBarChildrenExist()) {
188                         Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
189                                 flushCache);
190                         w.setBounds(clientArea.x, clientArea.y,
191                                 clientArea.width, e.y);
192                         clientArea.y += e.y + VGAP;
193                         clientArea.height -= e.y + VGAP;
194                     }
195                 } else if (getCoolBarControl() == w) {
196                     if (coolBarChildrenExist()) {
197                         Point e = w.computeSize(clientArea.width, SWT.DEFAULT,
198                                 flushCache);
199                         w.setBounds(clientArea.x, clientArea.y,
200                                 clientArea.width, e.y);
201                         clientArea.y += e.y + VGAP;
202                         clientArea.height -= e.y + VGAP;
203                     }
204                 } else if (statusLineManager != null
205                         && statusLineManager.getControl() == w) {
206                     Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
207                             flushCache);
208                     w.setBounds(clientArea.x, clientArea.y + clientArea.height
209                             - e.y, clientArea.width, e.y);
210                     clientArea.height -= e.y + VGAP;
211                 } else {
212                     w.setBounds(clientArea.x, clientArea.y + VGAP,
213                             clientArea.width, clientArea.height - VGAP);
214                 }
215             }
216         }
217     }
218
219     /**
220      * Return the top seperator.
221      * @return Label
222      */

223     protected Label getSeperator1() {
224         return seperator1;
225     }
226
227     /**
228      * Create an application window instance, whose shell will be created under the
229      * given parent shell.
230      * Note that the window will have no visual representation (no widgets)
231      * until it is told to open. By default, <code>open</code> does not block.
232      *
233      * @param parentShell the parent shell, or <code>null</code> to create a top-level shell
234      */

235     public ApplicationWindow(Shell parentShell) {
236         super(parentShell);
237     }
238
239     /**
240      * Configures this window to have a menu bar.
241      * Does nothing if it already has one.
242      * This method must be called before this window's shell is created.
243      */

244     protected void addMenuBar() {
245         if ((getShell() == null) && (menuBarManager == null)) {
246             menuBarManager = createMenuManager();
247         }
248     }
249
250     /**
251      * Configures this window to have a status line.
252      * Does nothing if it already has one.
253      * This method must be called before this window's shell is created.
254      */

255     protected void addStatusLine() {
256         if ((getShell() == null) && (statusLineManager == null)) {
257             statusLineManager = createStatusLineManager();
258         }
259     }
260
261     /**
262      * Configures this window to have a tool bar.
263      * Does nothing if it already has one.
264      * This method must be called before this window's shell is created.
265      * @param style swt style bits used to create the Toolbar
266      * @see ToolBarManager#ToolBarManager(int)
267      * @see ToolBar for style bits
268      */

269     protected void addToolBar(int style) {
270         if ((getShell() == null) && (toolBarManager == null)
271                 && (coolBarManager == null)) {
272             toolBarManager = createToolBarManager2(style);
273         }
274     }
275
276     /**
277      * Configures this window to have a cool bar.
278      * Does nothing if it already has one.
279      * This method must be called before this window's shell is created.
280      *
281      * @param style the cool bar style
282      * @since 3.0
283      */

284     protected void addCoolBar(int style) {
285         if ((getShell() == null) && (toolBarManager == null)
286                 && (coolBarManager == null)) {
287             coolBarManager = createCoolBarManager2(style);
288         }
289     }
290
291     /* (non-Javadoc)
292      * Method declared on Window.
293      */

294     protected boolean canHandleShellCloseEvent() {
295         return super.canHandleShellCloseEvent() && !operationInProgress;
296     }
297
298     /* (non-Javadoc)
299      * Method declared on Window.
300      */

301     public boolean close() {
302         if (operationInProgress) {
303             return false;
304         }
305
306         if (super.close()) {
307             if (menuBarManager != null) {
308                 menuBarManager.dispose();
309                 menuBarManager = null;
310             }
311             if (toolBarManager != null) {
312                 if (toolBarManager instanceof IToolBarManager2) {
313                     ((IToolBarManager2) toolBarManager).dispose();
314                 } else if (toolBarManager instanceof ToolBarManager) {
315                     ((ToolBarManager) toolBarManager).dispose();
316                 }
317                 toolBarManager = null;
318             }
319             if (statusLineManager != null) {
320                 statusLineManager.dispose();
321                 statusLineManager = null;
322             }
323             if (coolBarManager != null) {
324                 if (coolBarManager instanceof ICoolBarManager2) {
325                     ((ICoolBarManager2) coolBarManager).dispose();
326                 } else if (coolBarManager instanceof CoolBarManager) {
327                     ((CoolBarManager) coolBarManager).dispose();
328                 }
329                 coolBarManager = null;
330             }
331             return true;
332         }
333         return false;
334     }
335
336     /**
337      * Extends the super implementation by creating the trim widgets using <code>createTrimWidgets</code>.
338      */

339     protected void configureShell(Shell shell) {
340
341         super.configureShell(shell);
342
343         createTrimWidgets(shell);
344     }
345
346     /**
347      * Creates the trim widgets around the content area.
348      *
349      * @param shell the shell
350      * @since 3.0
351      */

352     protected void createTrimWidgets(Shell shell) {
353         if (menuBarManager != null) {
354             menuBarManager.updateAll(true);
355             shell.setMenuBar(menuBarManager.createMenuBar((Decorations) shell));
356         }
357
358         if (showTopSeperator()) {
359             seperator1 = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
360         }
361
362         // will create either a cool bar or a tool bar
363
createToolBarControl(shell);
364         createCoolBarControl(shell);
365         createStatusLine(shell);
366     }
367
368     /* (non-Javadoc)
369      * @see org.eclipse.jface.window.Window#getLayout()
370      */

371     protected Layout getLayout() {
372         return new ApplicationWindowLayout();
373     }
374
375     /**
376      * Returns whether to show a top separator line between the menu bar
377      * and the rest of the window contents. On some platforms such as the Mac,
378      * the menu is separated from the main window already, so a separator line
379      * is not desired.
380      *
381      * @return <code>true</code> to show the top separator, <code>false</code>
382      * to not show it
383      * @since 3.0
384      */

385     protected boolean showTopSeperator() {
386         return !"carbon".equals(SWT.getPlatform()); //$NON-NLS-1$
387
}
388
389     /**
390      * Create the status line if required.
391      * @param shell
392      */

393     protected void createStatusLine(Shell shell) {
394         if (statusLineManager != null) {
395             statusLineManager.createControl(shell, SWT.NONE);
396         }
397     }
398
399     /**
400      * Returns a new menu manager for the window.
401      * <p>
402      * Subclasses may override this method to customize the menu manager.
403      * </p>
404      * @return a menu manager
405      */

406     protected MenuManager createMenuManager() {
407         return new MenuManager();
408     }
409
410     /**
411      * Returns a new status line manager for the window.
412      * <p>
413      * Subclasses may override this method to customize the status line manager.
414      * </p>
415      * @return a status line manager
416      */

417     protected StatusLineManager createStatusLineManager() {
418         return new StatusLineManager();
419     }
420
421     /**
422      * Returns a new tool bar manager for the window.
423      * <p>
424      * Subclasses may override this method to customize the tool bar manager.
425      * </p>
426      * @param style swt style bits used to create the Toolbar
427      *
428      * @return a tool bar manager
429      * @see ToolBarManager#ToolBarManager(int)
430      * @see ToolBar for style bits
431      */

432     protected ToolBarManager createToolBarManager(int style) {
433         return new ToolBarManager(style);
434     }
435     
436     /**
437      * Returns a new tool bar manager for the window.
438      * <p>
439      * By default this method calls <code>createToolBarManager</code>. Subclasses
440      * may override this method to provide an alternative implementation for the
441      * tool bar manager.
442      * </p>
443      *
444      * @param style swt style bits used to create the Toolbar
445      *
446      * @return a tool bar manager
447      * @since 3.2
448      * @see #createToolBarManager(int)
449      */

450     protected IToolBarManager createToolBarManager2(int style) {
451         return createToolBarManager(style);
452     }
453
454     /**
455      * Returns a new cool bar manager for the window.
456      * <p>
457      * Subclasses may override this method to customize the cool bar manager.
458      * </p>
459      *
460      * @param style swt style bits used to create the Coolbar
461      *
462      * @return a cool bar manager
463      * @since 3.0
464      * @see CoolBarManager#CoolBarManager(int)
465      * @see CoolBar for style bits
466      */

467     protected CoolBarManager createCoolBarManager(int style) {
468         return new CoolBarManager(style);
469     }
470     
471     /**
472      * Returns a new cool bar manager for the window.
473      * <p>
474      * By default this method calls <code>createCoolBarManager</code>. Subclasses
475      * may override this method to provide an alternative implementation for the
476      * cool bar manager.
477      * </p>
478      *
479      * @param style swt style bits used to create the Coolbar
480      *
481      * @return a cool bar manager
482      * @since 3.2
483      * @see #createCoolBarManager(int)
484      */

485     protected ICoolBarManager createCoolBarManager2(int style) {
486         return createCoolBarManager(style);
487     }
488
489     /**
490      * Creates the control for the tool bar manager.
491      * <p>
492      * Subclasses may override this method to customize the tool bar manager.
493      * </p>
494      * @param parent the parent used for the control
495      * @return a Control
496      */

497     protected Control createToolBarControl(Composite parent) {
498         if (toolBarManager != null) {
499             if (toolBarManager instanceof IToolBarManager2) {
500                 return ((IToolBarManager2) toolBarManager).createControl2(parent);
501             }
502             if (toolBarManager instanceof ToolBarManager) {
503                 return ((ToolBarManager) toolBarManager).createControl(parent);
504             }
505         }
506         return null;
507     }
508
509     /**
510      * Creates the control for the cool bar manager.
511      * <p>
512      * Subclasses may override this method to customize the cool bar manager.
513      * </p>
514      * @param composite the parent used for the control
515      *
516      * @return an instance of <code>CoolBar</code>
517      * @since 3.0
518      */

519     protected Control createCoolBarControl(Composite composite) {
520         if (coolBarManager != null) {
521             if (coolBarManager instanceof ICoolBarManager2) {
522                 return ((ICoolBarManager2) coolBarManager).createControl2(composite);
523             }
524             if (coolBarManager instanceof CoolBarManager) {
525                 return ((CoolBarManager) coolBarManager).createControl(composite);
526             }
527         }
528         return null;
529     }
530
531     /**
532      * Returns the default font used for this window.
533      * <p>
534      * The default implementation of this framework method
535      * obtains the symbolic name of the font from the
536      * <code>getSymbolicFontName</code> framework method
537      * and retrieves this font from JFace's font
538      * registry using <code>JFaceResources.getFont</code>.
539      * Subclasses may override to use a different registry,
540      * etc.
541      * </p>
542      *
543      * @return the default font, or <code>null</code> if none
544      */

545     protected Font getFont() {
546         return JFaceResources.getFont(getSymbolicFontName());
547     }
548
549     /**
550      * Returns the menu bar manager for this window (if it has one).
551      *
552      * @return the menu bar manager, or <code>null</code> if
553      * this window does not have a menu bar
554      * @see #addMenuBar()
555      */

556     public MenuManager getMenuBarManager() {
557         return menuBarManager;
558     }
559
560     /**
561      * Returns the status line manager for this window (if it has one).
562      *
563      * @return the status line manager, or <code>null</code> if
564      * this window does not have a status line
565      * @see #addStatusLine
566      */

567     protected StatusLineManager getStatusLineManager() {
568         return statusLineManager;
569     }
570
571     /**
572      * Returns the symbolic font name of the font to be
573      * used to display text in this window.
574      * This is not recommended and is included for backwards
575      * compatability.
576      * It is recommended to use the default font provided by
577      * SWT (that is, do not set the font).
578      *
579      * @return the symbolic font name
580      */

581     public String JavaDoc getSymbolicFontName() {
582         return JFaceResources.TEXT_FONT;
583     }
584
585     /**
586      * Returns the tool bar manager for this window (if it has one).
587      *
588      * @return the tool bar manager, or <code>null</code> if
589      * this window does not have a tool bar
590      * @see #addToolBar(int)
591      */

592     public ToolBarManager getToolBarManager() {
593         if (toolBarManager instanceof ToolBarManager) {
594             return (ToolBarManager)toolBarManager;
595         }
596         return null;
597     }
598     
599     /**
600      * Returns the tool bar manager for this window (if it has one).
601      *
602      * @return the tool bar manager, or <code>null</code> if
603      * this window does not have a tool bar
604      * @see #addToolBar(int)
605      * @since 3.2
606      */

607     public IToolBarManager getToolBarManager2() {
608         return toolBarManager;
609     }
610
611     /**
612      * Returns the cool bar manager for this window.
613      *
614      * @return the cool bar manager, or <code>null</code> if
615      * this window does not have a cool bar
616      * @see #addCoolBar(int)
617      * @since 3.0
618      */

619     public CoolBarManager getCoolBarManager() {
620         if (coolBarManager instanceof CoolBarManager) {
621             return (CoolBarManager)coolBarManager;
622         }
623         return null;
624     }
625     
626     /**
627      * Returns the cool bar manager for this window.
628      *
629      * @return the cool bar manager, or <code>null</code> if
630      * this window does not have a cool bar
631      * @see #addCoolBar(int)
632      * @since 3.2
633      */

634     public ICoolBarManager getCoolBarManager2() {
635         return coolBarManager;
636     }
637
638     /**
639      * Returns the control for the window's toolbar.
640      * <p>
641      * Subclasses may override this method to customize the tool bar manager.
642      * </p>
643      * @return a Control
644      */

645     protected Control getToolBarControl() {
646         if (toolBarManager != null) {
647             if (toolBarManager instanceof IToolBarManager2) {
648                 return ((IToolBarManager2) toolBarManager).getControl2();
649             }
650             if (toolBarManager instanceof ToolBarManager) {
651                 return ((ToolBarManager) toolBarManager).getControl();
652             }
653         }
654         return null;
655     }
656
657     /**
658      * Returns the control for the window's cool bar.
659      * <p>
660      * Subclasses may override this method to customize the cool bar manager.
661      * </p>
662      *
663      * @return an instance of <code>CoolBar</code>
664      * @since 3.0
665      */

666     protected Control getCoolBarControl() {
667         if (coolBarManager != null) {
668             if (coolBarManager instanceof ICoolBarManager2) {
669                 return ((ICoolBarManager2) coolBarManager).getControl2();
670             }
671             if (coolBarManager instanceof CoolBarManager) {
672                 return ((CoolBarManager) coolBarManager).getControl();
673             }
674         }
675         return null;
676     }
677
678     /**
679      * This implementation of IRunnableContext#run(boolean, boolean,
680      * IRunnableWithProgress) blocks until the runnable has been run,
681      * regardless of the value of <code>fork</code>.
682      * It is recommended that <code>fork</code> is set to
683      * true in most cases. If <code>fork</code> is set to <code>false</code>,
684      * the runnable will run in the UI thread and it is the runnable's
685      * responsibility to call <code>Display.readAndDispatch()</code>
686      * to ensure UI responsiveness.
687      */

688     public void run(final boolean fork, boolean cancelable,
689             final IRunnableWithProgress runnable)
690             throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
691         try {
692             operationInProgress = true;
693             final StatusLineManager mgr = getStatusLineManager();
694             if (mgr == null) {
695                 runnable.run(new NullProgressMonitor());
696                 return;
697             }
698             boolean cancelWasEnabled = mgr.isCancelEnabled();
699
700             final Control contents = getContents();
701             final Display display = contents.getDisplay();
702             Shell shell = getShell();
703             boolean contentsWasEnabled = contents.getEnabled();
704             MenuManager manager = getMenuBarManager();
705             Menu menuBar = null;
706             if (manager != null) {
707                 menuBar = manager.getMenu();
708                 manager = null;
709             }
710             boolean menuBarWasEnabled = false;
711             if (menuBar != null) {
712                 menuBarWasEnabled = menuBar.getEnabled();
713             }
714
715             Control toolbarControl = getToolBarControl();
716             boolean toolbarWasEnabled = false;
717             if (toolbarControl != null) {
718                 toolbarWasEnabled = toolbarControl.getEnabled();
719             }
720
721             Control coolbarControl = getCoolBarControl();
722             boolean coolbarWasEnabled = false;
723             if (coolbarControl != null) {
724                 coolbarWasEnabled = coolbarControl.getEnabled();
725             }
726
727             // Disable the rest of the shells on the current display
728
Shell[] shells = display.getShells();
729             boolean[] enabled = new boolean[shells.length];
730             for (int i = 0; i < shells.length; i++) {
731                 Shell current = shells[i];
732                 if (current == shell) {
733                     continue;
734                 }
735                 if (current != null && !current.isDisposed()) {
736                     enabled[i] = current.getEnabled();
737                     current.setEnabled(false);
738                 }
739             }
740
741             Control currentFocus = display.getFocusControl();
742             try {
743                 contents.setEnabled(false);
744                 if (menuBar != null) {
745                     menuBar.setEnabled(false);
746                 }
747                 if (toolbarControl != null) {
748                     toolbarControl.setEnabled(false);
749                 }
750                 if (coolbarControl != null) {
751                     coolbarControl.setEnabled(false);
752                 }
753                 mgr.setCancelEnabled(cancelable);
754                 final Exception JavaDoc[] holder = new Exception JavaDoc[1];
755                 BusyIndicator.showWhile(display, new Runnable JavaDoc() {
756                     public void run() {
757                         try {
758                             ModalContext.run(runnable, fork, mgr
759                                     .getProgressMonitor(), display);
760                         } catch (InvocationTargetException JavaDoc ite) {
761                             holder[0] = ite;
762                         } catch (InterruptedException JavaDoc ie) {
763                             holder[0] = ie;
764                         }
765                     }
766                 });
767
768                 if (holder[0] != null) {
769                     if (holder[0] instanceof InvocationTargetException JavaDoc) {
770                         throw (InvocationTargetException JavaDoc) holder[0];
771                     } else if (holder[0] instanceof InterruptedException JavaDoc) {
772                         throw (InterruptedException JavaDoc) holder[0];
773                     }
774                 }
775             } finally {
776                 operationInProgress = false;
777                 // Enable the rest of the shells on the current display
778
for (int i = 0; i < shells.length; i++) {
779                     Shell current = shells[i];
780                     if (current == shell) {
781                         continue;
782                     }
783                     if (current != null && !current.isDisposed()) {
784                         current.setEnabled(enabled[i]);
785                     }
786                 }
787                 if (!contents.isDisposed()) {
788                     contents.setEnabled(contentsWasEnabled);
789                 }
790                 if (menuBar != null && !menuBar.isDisposed()) {
791                     menuBar.setEnabled(menuBarWasEnabled);
792                 }
793                 if (toolbarControl != null && !toolbarControl.isDisposed()) {
794                     toolbarControl.setEnabled(toolbarWasEnabled);
795                 }
796                 if (coolbarControl != null && !coolbarControl.isDisposed()) {
797                     coolbarControl.setEnabled(coolbarWasEnabled);
798                 }
799                 mgr.setCancelEnabled(cancelWasEnabled);
800                 if (currentFocus != null && !currentFocus.isDisposed()) {
801                     // It's necessary to restore focus after reenabling the controls
802
// because disabling them causes focus to jump elsewhere.
803
// Use forceFocus rather than setFocus to avoid SWT's
804
// search for children which can take focus, so focus
805
// ends up back on the actual control that previously had it.
806
currentFocus.forceFocus();
807                 }
808             }
809         } finally {
810             operationInProgress = false;
811         }
812     }
813
814     /**
815      * Sets or clears the message displayed in this window's status
816      * line (if it has one). This method has no effect if the
817      * window does not have a status line.
818      *
819      * @param message the status message, or <code>null</code> to clear it
820      */

821     public void setStatus(String JavaDoc message) {
822         if (statusLineManager != null) {
823             statusLineManager.setMessage(message);
824         }
825     }
826
827     /**
828      * Returns whether or not children exist for the Application Window's
829      * toolbar control.
830      * <p>
831      * @return boolean true if children exist, false otherwise
832      */

833     protected boolean toolBarChildrenExist() {
834         Control toolControl = getToolBarControl();
835         if (toolControl instanceof ToolBar) {
836             return ((ToolBar) toolControl).getItemCount() > 0;
837         }
838         return false;
839     }
840
841     /**
842      * Returns whether or not children exist for this application window's
843      * cool bar control.
844      *
845      * @return boolean true if children exist, false otherwise
846      * @since 3.0
847      */

848     protected boolean coolBarChildrenExist() {
849         Control coolControl = getCoolBarControl();
850         if (coolControl instanceof CoolBar) {
851             return ((CoolBar) coolControl).getItemCount() > 0;
852         }
853         return false;
854     }
855
856 }
857
Popular Tags