001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Roman Dawydkin - bug 55116
011: *******************************************************************************/package org.eclipse.jface.window;
012:
013: import java.lang.reflect.InvocationTargetException;
014:
015: import org.eclipse.core.runtime.NullProgressMonitor;
016: import org.eclipse.jface.action.CoolBarManager;
017: import org.eclipse.jface.action.ICoolBarManager;
018: import org.eclipse.jface.action.IToolBarManager;
019: import org.eclipse.jface.action.MenuManager;
020: import org.eclipse.jface.action.StatusLineManager;
021: import org.eclipse.jface.action.ToolBarManager;
022: import org.eclipse.jface.internal.provisional.action.ICoolBarManager2;
023: import org.eclipse.jface.internal.provisional.action.IToolBarManager2;
024: import org.eclipse.jface.operation.IRunnableContext;
025: import org.eclipse.jface.operation.IRunnableWithProgress;
026: import org.eclipse.jface.operation.ModalContext;
027: import org.eclipse.jface.resource.JFaceResources;
028: import org.eclipse.swt.SWT;
029: import org.eclipse.swt.custom.BusyIndicator;
030: import org.eclipse.swt.graphics.Font;
031: import org.eclipse.swt.graphics.Point;
032: import org.eclipse.swt.graphics.Rectangle;
033: import org.eclipse.swt.widgets.Composite;
034: import org.eclipse.swt.widgets.Control;
035: import org.eclipse.swt.widgets.CoolBar;
036: import org.eclipse.swt.widgets.Decorations;
037: import org.eclipse.swt.widgets.Display;
038: import org.eclipse.swt.widgets.Label;
039: import org.eclipse.swt.widgets.Layout;
040: import org.eclipse.swt.widgets.Menu;
041: import org.eclipse.swt.widgets.Shell;
042: import org.eclipse.swt.widgets.ToolBar;
043:
044: /**
045: * An application window is a high-level "main window", with built-in
046: * support for an optional menu bar with standard menus, an optional toolbar,
047: * and an optional status line.
048: * <p>
049: * Creating an application window involves the following steps:
050: * <ul>
051: * <li>creating an instance of <code>ApplicationWindow</code>
052: * </li>
053: * <li>assigning the window to a window manager (optional)
054: * </li>
055: * <li>opening the window by calling <code>open</code>
056: * </li>
057: * </ul>
058: * Only on the last step, when the window is told to open, are
059: * the window's shell and widget tree created. When the window is
060: * closed, the shell and widget tree are disposed of and are no longer
061: * referenced, and the window is automatically removed from its window
062: * manager. Like all windows, an application window may be reopened.
063: * </p>
064: * <p>
065: * An application window is also a suitable context in which to perform
066: * long-running operations (that is, it implements <code>IRunnableContext</code>).
067: * </p>
068: */
069: public class ApplicationWindow extends Window implements
070: IRunnableContext {
071:
072: /**
073: * Menu bar manager, or <code>null</code> if none (default).
074: *
075: * @see #addMenuBar
076: */
077: private MenuManager menuBarManager = null;
078:
079: /**
080: * Tool bar manager, or <code>null</code> if none (default).
081: *
082: * @see #addToolBar
083: */
084: private IToolBarManager toolBarManager = null;
085:
086: /**
087: * Status line manager, or <code>null</code> if none (default).
088: *
089: * @see #addStatusLine
090: */
091: private StatusLineManager statusLineManager = null;
092:
093: /**
094: * Cool bar manager, or <code>null</code> if none (default).
095: *
096: * @see #addCoolBar
097: * @since 3.0
098: */
099: private ICoolBarManager coolBarManager = null;
100:
101: /**
102: * The seperator between the menu bar and the rest of the window.
103: */
104: protected Label seperator1;
105:
106: /**
107: * A flag indicating that an operation is running.
108: */
109: private boolean operationInProgress = false;
110:
111: /**
112: * Internal application window layout class.
113: * This vertical layout supports a tool bar area (fixed size),
114: * a separator line, the content area (variable size), and a
115: * status line (fixed size).
116: */
117: /*package*/class ApplicationWindowLayout extends Layout {
118:
119: static final int VGAP = 2;
120:
121: static final int BAR_SIZE = 23;
122:
123: protected Point computeSize(Composite composite, int wHint,
124: int hHint, boolean flushCache) {
125: if (wHint != SWT.DEFAULT && hHint != SWT.DEFAULT) {
126: return new Point(wHint, hHint);
127: }
128:
129: Point result = new Point(0, 0);
130: Control[] ws = composite.getChildren();
131: for (int i = 0; i < ws.length; i++) {
132: Control w = ws[i];
133:
134: boolean hide = false;
135: if (getToolBarControl() == w) {
136: if (!toolBarChildrenExist()) {
137: hide = true;
138: result.y += BAR_SIZE; // REVISIT
139: }
140: } else if (getCoolBarControl() == w) {
141: if (!coolBarChildrenExist()) {
142: hide = true;
143: result.y += BAR_SIZE;
144: }
145: } else if (statusLineManager != null
146: && statusLineManager.getControl() == w) {
147: } else if (i > 0) { /* we assume this window is contents */
148: hide = false;
149: }
150:
151: if (!hide) {
152: Point e = w.computeSize(wHint, hHint, flushCache);
153: result.x = Math.max(result.x, e.x);
154: result.y += e.y + VGAP;
155: }
156: }
157:
158: if (wHint != SWT.DEFAULT) {
159: result.x = wHint;
160: }
161: if (hHint != SWT.DEFAULT) {
162: result.y = hHint;
163: }
164: return result;
165: }
166:
167: protected void layout(Composite composite, boolean flushCache) {
168: Rectangle clientArea = composite.getClientArea();
169:
170: Control[] ws = composite.getChildren();
171:
172: // Lay out the separator, the tool bar control, the cool bar control, the status line, and the page composite.
173: // The following code assumes that the page composite is the last child, and that there are no unexpected other controls.
174:
175: for (int i = 0; i < ws.length; i++) {
176: Control w = ws[i];
177:
178: if (w == seperator1) { // Separator
179: Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
180: flushCache);
181: w.setBounds(clientArea.x, clientArea.y,
182: clientArea.width, e.y);
183: clientArea.y += e.y;
184: clientArea.height -= e.y;
185: } else if (getToolBarControl() == w) {
186: if (toolBarChildrenExist()) {
187: Point e = w.computeSize(SWT.DEFAULT,
188: SWT.DEFAULT, flushCache);
189: w.setBounds(clientArea.x, clientArea.y,
190: clientArea.width, e.y);
191: clientArea.y += e.y + VGAP;
192: clientArea.height -= e.y + VGAP;
193: }
194: } else if (getCoolBarControl() == w) {
195: if (coolBarChildrenExist()) {
196: Point e = w.computeSize(clientArea.width,
197: SWT.DEFAULT, flushCache);
198: w.setBounds(clientArea.x, clientArea.y,
199: clientArea.width, e.y);
200: clientArea.y += e.y + VGAP;
201: clientArea.height -= e.y + VGAP;
202: }
203: } else if (statusLineManager != null
204: && statusLineManager.getControl() == w) {
205: Point e = w.computeSize(SWT.DEFAULT, SWT.DEFAULT,
206: flushCache);
207: w.setBounds(clientArea.x, clientArea.y
208: + clientArea.height - e.y,
209: 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
356: .createMenuBar((Decorations) shell));
357: }
358:
359: if (showTopSeperator()) {
360: seperator1 = new Label(shell, SWT.SEPARATOR
361: | SWT.HORIZONTAL);
362: }
363:
364: // will create either a cool bar or a tool bar
365: createToolBarControl(shell);
366: createCoolBarControl(shell);
367: createStatusLine(shell);
368: }
369:
370: /* (non-Javadoc)
371: * @see org.eclipse.jface.window.Window#getLayout()
372: */
373: protected Layout getLayout() {
374: return new ApplicationWindowLayout();
375: }
376:
377: /**
378: * Returns whether to show a top separator line between the menu bar
379: * and the rest of the window contents. On some platforms such as the Mac,
380: * the menu is separated from the main window already, so a separator line
381: * is not desired.
382: *
383: * @return <code>true</code> to show the top separator, <code>false</code>
384: * to not show it
385: * @since 3.0
386: */
387: protected boolean showTopSeperator() {
388: return !"carbon".equals(SWT.getPlatform()); //$NON-NLS-1$
389: }
390:
391: /**
392: * Create the status line if required.
393: * @param shell
394: */
395: protected void createStatusLine(Shell shell) {
396: if (statusLineManager != null) {
397: statusLineManager.createControl(shell, SWT.NONE);
398: }
399: }
400:
401: /**
402: * Returns a new menu manager for the window.
403: * <p>
404: * Subclasses may override this method to customize the menu manager.
405: * </p>
406: * @return a menu manager
407: */
408: protected MenuManager createMenuManager() {
409: return new MenuManager();
410: }
411:
412: /**
413: * Returns a new status line manager for the window.
414: * <p>
415: * Subclasses may override this method to customize the status line manager.
416: * </p>
417: * @return a status line manager
418: */
419: protected StatusLineManager createStatusLineManager() {
420: return new StatusLineManager();
421: }
422:
423: /**
424: * Returns a new tool bar manager for the window.
425: * <p>
426: * Subclasses may override this method to customize the tool bar manager.
427: * </p>
428: * @param style swt style bits used to create the Toolbar
429: *
430: * @return a tool bar manager
431: * @see ToolBarManager#ToolBarManager(int)
432: * @see ToolBar for style bits
433: */
434: protected ToolBarManager createToolBarManager(int style) {
435: return new ToolBarManager(style);
436: }
437:
438: /**
439: * Returns a new tool bar manager for the window.
440: * <p>
441: * By default this method calls <code>createToolBarManager</code>. Subclasses
442: * may override this method to provide an alternative implementation for the
443: * tool bar manager.
444: * </p>
445: *
446: * @param style swt style bits used to create the Toolbar
447: *
448: * @return a tool bar manager
449: * @since 3.2
450: * @see #createToolBarManager(int)
451: */
452: protected IToolBarManager createToolBarManager2(int style) {
453: return createToolBarManager(style);
454: }
455:
456: /**
457: * Returns a new cool bar manager for the window.
458: * <p>
459: * Subclasses may override this method to customize the cool bar manager.
460: * </p>
461: *
462: * @param style swt style bits used to create the Coolbar
463: *
464: * @return a cool bar manager
465: * @since 3.0
466: * @see CoolBarManager#CoolBarManager(int)
467: * @see CoolBar for style bits
468: */
469: protected CoolBarManager createCoolBarManager(int style) {
470: return new CoolBarManager(style);
471: }
472:
473: /**
474: * Returns a new cool bar manager for the window.
475: * <p>
476: * By default this method calls <code>createCoolBarManager</code>. Subclasses
477: * may override this method to provide an alternative implementation for the
478: * cool bar manager.
479: * </p>
480: *
481: * @param style swt style bits used to create the Coolbar
482: *
483: * @return a cool bar manager
484: * @since 3.2
485: * @see #createCoolBarManager(int)
486: */
487: protected ICoolBarManager createCoolBarManager2(int style) {
488: return createCoolBarManager(style);
489: }
490:
491: /**
492: * Creates the control for the tool bar manager.
493: * <p>
494: * Subclasses may override this method to customize the tool bar manager.
495: * </p>
496: * @param parent the parent used for the control
497: * @return a Control
498: */
499: protected Control createToolBarControl(Composite parent) {
500: if (toolBarManager != null) {
501: if (toolBarManager instanceof IToolBarManager2) {
502: return ((IToolBarManager2) toolBarManager)
503: .createControl2(parent);
504: }
505: if (toolBarManager instanceof ToolBarManager) {
506: return ((ToolBarManager) toolBarManager)
507: .createControl(parent);
508: }
509: }
510: return null;
511: }
512:
513: /**
514: * Creates the control for the cool bar manager.
515: * <p>
516: * Subclasses may override this method to customize the cool bar manager.
517: * </p>
518: * @param composite the parent used for the control
519: *
520: * @return an instance of <code>CoolBar</code>
521: * @since 3.0
522: */
523: protected Control createCoolBarControl(Composite composite) {
524: if (coolBarManager != null) {
525: if (coolBarManager instanceof ICoolBarManager2) {
526: return ((ICoolBarManager2) coolBarManager)
527: .createControl2(composite);
528: }
529: if (coolBarManager instanceof CoolBarManager) {
530: return ((CoolBarManager) coolBarManager)
531: .createControl(composite);
532: }
533: }
534: return null;
535: }
536:
537: /**
538: * Returns the default font used for this window.
539: * <p>
540: * The default implementation of this framework method
541: * obtains the symbolic name of the font from the
542: * <code>getSymbolicFontName</code> framework method
543: * and retrieves this font from JFace's font
544: * registry using <code>JFaceResources.getFont</code>.
545: * Subclasses may override to use a different registry,
546: * etc.
547: * </p>
548: *
549: * @return the default font, or <code>null</code> if none
550: */
551: protected Font getFont() {
552: return JFaceResources.getFont(getSymbolicFontName());
553: }
554:
555: /**
556: * Returns the menu bar manager for this window (if it has one).
557: *
558: * @return the menu bar manager, or <code>null</code> if
559: * this window does not have a menu bar
560: * @see #addMenuBar()
561: */
562: public MenuManager getMenuBarManager() {
563: return menuBarManager;
564: }
565:
566: /**
567: * Returns the status line manager for this window (if it has one).
568: *
569: * @return the status line manager, or <code>null</code> if
570: * this window does not have a status line
571: * @see #addStatusLine
572: */
573: protected StatusLineManager getStatusLineManager() {
574: return statusLineManager;
575: }
576:
577: /**
578: * Returns the symbolic font name of the font to be
579: * used to display text in this window.
580: * This is not recommended and is included for backwards
581: * compatability.
582: * It is recommended to use the default font provided by
583: * SWT (that is, do not set the font).
584: *
585: * @return the symbolic font name
586: */
587: public String getSymbolicFontName() {
588: return JFaceResources.TEXT_FONT;
589: }
590:
591: /**
592: * Returns the tool bar manager for this window (if it has one).
593: *
594: * @return the tool bar manager, or <code>null</code> if
595: * this window does not have a tool bar
596: * @see #addToolBar(int)
597: */
598: public ToolBarManager getToolBarManager() {
599: if (toolBarManager instanceof ToolBarManager) {
600: return (ToolBarManager) toolBarManager;
601: }
602: return null;
603: }
604:
605: /**
606: * Returns the tool bar manager for this window (if it has one).
607: *
608: * @return the tool bar manager, or <code>null</code> if
609: * this window does not have a tool bar
610: * @see #addToolBar(int)
611: * @since 3.2
612: */
613: public IToolBarManager getToolBarManager2() {
614: return toolBarManager;
615: }
616:
617: /**
618: * Returns the cool bar manager for this window.
619: *
620: * @return the cool bar manager, or <code>null</code> if
621: * this window does not have a cool bar
622: * @see #addCoolBar(int)
623: * @since 3.0
624: */
625: public CoolBarManager getCoolBarManager() {
626: if (coolBarManager instanceof CoolBarManager) {
627: return (CoolBarManager) coolBarManager;
628: }
629: return null;
630: }
631:
632: /**
633: * Returns the cool bar manager for this window.
634: *
635: * @return the cool bar manager, or <code>null</code> if
636: * this window does not have a cool bar
637: * @see #addCoolBar(int)
638: * @since 3.2
639: */
640: public ICoolBarManager getCoolBarManager2() {
641: return coolBarManager;
642: }
643:
644: /**
645: * Returns the control for the window's toolbar.
646: * <p>
647: * Subclasses may override this method to customize the tool bar manager.
648: * </p>
649: * @return a Control
650: */
651: protected Control getToolBarControl() {
652: if (toolBarManager != null) {
653: if (toolBarManager instanceof IToolBarManager2) {
654: return ((IToolBarManager2) toolBarManager)
655: .getControl2();
656: }
657: if (toolBarManager instanceof ToolBarManager) {
658: return ((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 != null) {
675: if (coolBarManager instanceof ICoolBarManager2) {
676: return ((ICoolBarManager2) coolBarManager)
677: .getControl2();
678: }
679: if (coolBarManager instanceof CoolBarManager) {
680: return ((CoolBarManager) coolBarManager).getControl();
681: }
682: }
683: return null;
684: }
685:
686: /**
687: * This implementation of IRunnableContext#run(boolean, boolean,
688: * IRunnableWithProgress) blocks until the runnable has been run,
689: * regardless of the value of <code>fork</code>.
690: * It is recommended that <code>fork</code> is set to
691: * true in most cases. If <code>fork</code> is set to <code>false</code>,
692: * the runnable will run in the UI thread and it is the runnable's
693: * responsibility to call <code>Display.readAndDispatch()</code>
694: * to ensure UI responsiveness.
695: */
696: public void run(final boolean fork, boolean cancelable,
697: final IRunnableWithProgress runnable)
698: throws InvocationTargetException, InterruptedException {
699: try {
700: operationInProgress = true;
701: final StatusLineManager mgr = getStatusLineManager();
702: if (mgr == null) {
703: runnable.run(new NullProgressMonitor());
704: return;
705: }
706: boolean cancelWasEnabled = mgr.isCancelEnabled();
707:
708: final Control contents = getContents();
709: final Display display = contents.getDisplay();
710: Shell shell = getShell();
711: boolean contentsWasEnabled = contents.getEnabled();
712: MenuManager manager = getMenuBarManager();
713: Menu menuBar = null;
714: if (manager != null) {
715: menuBar = manager.getMenu();
716: manager = null;
717: }
718: boolean menuBarWasEnabled = false;
719: if (menuBar != null) {
720: menuBarWasEnabled = menuBar.getEnabled();
721: }
722:
723: Control toolbarControl = getToolBarControl();
724: boolean toolbarWasEnabled = false;
725: if (toolbarControl != null) {
726: toolbarWasEnabled = toolbarControl.getEnabled();
727: }
728:
729: Control coolbarControl = getCoolBarControl();
730: boolean coolbarWasEnabled = false;
731: if (coolbarControl != null) {
732: coolbarWasEnabled = coolbarControl.getEnabled();
733: }
734:
735: // Disable the rest of the shells on the current display
736: Shell[] shells = display.getShells();
737: boolean[] enabled = new boolean[shells.length];
738: for (int i = 0; i < shells.length; i++) {
739: Shell current = shells[i];
740: if (current == shell) {
741: continue;
742: }
743: if (current != null && !current.isDisposed()) {
744: enabled[i] = current.getEnabled();
745: current.setEnabled(false);
746: }
747: }
748:
749: Control currentFocus = display.getFocusControl();
750: try {
751: contents.setEnabled(false);
752: if (menuBar != null) {
753: menuBar.setEnabled(false);
754: }
755: if (toolbarControl != null) {
756: toolbarControl.setEnabled(false);
757: }
758: if (coolbarControl != null) {
759: coolbarControl.setEnabled(false);
760: }
761: mgr.setCancelEnabled(cancelable);
762: final Exception[] holder = new Exception[1];
763: BusyIndicator.showWhile(display, new Runnable() {
764: public void run() {
765: try {
766: ModalContext.run(runnable, fork, mgr
767: .getProgressMonitor(), display);
768: } catch (InvocationTargetException ite) {
769: holder[0] = ite;
770: } catch (InterruptedException ie) {
771: holder[0] = ie;
772: }
773: }
774: });
775:
776: if (holder[0] != null) {
777: if (holder[0] instanceof InvocationTargetException) {
778: throw (InvocationTargetException) holder[0];
779: } else if (holder[0] instanceof InterruptedException) {
780: throw (InterruptedException) holder[0];
781: }
782: }
783: } finally {
784: operationInProgress = false;
785: // Enable the rest of the shells on the current display
786: for (int i = 0; i < shells.length; i++) {
787: Shell current = shells[i];
788: if (current == shell) {
789: continue;
790: }
791: if (current != null && !current.isDisposed()) {
792: current.setEnabled(enabled[i]);
793: }
794: }
795: if (!contents.isDisposed()) {
796: contents.setEnabled(contentsWasEnabled);
797: }
798: if (menuBar != null && !menuBar.isDisposed()) {
799: menuBar.setEnabled(menuBarWasEnabled);
800: }
801: if (toolbarControl != null
802: && !toolbarControl.isDisposed()) {
803: toolbarControl.setEnabled(toolbarWasEnabled);
804: }
805: if (coolbarControl != null
806: && !coolbarControl.isDisposed()) {
807: coolbarControl.setEnabled(coolbarWasEnabled);
808: }
809: mgr.setCancelEnabled(cancelWasEnabled);
810: if (currentFocus != null && !currentFocus.isDisposed()) {
811: // It's necessary to restore focus after reenabling the controls
812: // because disabling them causes focus to jump elsewhere.
813: // Use forceFocus rather than setFocus to avoid SWT's
814: // search for children which can take focus, so focus
815: // ends up back on the actual control that previously had it.
816: currentFocus.forceFocus();
817: }
818: }
819: } finally {
820: operationInProgress = false;
821: }
822: }
823:
824: /**
825: * Sets or clears the message displayed in this window's status
826: * line (if it has one). This method has no effect if the
827: * window does not have a status line.
828: *
829: * @param message the status message, or <code>null</code> to clear it
830: */
831: public void setStatus(String message) {
832: if (statusLineManager != null) {
833: statusLineManager.setMessage(message);
834: }
835: }
836:
837: /**
838: * Returns whether or not children exist for the Application Window's
839: * toolbar control.
840: * <p>
841: * @return boolean true if children exist, false otherwise
842: */
843: protected boolean toolBarChildrenExist() {
844: Control toolControl = getToolBarControl();
845: if (toolControl instanceof ToolBar) {
846: return ((ToolBar) toolControl).getItemCount() > 0;
847: }
848: return false;
849: }
850:
851: /**
852: * Returns whether or not children exist for this application window's
853: * cool bar control.
854: *
855: * @return boolean true if children exist, false otherwise
856: * @since 3.0
857: */
858: protected boolean coolBarChildrenExist() {
859: Control coolControl = getCoolBarControl();
860: if (coolControl instanceof CoolBar) {
861: return ((CoolBar) coolControl).getItemCount() > 0;
862: }
863: return false;
864: }
865:
866: }
|