Java Code Examples for org.openide.util.LookupListener#resultChanged()

The following examples show how to use org.openide.util.LookupListener#resultChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentBreakpointActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ComponentBreakpointActionProvider() {
    final Result<Node> nodeLookupResult = Utilities.actionsGlobalContext().lookupResult(Node.class);
    LookupListener ll = new LookupListener() {
        @Override
        public void resultChanged(LookupEvent ev) {
            Collection<? extends Node> nodeInstances = nodeLookupResult.allInstances();
            for (Node n : nodeInstances) {
                JavaComponentInfo ci = n.getLookup().lookup(JavaComponentInfo.class);
                if (ci != null) {
                    setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, true);
                    return ;
                }
            }
            setEnabled(ActionsManager.ACTION_TOGGLE_BREAKPOINT, false);
        }
    };
    nodeLookupResult.addLookupListener(ll);
    ll.resultChanged(null); // To initialize
}
 
Example 2
Source File: ProxyURLStreamHandlerFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: PathLookup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    synchronized (PathLookupResult.this) {
        items = null;
    }
    List<LookupListener> lls;
    synchronized (listeners) {
        if (listeners.isEmpty()) {
            return;
        } else {
            lls = new ArrayList<LookupListener>(listeners);
        }
    }
    LookupEvent lev = new LookupEvent(PathLookupResult.this);
    for (LookupListener ll : lls) {
        ll.resultChanged(lev);
    }
}
 
Example 4
Source File: AbstractLookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void run() {
    Iterator it = evAndListeners.iterator();
    while (it.hasNext()) {
        LookupEvent ev = (LookupEvent)it.next();
        LookupListener l = (LookupListener)it.next();
        try {
            l.resultChanged(ev);
        } catch (RuntimeException x) {
            LOG.log(Level.WARNING, null, x);
        }
    }
}
 
Example 5
Source File: ContextManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void resultChanged(LookupEvent ev) {
    if (ev.getSource() == nodes) {
        Collection<? extends Item<Provider>> arr = nodes.allItems();
        if (arr.size() == 1 && arr.iterator().next().getInstance() == null) {
            return;
        }
        initValues();
        return;
    }
    final LookupEvent mev = new LookupEvent(this);
    for (LookupListener ll : listeners) {
        ll.resultChanged(mev);
    }
}
 
Example 6
Source File: ServerInstanceLookup.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void stateChanged(ChangeEvent e) {
    List<LookupListener> toFire = new ArrayList<LookupListener>();
    synchronized (listeners) {
        toFire.addAll(listeners);
    }

    for (LookupListener listener : toFire) {
        listener.resultChanged(new LookupEvent(this));
    }

}
 
Example 7
Source File: SimpleProxyLookup.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Checks whether we still delegate to the same lookup */
private Lookup checkLookup() {
    Lookup l = provider.getLookup();

    // iterator over Reference (ProxyResult)
    Iterator<Reference<ProxyResult<?>>> toCheck = null;

    synchronized (this) {
        if (l != delegate) {
            this.delegate = l;

            if (results != null) {
                toCheck = new ArrayList<Reference<ProxyResult<?>>>(results.values()).iterator();
            }
        }
    }

    if (toCheck != null) {
        // update
        ArrayList<Object> evAndListeners = new ArrayList<Object>();
        for (Iterator<Reference<ProxyResult<?>>> it = toCheck; it.hasNext(); ) {
            java.lang.ref.Reference<ProxyResult<?>> ref = it.next();
            if (ref == null) {
                continue;
            }

            ProxyResult<?> p = ref.get();

            if (p != null && p.updateLookup(null, null)) {
                p.collectFires(evAndListeners);
            }
        }

        for (Iterator it = evAndListeners.iterator(); it.hasNext(); ) {
            LookupEvent ev = (LookupEvent)it.next();
            LookupListener ll = (LookupListener)it.next();
            ll.resultChanged(ev);
        }
    }
    return l;
}