private BusyIndicator getBusyLabel() { if (busyLabel != null) { return busyLabel; } try { FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead(); // ensure that busy label exists heading.setBusy(true); heading.setBusy(false); Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$ field.setAccessible(true); TitleRegion titleRegion = (TitleRegion) field.get(heading); for (Control child : titleRegion.getChildren()) { if (child instanceof BusyIndicator) { busyLabel = (BusyIndicator) child; } } if (busyLabel == null) { return null; } busyLabel.addControlListener( new ControlAdapter() { @Override public void controlMoved(ControlEvent e) { updateSizeAndLocations(); } }); // the busy label may get disposed if it has no image busyLabel.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { busyLabel.setMenu(null); busyLabel = null; } }); if (leftToolBar != null) { leftToolBar.moveAbove(busyLabel); } if (titleLabel != null) { titleLabel.moveAbove(busyLabel); } updateSizeAndLocations(); return busyLabel; } catch (Exception e) { if (!toolBarFailureLogged) { StatusHandler.log( new Status( IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to obtain busy label toolbar", e)); //$NON-NLS-1$ } busyLabel = null; } return busyLabel; }
@Override protected Composite createPageContainer(Composite parent) { this.editorParent = parent; Composite composite = super.createPageContainer(parent); EditorUtil.initializeScrollbars(getHeaderForm().getForm()); // create left tool bar that replaces form heading label try { FormHeading heading = (FormHeading) getHeaderForm().getForm().getForm().getHead(); Field field = FormHeading.class.getDeclaredField("titleRegion"); // $NON-NLS-1$ field.setAccessible(true); TitleRegion titleRegion = (TitleRegion) field.get(heading); leftToolBarManager = new ToolBarManager(SWT.FLAT); leftToolBar = leftToolBarManager.createControl(titleRegion); leftToolBar.addControlListener( new ControlAdapter() { private boolean ignoreResizeEvents; @Override public void controlResized(ControlEvent e) { if (ignoreResizeEvents) { return; } ignoreResizeEvents = true; try { // the tool bar contents has changed, update state updateHeaderImage(); updateHeaderLabel(); } finally { ignoreResizeEvents = false; } } }); // titleLabel = new Label(titleRegion, SWT.NONE); // need a viewer for copy support TextViewer titleViewer = new TextViewer(titleRegion, SWT.READ_ONLY); // Eclipse 3.3 needs a document, otherwise an NPE is thrown titleViewer.setDocument(new Document()); titleLabel = titleViewer.getTextWidget(); titleLabel.setForeground(heading.getForeground()); titleLabel.setFont(heading.getFont()); // XXX work-around problem that causes field to maintain selection when unfocused titleLabel.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { titleLabel.setSelection(0); } }); titleRegion.addControlListener( new ControlAdapter() { @Override public void controlResized(ControlEvent e) { // do not create busyLabel to avoid recursion updateSizeAndLocations(); } }); IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class); if (handlerService != null) { textSupport = new CommonTextSupport(handlerService); textSupport.install(titleViewer, false); } } catch (Exception e) { if (!toolBarFailureLogged) { StatusHandler.log( new Status( IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Failed to obtain busy label toolbar", e)); //$NON-NLS-1$ } if (titleLabel != null) { titleLabel.dispose(); titleLabel = null; } if (leftToolBar != null) { leftToolBar.dispose(); leftToolBar = null; } if (leftToolBarManager != null) { leftToolBarManager.dispose(); leftToolBarManager = null; } } updateHeader(); return composite; }