/** Reset cache, for use from unit tests. */ static void reset() { cache = null; result = Lookup.getDefault().lookupResult(URLMapper.class); result.addLookupListener( new LookupListener() { public void resultChanged(LookupEvent ev) { synchronized (URLMapper.class) { cache = null; } } } ); }
/** * Find all instances corresponding to a given class. * Equivalent to calling {@link #lookupResult} and asking for {@link Lookup.Result#allInstances} but slightly more convenient. * Subclasses may override this method to produce the same semantics more efficiently. * <div class="nonnormative"> * <p>Example usage:</p> * <pre> * for (MyService svc : Lookup.getDefault().lookupAll(MyService.class)) { * svc.useMe(); * } * </pre> * </div> * @param clazz the supertype of the result * @return all currently available instances of that type * @since org.openide.util 6.10 */ public <T> Collection<? extends T> lookupAll(Class<T> clazz) { return lookupResult(clazz).allInstances(); }
/** Blocks on lookup and after the lookup returns updates * delegates and adds a listener. */ public void initialize() { r = Lookup.getDefault().lookupResult(ErrorManager.class); setDelegates(r.allInstances()); }
public @Override InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { if (result == null) { result = Lookup.getDefault().lookupResult(EntityCatalog.class); } for (EntityCatalog res : result.allInstances()) { // using resolver's method because EntityCatalog extends EntityResolver InputSource is = res.resolveEntity(publicID, systemID); if (is != null) { return is; } } if (systemID != null && systemID.startsWith("http")) { // NOI18N Logger.getLogger(EntityCatalog.class.getName()).log( /* More of a problem when blocking EQ; cf. #157850: */ EventQueue.isDispatchThread() ? Level.WARNING : Level.FINE, "No resolver found for {0}", systemID); } return null; } }
public @Override synchronized URLStreamHandler createURLStreamHandler(final String protocol) { if (STANDARD_PROTOCOLS.contains(protocol)) { // Well-known handlers in JRE. Do not try to initialize lookup. return null; } if (!results.containsKey(protocol)) { final Lookup.Result<URLStreamHandler> result = Lookups.forPath("URLStreamHandler/" + protocol).lookupResult(URLStreamHandler.class); LookupListener listener = new LookupListener() { public @Override void resultChanged(LookupEvent ev) { synchronized (ProxyURLStreamHandlerFactory.this) { Collection<? extends URLStreamHandler> instances = result.allInstances(); handlers.put(protocol, instances.isEmpty() ? null : instances.iterator().next()); } } }; result.addLookupListener(listener); listener.resultChanged(null); results.put(protocol, result); } return handlers.get(protocol); } }
/** * Load a menu sequence from a lookup path. * Any {@link Action} instances are returned as is; * any {@link JSeparator} instances are translated to nulls. * Warnings are logged for any other instances. * @param path a path as given to {@link Lookups#forPath}, generally a layer folder name * @return a list of actions interspersed with null separators * @since org.openide.util 7.14 */ public static List<? extends Action> actionsForPath(String path) { List<Action> actions = new ArrayList<Action>(); for (Lookup.Item<Object> item : Lookups.forPath(path).lookupResult(Object.class).allItems()) { if (Action.class.isAssignableFrom(item.getType())) { Object instance = item.getInstance(); if (instance != null) { actions.add((Action) instance); } } else if (JSeparator.class.isAssignableFrom(item.getType())) { actions.add(null); } else { Logger.getLogger(Utilities.class.getName()).log(Level.WARNING, "Unrecognized object of {0} found in actions path {1}", new Object[] {item.getType(), path}); } } return actions; }
result = Lookup.getDefault().lookupResult(MIMEResolver.class); result.addLookupListener( new LookupListener() {
private Lookup.Result<Lookup.Provider> initSelectionAll() { assert Thread.holdsLock(CACHE); if (selectionAll == null) { Lookup.Result<Lookup.Provider> result = lookup.lookupResult(Lookup.Provider.class); selectionAll = new LSet<Lookup.Provider>(result, Lookup.Provider.class); } return selectionAll.result; }
@Override public void resultChanged(LookupEvent ev) { lookupResult = Lookup.getDefault().lookupResult(cls); register(); } }
private <T> Lookup.Result<T> findResult(final Class<T> type) { LSet<T> lset = findLSet(type); Lookup.Result<T> result; if (lset != null) { result = lset.result; } else { result = lookup.lookupResult(type); } return result; }
static void enhancedQueryMode(Lookup lookup, Class<?> clazz) { Object type = QUERY_MODE.get(); if (type != clazz) { return; } Collection<? extends Lookup.Item<?>> items = lookup.lookupResult(clazz).allItems(); if (items.size() == 0) { return; } AbstractLookup.Pair[] arr = new AbstractLookup.Pair[items.size()]; Iterator<? extends Lookup.Item> it = items.iterator(); for (int i = 0; i < arr.length; i++) { arr[i] = new PairWrap(it.next()); } QUERY_MODE.set(arr); }
/** Blocks on lookup and after the lookup returns updates * delegates and adds a listener. */ public void initialize() { r = Lookup.getDefault().lookupResult(ErrorManager.class); setDelegates(r.allInstances()); }
Iter() { result = Lookup.getDefault().lookupResult(AcceleratorBinding.class); resultChanged(null); result.addLookupListener(this); }
private GlobalManager(Lookup lookup) { this.listeners = new HashMap<Object,Set<GeneralAction.BaseDelAction>>(); this.result = lookup.lookupResult(ActionMap.class); result.addLookupListener(this); resultChanged(null); }
ButtonActionConnectorGetter() { result = Lookup.getDefault().lookupResult(ButtonActionConnector.class); result.addLookupListener(this); resultChanged(null); }
AbstractRegistrator(Class cls) { this.cls = cls; init(); lookupResult = Lookup.getDefault().lookupResult(cls); register(); lookupResult.addLookupListener(this); }
public DelegateAction(NodeAction a, Lookup actionContext) { this.delegate = a; this.result = actionContext.lookupResult(Node.class); this.result.addLookupListener(WeakListeners.create(LookupListener.class, this, this.result)); resultChanged(null); }
/** * Load a menu sequence from a lookup path. * Any {@link Action} instances are returned as is; * any {@link JSeparator} instances are translated to nulls. * Warnings are logged for any other instances. * @param path a path as given to {@link Lookups#forPath}, generally a layer folder name * @return a list of actions interspersed with null separators * @since org.openide.util 7.14 */ public static List<? extends Action> actionsForPath(String path) { List<Action> actions = new ArrayList<Action>(); for (Lookup.Item<Object> item : Lookups.forPath(path).lookupResult(Object.class).allItems()) { if (Action.class.isAssignableFrom(item.getType())) { Object instance = item.getInstance(); if (instance != null) { actions.add((Action) instance); } } else if (JSeparator.class.isAssignableFrom(item.getType())) { actions.add(null); } else { Logger.getLogger(Utilities.class.getName()).log(Level.WARNING, "Unrecognized object of {0} found in actions path {1}", new Object[] {item.getType(), path}); } } return actions; }
/** Activates/passivates the listener. */ synchronized void setActive(boolean active) { Lookup context = Utilities.actionsGlobalContext(); if (active) { if (result == null) { result = context.lookupResult(Node.class); result.addLookupListener(this); } } else { // result.removeLookupListener (this); // result = null; // Any saved PROP_ENABLED will be bogus now: forget(true); forget(false); } }
public <T> void registerListener(Class<T> type, ContextAction<T> a) { synchronized (CACHE) { LSet<T> existing = findLSet(type); if (existing == null) { Lookup.Result<T> result = createResult(lookup.lookupResult(type)); existing = new LSet<T>(result, type); listeners.put(type, existing); } existing.add(a); // TBD: a.updateState(new ActionMap(), actionMap.get()); if (a.selectMode == ContextSelection.ALL) { initSelectionAll(); selectionAll.add(a); } } }