1 11 12 package org.eclipse.ui.application; 13 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.swt.widgets.Display; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.IMemento; 20 import org.eclipse.ui.IWorkbenchPreferenceConstants; 21 import org.eclipse.ui.IWorkbenchWindow; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.WorkbenchException; 24 import org.eclipse.ui.internal.StartupThreading; 25 import org.eclipse.ui.internal.UISynchronizer; 26 import org.eclipse.ui.internal.WorkbenchPlugin; 27 import org.eclipse.ui.internal.WorkbenchWindowConfigurer; 28 import org.eclipse.ui.internal.StartupThreading.StartupRunnable; 29 import org.eclipse.ui.internal.application.CompatibilityWorkbenchWindowAdvisor; 30 import org.eclipse.ui.internal.util.PrefUtil; 31 import org.eclipse.ui.statushandlers.AbstractStatusHandler; 32 import org.eclipse.ui.statushandlers.StatusManager; 33 import org.eclipse.ui.statushandlers.WorkbenchErrorHandler; 34 35 115 public abstract class WorkbenchAdvisor { 116 117 124 public static final int FILL_PROXY = ActionBarAdvisor.FILL_PROXY; 125 126 133 public static final int FILL_MENU_BAR = ActionBarAdvisor.FILL_MENU_BAR; 134 135 142 public static final int FILL_COOL_BAR = ActionBarAdvisor.FILL_COOL_BAR; 143 144 151 public static final int FILL_STATUS_LINE = ActionBarAdvisor.FILL_STATUS_LINE; 152 153 156 private IWorkbenchConfigurer workbenchConfigurer; 157 158 161 private AbstractStatusHandler workbenchErrorHandler; 162 163 private boolean introOpened; 164 165 168 protected WorkbenchAdvisor() { 169 } 171 172 181 public final void internalBasicInitialize(IWorkbenchConfigurer configurer) { 182 if (workbenchConfigurer != null) { 183 throw new IllegalStateException (); 184 } 185 this.workbenchConfigurer = configurer; 186 initialize(configurer); 187 } 188 189 203 public void initialize(IWorkbenchConfigurer configurer) { 204 } 206 207 214 protected IWorkbenchConfigurer getWorkbenchConfigurer() { 215 return workbenchConfigurer; 216 } 217 218 224 public AbstractStatusHandler getWorkbenchErrorHandler() { 225 if (workbenchErrorHandler == null) { 226 workbenchErrorHandler = new WorkbenchErrorHandler(); 227 } 228 return workbenchErrorHandler; 229 } 230 231 241 public void preStartup() { 242 } 244 245 255 public void postStartup() { 256 } 258 259 277 public boolean preShutdown() { 278 return true; 279 } 280 281 290 public void postShutdown() { 291 } 293 294 317 public void eventLoopException(Throwable exception) { 318 if (exception == null) { 320 return; 321 } 322 323 try { 324 StatusManager.getManager().handle( 325 new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH, 326 "Unhandled event loop exception", exception)); 328 if (WorkbenchPlugin.DEBUG) { 329 exception.printStackTrace(); 330 } 331 } catch (Throwable e) { 332 System.err.println("Error while logging event loop exception:"); exception.printStackTrace(); 337 System.err.println("Logging exception:"); e.printStackTrace(); 339 } 340 } 341 342 360 public void eventLoopIdle(Display display) { 361 display.sleep(); 363 } 364 365 381 public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( 382 IWorkbenchWindowConfigurer configurer) { 383 return new CompatibilityWorkbenchWindowAdvisor(this, configurer); 384 } 385 386 407 public void preWindowOpen(IWorkbenchWindowConfigurer configurer) { 408 } 410 411 457 public void fillActionBars(IWorkbenchWindow window, 458 IActionBarConfigurer configurer, int flags) { 459 } 461 462 483 public void postWindowRestore(IWorkbenchWindowConfigurer configurer) 484 throws WorkbenchException { 485 } 487 488 509 public void openIntro(IWorkbenchWindowConfigurer configurer) { 510 if (introOpened) { 511 return; 512 } 513 514 introOpened = true; 515 516 boolean showIntro = PrefUtil.getAPIPreferenceStore().getBoolean( 517 IWorkbenchPreferenceConstants.SHOW_INTRO); 518 519 if (!showIntro) { 520 return; 521 } 522 523 if (getWorkbenchConfigurer().getWorkbench().getIntroManager() 524 .hasIntro()) { 525 getWorkbenchConfigurer().getWorkbench().getIntroManager() 526 .showIntro(configurer.getWindow(), false); 527 528 PrefUtil.getAPIPreferenceStore().setValue( 529 IWorkbenchPreferenceConstants.SHOW_INTRO, false); 530 PrefUtil.saveAPIPrefs(); 531 } 532 } 533 534 553 public void postWindowCreate(IWorkbenchWindowConfigurer configurer) { 554 } 556 557 576 public void postWindowOpen(IWorkbenchWindowConfigurer configurer) { 577 } 579 580 606 public boolean preWindowShellClose(IWorkbenchWindowConfigurer configurer) { 607 return true; 609 } 610 611 629 public void postWindowClose(IWorkbenchWindowConfigurer configurer) { 630 } 632 633 653 public boolean isApplicationMenu(IWorkbenchWindowConfigurer configurer, 654 String menuId) { 655 return false; 657 } 658 659 672 public IAdaptable getDefaultPageInput() { 673 return null; 675 } 676 677 693 public abstract String getInitialWindowPerspectiveId(); 694 695 705 public String getMainPreferencePageId() { 706 return null; 708 } 709 710 737 public void createWindowContents(IWorkbenchWindowConfigurer configurer, 738 Shell shell) { 739 ((WorkbenchWindowConfigurer) configurer).createDefaultContents(shell); 740 } 741 742 753 public boolean openWindows() { 754 final Display display = PlatformUI.getWorkbench().getDisplay(); 755 final boolean result [] = new boolean[1]; 756 757 final boolean[] initDone = new boolean[]{false}; 762 final Throwable [] error = new Throwable [1]; 763 Thread initThread = new Thread () { 764 767 public void run() { 768 try { 769 UISynchronizer.startupThread.set(Boolean.TRUE); 771 final IWorkbenchConfigurer [] myConfigurer = new IWorkbenchConfigurer[1]; 772 StartupThreading.runWithoutExceptions(new StartupRunnable() { 773 774 public void runWithException() throws Throwable { 775 myConfigurer[0] = getWorkbenchConfigurer(); 776 777 }}); 778 779 IStatus status = myConfigurer[0].restoreState(); 780 if (!status.isOK()) { 781 if (status.getCode() == IWorkbenchConfigurer.RESTORE_CODE_EXIT) { 782 result[0] = false; 783 return; 784 } 785 if (status.getCode() == IWorkbenchConfigurer.RESTORE_CODE_RESET) { 786 myConfigurer[0].openFirstTimeWindow(); 787 } 788 } 789 result[0] = true; 790 } catch (Throwable e) { 791 error[0] = e; 792 } 793 finally { 794 initDone[0] = true; 795 display.wake(); 796 } 797 }}; 798 initThread.start(); 799 800 while (true) { 801 if (!display.readAndDispatch()) { 802 if (initDone[0]) 803 break; 804 display.sleep(); 805 } 806 807 } 808 809 if (error[0] instanceof Error ) 811 throw (Error )error[0]; 812 else if (error[0] instanceof RuntimeException ) 813 throw (RuntimeException )error[0]; 814 815 return result[0]; 816 } 817 818 831 public IStatus saveState(IMemento memento) { 832 return Status.OK_STATUS; 833 } 834 835 848 public IStatus restoreState(IMemento memento) { 849 return Status.OK_STATUS; 850 } 851 } | Popular Tags |