org.openide.util.Lookup.lookupResult()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中org.openide.util.Lookup.lookupResult()方法的一些代码示例,展示了Lookup.lookupResult()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lookup.lookupResult()方法的具体详情如下:
包路径:org.openide.util.Lookup
类名称:Lookup
方法名:lookupResult

Lookup.lookupResult介绍

[英]Find a result corresponding to a given class. Equivalent to calling #lookup(Lookup.Template) but slightly more convenient. Subclasses may override this method to produce the same semantics more efficiently.
[中]查找与给定类对应的结果。相当于调用#lookup(lookup.Template),但稍微方便一些。子类可以重写此方法以更有效地生成相同的语义。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/** 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;
        }
      }
    }
  );
}

代码示例来源:origin: org.netbeans.api/org-openide-util-lookup

/**
 * 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();
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/** 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());
}

代码示例来源:origin: org.netbeans.api/org-openide-util

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;
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

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);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/**
 * 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;
}

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

result = Lookup.getDefault().lookupResult(MIMEResolver.class);
result.addLookupListener(
  new LookupListener() {

代码示例来源:origin: org.netbeans.api/org-openide-awt

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;
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

@Override
  public void resultChanged(LookupEvent ev) {
    lookupResult = Lookup.getDefault().lookupResult(cls);
    register();
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

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;
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

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);
}

代码示例来源:origin: org.netbeans.api/org-openide-util-ui

/** 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());
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

Iter() {
  result = Lookup.getDefault().lookupResult(AcceleratorBinding.class);
  resultChanged(null);
  result.addLookupListener(this);
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

private GlobalManager(Lookup lookup) {
  this.listeners = new HashMap<Object,Set<GeneralAction.BaseDelAction>>();
  this.result = lookup.lookupResult(ActionMap.class);
  result.addLookupListener(this);
  resultChanged(null);
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

ButtonActionConnectorGetter() {
  result = Lookup.getDefault().lookupResult(ButtonActionConnector.class);
  result.addLookupListener(this);
  resultChanged(null);
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

AbstractRegistrator(Class cls) {
  this.cls = cls;
  init();
  lookupResult = Lookup.getDefault().lookupResult(cls);
  register();
  lookupResult.addLookupListener(this);
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

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);
}

代码示例来源:origin: org.netbeans.api/org-openide-util-ui

/**
 * 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;
}

代码示例来源:origin: org.netbeans.api/org-openide-nodes

/** 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);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

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);
    }
  }
}

相关文章