1 11 package org.eclipse.debug.internal.ui.views; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 16 import org.eclipse.ui.IWindowListener; 17 import org.eclipse.ui.IWorkbench; 18 import org.eclipse.ui.IWorkbenchWindow; 19 import org.eclipse.ui.PlatformUI; 20 21 26 public class ViewContextManager implements IWindowListener { 27 28 31 private Map fWindowToService = new HashMap (); 32 33 private static ViewContextManager fgManager; 35 36 41 public static ViewContextManager getDefault() { 42 if (fgManager == null) { 43 fgManager = new ViewContextManager(); 44 } 45 return fgManager; 46 } 47 48 49 private ViewContextManager() { 50 IWorkbench workbench = PlatformUI.getWorkbench(); 51 IWorkbenchWindow[] workbenchWindows = workbench.getWorkbenchWindows(); 52 for (int i = 0; i < workbenchWindows.length; i++) { 53 IWorkbenchWindow window = workbenchWindows[i]; 54 windowOpened(window); 55 } 56 workbench.addWindowListener(this); 57 } 58 59 62 public void windowActivated(IWorkbenchWindow window) { 63 } 64 65 68 public void windowDeactivated(IWorkbenchWindow window) { 69 } 70 71 74 public void windowClosed(IWorkbenchWindow window) { 75 ViewContextService service = (ViewContextService) fWindowToService.get(window); 76 if (service != null) { 77 service.dispose(); 78 } 79 } 80 81 84 public void windowOpened(IWorkbenchWindow window) { 85 ViewContextService service = (ViewContextService) fWindowToService.get(window); 86 if (service == null) { 87 service = new ViewContextService(window); 88 fWindowToService.put(window, service); 89 } 90 } 91 92 98 public ViewContextService getService(IWorkbenchWindow window) { 99 return (ViewContextService) fWindowToService.get(window); 100 } 101 102 } 103 | Popular Tags |