1 19 20 package org.netbeans.modules.openide.windows; 21 22 import org.openide.util.Lookup; 23 import org.openide.util.ContextGlobalProvider; 24 import org.openide.util.lookup.Lookups; 25 import org.openide.util.lookup.ProxyLookup; 26 import org.openide.windows.TopComponent; 27 28 33 public final class GlobalActionContextImpl extends Object 34 implements ContextGlobalProvider, Lookup.Provider, java.beans.PropertyChangeListener { 35 36 private TopComponent.Registry registry; 37 38 public GlobalActionContextImpl () { 39 this (TopComponent.getRegistry()); 40 } 41 42 public GlobalActionContextImpl (TopComponent.Registry r) { 43 this.registry = r; 44 } 45 46 47 private static volatile Lookup temporary; 48 50 public static void blickActionMap (javax.swing.ActionMap map) { 51 Object obj = Lookup.getDefault ().lookup (ContextGlobalProvider.class); 52 if (obj instanceof GlobalActionContextImpl) { 53 GlobalActionContextImpl g = (GlobalActionContextImpl)obj; 54 55 Lookup[] arr = { 56 Lookups.singleton (map), 57 Lookups.exclude (g.getLookup (), new Class [] { javax.swing.ActionMap .class }), 58 }; 59 60 Lookup prev = temporary; 61 try { 62 temporary = new ProxyLookup (arr); 63 Object q = org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap .class); 64 assert q == map : "We really get map from the lookup. Map: " + map + " returned: " + q; } finally { 66 temporary = prev; 67 org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap .class); 69 } 70 } 71 } 72 73 76 public Lookup createGlobalContext() { 77 registry.addPropertyChangeListener(this); 78 return org.openide.util.lookup.Lookups.proxy(this); 79 } 80 81 82 public Lookup getLookup() { 83 Lookup l = temporary; 84 if (l != null) { 85 return l; 86 } 87 88 TopComponent tc = registry.getActivated(); 89 return tc == null ? Lookup.EMPTY : tc.getLookup(); 90 } 91 92 94 public void propertyChange(java.beans.PropertyChangeEvent evt) { 95 if (TopComponent.Registry.PROP_ACTIVATED.equals (evt.getPropertyName())) { 96 org.openide.util.Utilities.actionsGlobalContext ().lookup (javax.swing.ActionMap .class); 97 } 98 } 99 100 } 101 | Popular Tags |