1 11 package org.eclipse.debug.internal.ui.contexts; 12 13 import java.util.Collection ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.ListenerList; 18 import org.eclipse.debug.internal.ui.views.ViewContextManager; 19 import org.eclipse.debug.ui.contexts.IDebugContextListener; 20 import org.eclipse.debug.ui.contexts.IDebugContextManager; 21 import org.eclipse.debug.ui.contexts.IDebugContextService; 22 import org.eclipse.ui.IWindowListener; 23 import org.eclipse.ui.IWorkbenchWindow; 24 import org.eclipse.ui.PlatformUI; 25 26 29 public class DebugContextManager implements IDebugContextManager { 30 31 private static DebugContextManager fgDefault; 32 private Map fServices = new HashMap (); 33 private ListenerList fGlobalListeners = new ListenerList(); 34 35 private class WindowListener implements IWindowListener { 36 37 40 public void windowActivated(IWorkbenchWindow window) { 41 } 42 43 46 public void windowDeactivated(IWorkbenchWindow window) { 47 } 48 49 52 public void windowClosed(IWorkbenchWindow window) { 53 DebugWindowContextService service = (DebugWindowContextService) fServices.remove(window); 54 if (service != null) { 55 service.dispose(); 56 } 57 } 58 59 62 public void windowOpened(IWorkbenchWindow window) { 63 } 64 65 } 66 67 private DebugContextManager() { 68 PlatformUI.getWorkbench().addWindowListener(new WindowListener()); 69 } 70 71 public static IDebugContextManager getDefault() { 72 if (fgDefault == null) { 73 fgDefault = new DebugContextManager(); 74 DebugModelContextBindingManager.getDefault(); 76 ViewContextManager.getDefault(); 78 } 79 return fgDefault; 80 } 81 82 protected DebugWindowContextService createService(IWorkbenchWindow window) { 83 DebugWindowContextService service = (DebugWindowContextService) fServices.get(window); 84 if (service == null) { 85 service = new DebugWindowContextService(window); 86 fServices.put(window, service); 87 Object [] listeners = fGlobalListeners.getListeners(); 89 for (int i = 0; i < listeners.length; i++) { 90 IDebugContextListener listener = (IDebugContextListener) listeners[i]; 91 service.addDebugContextListener(listener); 92 } 93 } 94 return service; 95 } 96 97 protected IDebugContextService getService(IWorkbenchWindow window) { 98 return (DebugWindowContextService) fServices.get(window); 99 } 100 101 104 public void addDebugContextListener(IDebugContextListener listener) { 105 fGlobalListeners.add(listener); 106 DebugWindowContextService[] services = getServices(); 107 for (int i = 0; i < services.length; i++) { 108 DebugWindowContextService service = services[i]; 109 service.addDebugContextListener(listener); 110 } 111 } 112 113 116 public void removeDebugContextListener(IDebugContextListener listener) { 117 fGlobalListeners.remove(listener); 118 DebugWindowContextService[] services = getServices(); 119 for (int i = 0; i < services.length; i++) { 120 DebugWindowContextService service = services[i]; 121 service.removeDebugContextListener(listener); 122 } 123 } 124 125 130 private DebugWindowContextService[] getServices() { 131 Collection sevices = fServices.values(); 132 return (DebugWindowContextService[]) sevices.toArray(new DebugWindowContextService[sevices.size()]); 133 } 134 135 138 public IDebugContextService getContextService(IWorkbenchWindow window) { 139 return createService(window); 140 } 141 142 } 143 | Popular Tags |