📄 applicationwindow.java
字号:
* * <p> * <strong>EXPERIMENTAL</strong>. This method has been added as * part of a work in progress. There is a guarantee neither that this API will * work nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. * </p> * * @return a tool bar manager * @since 3.2 */ protected IToolBarManager createToolBarManager2(int style) { return createToolBarManager(style); } /** * Returns a new cool bar manager for the window. * <p> * Subclasses may override this method to customize the cool bar manager. * </p> * * @return a cool bar manager * @since 3.0 */ protected CoolBarManager createCoolBarManager(int style) { return new CoolBarManager(style); } /** * Returns a new cool bar manager for the window. * <p> * By default this method calls <code>createCoolBarManager</code>. Subclasses * may override this method to provide an alternative implementation for the * cool bar manager. * </p> * * <p> * <strong>EXPERIMENTAL</strong>. This method has been added as * part of a work in progress. There is a guarantee neither that this API will * work nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. * </p> * * @return a cool bar manager * @since 3.2 */ protected ICoolBarManager createCoolBarManager2(int style) { return createCoolBarManager(style); } /** * Creates the control for the tool bar manager. * <p> * Subclasses may override this method to customize the tool bar manager. * </p> * @return a Control */ protected Control createToolBarControl(Composite parent) { if (toolBarManager != null) { if (toolBarManager instanceof IToolBarManager2) { return ((IToolBarManager2) toolBarManager).createControl2(parent); } if (toolBarManager instanceof ToolBarManager) { return ((ToolBarManager) toolBarManager).createControl(parent); } } return null; } /** * Creates the control for the cool bar manager. * <p> * Subclasses may override this method to customize the cool bar manager. * </p> * * @return an instance of <code>CoolBar</code> * @since 3.0 */ protected Control createCoolBarControl(Composite composite) { if (coolBarManager != null) { if (coolBarManager instanceof ICoolBarManager2) { return ((ICoolBarManager2) coolBarManager).createControl2(composite); } if (coolBarManager instanceof CoolBarManager) { return ((CoolBarManager) coolBarManager).createControl(composite); } } return null; } /** * Returns the default font used for this window. * <p> * The default implementation of this framework method * obtains the symbolic name of the font from the * <code>getSymbolicFontName</code> framework method * and retrieves this font from JFace's font * registry using <code>JFaceResources.getFont</code>. * Subclasses may override to use a different registry, * etc. * </p> * * @return the default font, or <code>null</code> if none */ protected Font getFont() { return JFaceResources.getFont(getSymbolicFontName()); } /** * Returns the menu bar manager for this window (if it has one). * * @return the menu bar manager, or <code>null</code> if * this window does not have a menu bar * @see #addMenuBar() */ public MenuManager getMenuBarManager() { return menuBarManager; } /** * Returns the status line manager for this window (if it has one). * * @return the status line manager, or <code>null</code> if * this window does not have a status line * @see #addStatusLine */ protected StatusLineManager getStatusLineManager() { return statusLineManager; } /** * Returns the symbolic font name of the font to be * used to display text in this window. * This is not recommended and is included for backwards * compatability. * It is recommended to use the default font provided by * SWT (that is, do not set the font). * * @return the symbolic font name */ public String getSymbolicFontName() { return JFaceResources.TEXT_FONT; } /** * Returns the tool bar manager for this window (if it has one). * * @return the tool bar manager, or <code>null</code> if * this window does not have a tool bar * @see #addToolBar(int) */ public ToolBarManager getToolBarManager() { if (toolBarManager instanceof ToolBarManager) { return (ToolBarManager)toolBarManager; } return null; } /** * Returns the tool bar manager for this window (if it has one). * * <p> * <strong>EXPERIMENTAL</strong>. This class or interface has been added as * part of a work in progress. There is a guarantee neither that this API will * work nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. * </p> * * @return the tool bar manager, or <code>null</code> if * this window does not have a tool bar * @see #addToolBar(int) * @since 3.2 */ public IToolBarManager getToolBarManager2() { return toolBarManager; } /** * Returns the cool bar manager for this window. * * @return the cool bar manager, or <code>null</code> if * this window does not have a cool bar * @see #addCoolBar(int) * @since 3.0 */ public CoolBarManager getCoolBarManager() { if (coolBarManager instanceof CoolBarManager) { return (CoolBarManager)coolBarManager; } return null; } /** * Returns the cool bar manager for this window. * * <p> * <strong>EXPERIMENTAL</strong>. This class or interface has been added as * part of a work in progress. There is a guarantee neither that this API will * work nor that it will remain the same. Please do not use this API without * consulting with the Platform/UI team. * </p> * * @return the cool bar manager, or <code>null</code> if * this window does not have a cool bar * @see #addCoolBar(int) * @since 3.2 */ public ICoolBarManager getCoolBarManager2() { return coolBarManager; } /** * Returns the control for the window's toolbar. * <p> * Subclasses may override this method to customize the tool bar manager. * </p> * @return a Control */ protected Control getToolBarControl() { if (toolBarManager != null) { if (toolBarManager instanceof IToolBarManager2) { return ((IToolBarManager2) toolBarManager).getControl2(); } if (toolBarManager instanceof ToolBarManager) { return ((ToolBarManager) toolBarManager).getControl(); } } return null; } /** * Returns the control for the window's cool bar. * <p> * Subclasses may override this method to customize the cool bar manager. * </p> * * @return an instance of <code>CoolBar</code> * @since 3.0 */ protected Control getCoolBarControl() { if (coolBarManager != null) { if (coolBarManager instanceof ICoolBarManager2) { return ((ICoolBarManager2) coolBarManager).getControl2(); } if (coolBarManager instanceof CoolBarManager) { return ((CoolBarManager) coolBarManager).getControl(); } } return null; } /** * This implementation of IRunnableContext#run(boolean, boolean, * IRunnableWithProgress) blocks until the runnable has been run, * regardless of the value of <code>fork</code>. * It is recommended that <code>fork</code> is set to * true in most cases. If <code>fork</code> is set to <code>false</code>, * the runnable will run in the UI thread and it is the runnable's * responsibility to call <code>Display.readAndDispatch()</code> * to ensure UI responsiveness. */ public void run(final boolean fork, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException { try { operationInProgress = true; final StatusLineManager mgr = getStatusLineManager(); if (mgr == null) { runnable.run(new NullProgressMonitor()); return; } boolean cancelWasEnabled = mgr.isCancelEnabled(); final Control contents = getContents(); final Display display = contents.getDisplay(); Shell shell = getShell(); boolean contentsWasEnabled = contents.getEnabled(); MenuManager manager = getMenuBarManager(); Menu menuBar = null; if (manager != null) { menuBar = manager.getMenu(); manager = null; } boolean menuBarWasEnabled = false; if (menuBar != null) { menuBarWasEnabled = menuBar.isEnabled(); } Control toolbarControl = getToolBarControl(); boolean toolbarWasEnabled = false; if (toolbarControl != null) { toolbarWasEnabled = toolbarControl.getEnabled(); } Control coolbarControl = getCoolBarControl(); boolean coolbarWasEnabled = false; if (coolbarControl != null) { coolbarWasEnabled = coolbarControl.getEnabled(); } // Disable the rest of the shells on the current display Shell[] shells = display.getShells(); boolean[] enabled = new boolean[shells.length]; for (int i = 0; i < shells.length; i++) { Shell current = shells[i]; if (current == shell) { continue; } if (current != null && !current.isDisposed()) { enabled[i] = current.getEnabled(); current.setEnabled(false); } } Control currentFocus = display.getFocusControl(); try { contents.setEnabled(false); if (menuBar != null) { menuBar.setEnabled(false); } if (toolbarControl != null) { toolbarControl.setEnabled(false); } if (coolbarControl != null) { coolbarControl.setEnabled(false); } mgr.setCancelEnabled(cancelable); final Exception[] holder = new Exception[1]; BusyIndicator.showWhile(display, new Runnable() { public void run() { try { ModalContext.run(runnable, fork, mgr .getProgressMonitor(), display); } catch (InvocationTargetException ite) { holder[0] = ite; } catch (InterruptedException ie) { holder[0] = ie; } } }); if (holder[0] != null) { if (holder[0] instanceof InvocationTargetException) { throw (InvocationTargetException) holder[0]; } else if (holder[0] instanceof InterruptedException) { throw (InterruptedException) holder[0]; } } } finally { operationInProgress = false; // Enable the rest of the shells on the current display for (int i = 0; i < shells.length; i++) { Shell current = shells[i]; if (current == shell) { continue; } if (current != null && !current.isDisposed()) { current.setEnabled(enabled[i]); } } if (!contents.isDisposed()) { contents.setEnabled(contentsWasEnabled); } if (menuBar != null && !menuBar.isDisposed()) { menuBar.setEnabled(menuBarWasEnabled); } if (toolbarControl != null && !toolbarControl.isDisposed()) { toolbarControl.setEnabled(toolbarWasEnabled); } if (coolbarControl != null && !coolbarControl.isDisposed()) { coolbarControl.setEnabled(coolbarWasEnabled); } mgr.setCancelEnabled(cancelWasEnabled); if (currentFocus != null && !currentFocus.isDisposed()) { // It's necessary to restore focus after reenabling the controls // because disabling them causes focus to jump elsewhere. // Use forceFocus rather than setFocus to avoid SWT's // search for children which can take focus, so focus // ends up back on the actual control that previously had it. currentFocus.forceFocus(); } } } finally { operationInProgress = false; } } /** * Sets or clears the message displayed in this window's status * line (if it has one). This method has no effect if the * window does not have a status line. * * @param message the status message, or <code>null</code> to clear it */ public void setStatus(String message) { if (statusLineManager != null) { statusLineManager.setMessage(message); } } /** * Returns whether or not children exist for the Application Window's * toolbar control. * <p> * @return boolean true if children exist, false otherwise */ protected boolean toolBarChildrenExist() { Control toolControl = getToolBarControl(); if (toolControl instanceof ToolBar) { return ((ToolBar) toolControl).getItemCount() > 0; } return false; } /** * Returns whether or not children exist for this application window's * cool bar control. * * @return boolean true if children exist, false otherwise * @since 3.0 */ protected boolean coolBarChildrenExist() { Control coolControl = getCoolBarControl(); if (coolControl instanceof CoolBar) { return ((CoolBar) coolControl).getItemCount() > 0; } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -