@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); } }
private synchronized void ensureTaskListLoaded () throws CoreException { if (!taskListInitialized) { if (result == null) { LookupListener lookupListener = new LookupListener() { @Override public void resultChanged (LookupEvent ev) { registerConnectors(); } }; result = Lookup.getDefault().lookupResult(RepositoryConnectorProvider.class); result.addLookupListener(lookupListener); } registerConnectors(); try { if (taskListStorageFile.length() > 0) { taskListWriter.readTaskList(taskList, taskListStorageFile); } } catch (CoreException ex) { LOG.log(Level.INFO, null, ex); throw new CoreException(new Status(ex.getStatus().getSeverity(), ex.getStatus().getPlugin(), "Cannot deserialize tasklist")); } finally { taskListInitialized = true; } } }
public void resultChanged(LookupEvent ev) { synchronized (listeners) { Collection current = allInstances(); boolean equal = lastResults != null && current != null && current.containsAll(lastResults) && lastResults.containsAll(current); if (equal) { // the merged list is the same, ignore... return ; } lastResults = current; } LookupEvent ev2 = new LookupEvent(this); LookupListener[] ls; synchronized (listeners) { ls = (LookupListener[])listeners.toArray(new LookupListener[listeners.size()]); } for (int i = 0; i < ls.length; i++) { ls[i].resultChanged(ev2); } }
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 }
private void initGroups() { synchronized( this ) { if( null == name2group ) { if( null == lookupRes ) { lookupRes = initLookup(); lookupRes.addLookupListener( new LookupListener() { public void resultChanged(LookupEvent ev) { synchronized( TaskGroupFactory.this ) { name2group = null; groups = null; } } }); } int index = 0; groups = new ArrayList<TaskGroup>( lookupRes.allInstances() ); name2group = new HashMap<String,TaskGroup>(groups.size()); for( TaskGroup tg : groups) { name2group.put( tg.getName(), tg ); tg.setIndex( index++ ); } } } }
@Override public void resultChanged(LookupEvent ev) { if (TopComponent.getRegistry().getActivated() == ProjectTab.this) { // Do not want to go into a loop. return; } if (synchronizeViews) { Collection<? extends FileObject> fos = foSelection.allInstances(); if (fos.size() == 1) { selectNodeAsyncNoSelect(fos.iterator().next(), false); } else { Collection<? extends DataObject> dos = doSelection.allInstances(); if (dos.size() == 1) { selectNodeAsyncNoSelect((dos.iterator().next()).getPrimaryFile(), false); } } } }
public void resultChanged(LookupEvent ev) { synchronized (lookupListener) { descriptorRef = new WeakReference<DialogDescriptor>(null); // #156947 - close dialog when categories change if (dialog != null) { Mutex.EVENT.readAccess(new Runnable() { @Override public void run() { if (dialog != null) { log.log(Level.FINE, "Options Dialog - closing dialog when categories change."); //NOI18N dialog.setVisible(false); dialog = null; } } }); } } }
@Override final public void resultChanged(LookupEvent lookupEvent) { boolean isNowSelected = false; Lookup.Result selected = (Lookup.Result)lookupEvent.getSource(); for (Object selectedEntity : selected.allInstances()) { if (agent.equals(selectedEntity)) { isNowSelected = true; } } if (isNowSelected != selectedFlag) { selectedFlag = isNowSelected; fireDisplayNameChange(null, null); } }
@Override protected void collectFires(Collection<Object> evAndListeners) { LookupListenerList l = this.getListeners(null, null); if (l == null) { return; } Object[] listeners = l.getListenerList(); if (listeners.length == 0) { return; } LookupEvent ev = new LookupEvent(this); AbstractLookup.notifyListeners(listeners, ev, evAndListeners); }
/** Get all available help sets. * Pay attention to {@link #helpSetsChanged} to see * when this set will change. * @return a collection of HelpSet */ protected final Collection<? extends HelpSet> getHelpSets() { if (helpsets == null) { Installer.log.fine("searching for instances of HelpSet..."); helpsets = Lookup.getDefault().lookupResult(HelpSet.class); helpsets.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { helpSetsChanged(); } }); fireChangeEvent(); // since someone may be listening to whether they are ready } Collection<? extends HelpSet> c = helpsets.allInstances(); if (Installer.log.isLoggable(Level.FINE)) { List<String> l = new ArrayList<String>(Math.min(1, c.size())); for (HelpSet hs: c) { l.add(hs.getTitle()); } Installer.log.fine("listing helpsets: " + l); } return c; }
/** Invokes navigator data context change upon current nodes change or * current navigator hints change, * performs coalescing of fast coming changes. */ @Override public void resultChanged(LookupEvent ev) { if (!navigatorTC.getTopComponent().equals(WindowManager.getDefault().getRegistry().getActivated()) // #117089: allow node change when we are empty || (curNodes == null || curNodes.isEmpty())) { Lookup globalContext = Utilities.actionsGlobalContext(); NavigatorLookupPanelsPolicy panelsPolicy = globalContext.lookup(NavigatorLookupPanelsPolicy.class); Collection<? extends NavigatorLookupHint> lkpHints = globalContext.lookupAll(NavigatorLookupHint.class); ActNodeSetter nodeSetter = new ActNodeSetter(panelsPolicy, lkpHints); if (navigatorTC.allowAsyncUpdate()) { synchronized (NODE_SETTER_LOCK) { if (nodeSetterTask != null) { nodeSetterTask.cancel(); } // wait some time before propagating the change further nodeSetterTask = RequestProcessor.getDefault().post(nodeSetter, COALESCE_TIME); nodeSetterTask.addTaskListener(nodeSetter); } } else { nodeSetter.run(); } } }
public void resultChanged(LookupEvent ev) { synchronized (CACHE) { ArrayList<JTextComponent> toRemove = new ArrayList<JTextComponent>(); for(JTextComponent jtc : CACHE.keySet()) { String mimeType = NbEditorUtilities.getMimeType(jtc); if (mimeType.equals(this.mimeType)) { toRemove.add(jtc); } } CACHE.keySet().removeAll(toRemove); } fireChange(mimeType); }
protected void collectFires(Collection<Object> evAndListeners) { LookupListener[] arr; synchronized (this) { if (listeners == null) { return; } if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { ArrayList<?> l = (ArrayList<?>) listeners; arr = l.toArray(new LookupListener[l.size()]); } } final LookupListener[] ll = arr; final org.openide.util.LookupEvent newev = new org.openide.util.LookupEvent(this); AbstractLookup.notifyListeners(ll, newev, evAndListeners); }
private List<URL> defaultJavadoc(final boolean listen) { final JavaPlatform safePlatform = new ForwardingJavaPlatform(this) { @Override public List<URL> getJavadocFolders() { return Collections.<URL>emptyList(); } }; final Set<URI> roots = new LinkedHashSet<>(); final Lookup.Result<? extends J2SEPlatformDefaultJavadoc> res = getJ2SEPlatformDefaultJavadoc(); if (listen) { synchronized (this) { if (jdocListener == null) { jdocListener = new LookupListener[2]; jdocListener[0] = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { javadoc = null; } }; jdocListener[1] = WeakListeners.create(LookupListener.class, jdocListener[0], res); res.addLookupListener(jdocListener[1]); } } } for (J2SEPlatformDefaultJavadoc jdoc : res.allInstances()) { roots.addAll(jdoc.getDefaultJavadoc(safePlatform)); } final List<URL> result = new ArrayList<>(roots.size()); for (URI root : roots) { try { result.add(root.toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } return Collections.unmodifiableList(result); }
@NonNull private List<URL> defaultSources(final boolean listen) { final JavaPlatform safePlatform = new ForwardingJavaPlatform(this) { @Override public List<URL> getJavadocFolders() { return Collections.<URL>emptyList(); } }; final Set<URI> roots = new LinkedHashSet<>(); final Lookup.Result<? extends J2SEPlatformDefaultSources> res = getJ2SEPlatformDefaultSources(); if (listen) { synchronized (this) { if (sourcesListener == null) { sourcesListener = new LookupListener[2]; sourcesListener[0] = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { sources = null; } }; sourcesListener[1] = WeakListeners.create(LookupListener.class, sourcesListener[0], res); res.addLookupListener(sourcesListener[1]); } } } for (J2SEPlatformDefaultSources src : res.allInstances()) { roots.addAll(src.getDefaultSources(safePlatform)); } final List<URL> result = new ArrayList<>(roots.size()); for (URI root : roots) { try { result.add(root.toURL()); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } return Collections.unmodifiableList(result); }
public void resultChanged(LookupEvent ev) { readPanels(); Mutex.EVENT.readAccess(new Runnable() { public void run() { initTabbedPane(); } }); }
@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); } }
@Override public void resultChanged(LookupEvent ev) { err.log (Level.FINE, "Lookup.Result changed " + ev); try { refreshProviders (null, false); } catch (IOException ioe) { err.log (Level.INFO, ioe.getMessage (), ioe); } }
public void resultChanged(LookupEvent ev) { Mutex.EVENT.readAccess(new Runnable() { // #69355: safest to run in EQ public void run() { if (selection != null) { // #111772 display(selection.allInstances()); } } }); }
public void resultChanged (LookupEvent ev) { Lookup.Result res = (Lookup.Result)ev.getSource(); assertEquals(1, res.allInstances().size()); ActionMap map = (ActionMap)res.allInstances().iterator().next(); if (lastMap != null) { // because of CallbackSystemAction.GlobalManager assertNotSame(map, lastMap); } lastMap = map; Action act = map.get(key); assertEquals(action, act); count++; }
public void resultChanged(LookupEvent ev) { attribs = null; SwingUtilities.invokeLater(new Runnable() { public void run() { //EMI: This is needed as maybe the DEFAULT_COLORING is changed, the font is different // and while getMarkSize() is used in paint() and will make the artifacts bigger, // the component itself will be the same size and it must be changed. // See http://www.netbeans.org/issues/show_bug.cgi?id=153316 updatePreferredSize(); CodeFoldingSideBar.this.repaint(); } }); }
public void resultChanged(LookupEvent ev) { attribs = null; SwingUtilities.invokeLater(new Runnable() { public void run() { JTextComponent jtc = CollapsedView.this.getComponent(); if (jtc != null) { CollapsedView.this.getBaseTextUI().damageRange( jtc, CollapsedView.this.getStartOffset(), CollapsedView.this.getEndOffset()); } } }); }
public InstalledModuleProvider() { result = Lookup.getDefault().lookup(new Lookup.Template<ModuleInfo> (ModuleInfo.class)); lkpListener = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { clearModuleInfos(); } }; result.addLookupListener(lkpListener); }
public void testDeadlock203187() throws Exception { createWhiteListsFolder(Query1.class, Query2.class); final FileObject home = FileUtil.toFileObject(getWorkDir()); final Project p = new MockProject(home); final Lookup lkp = WhiteListLookupProvider.getEnabledUserSelectableWhiteLists(p); assertNotNull(lkp); final Object lck = new Object(); final CountDownLatch l1 = new CountDownLatch(1); final CountDownLatch l2 = new CountDownLatch(1); new Thread(new Runnable() { @Override public void run() { final Lookup.Result<? extends WhiteListQueryImplementation> res = lkp.lookupResult(WhiteListQueryImplementation.class); res.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { l1.countDown(); try { l2.await(); } catch (InterruptedException ex) { Exceptions.printStackTrace(ex); } synchronized(lck) { lkp.getClass(); } } }); res.allInstances(); WhiteListLookupProvider.enableWhiteListInProject(p, Query1.class.getSimpleName(), true); } }).start(); synchronized (lck) { l1.await(); l2.countDown(); lkp.lookup(WhiteListQueryImplementation.class); } }
@Override public void resultChanged(LookupEvent ev) { FontColorSettings fcs = result.allInstances().iterator().next(); synchronized (this) { if (!customAttrs) { assignAttrs( fcs.getFontColors(INDENT_ATTRS_FCS_NAME), fcs.getFontColors(TRAILING_ATTRS_FCS_NAME)); } } }
@Override public final void resultChanged(LookupEvent ev) { PageInspector pageInspector = PageInspector.getDefault(); if (pageInspector != null) { Lookup.Result lookupResult = (Lookup.Result) ev.getSource(); lookupResult.removeLookupListener(this); pageInspector.addPropertyChangeListener(this); } }
public void testProxyWithLiveResultCanBeCollected() { Lookup layer0 = Lookups.singleton("Hello"); Lookup layer1 = new ProxyLookup(new Lookup[] { layer0 }); Lookup layer2 = new ProxyLookup(new Lookup[] { layer1 }); Lookup.Result result1 = layer1.lookup(new Lookup.Template(String.class)); assertEquals("One instance", 1, result1.allInstances().size()); // this will create ProxyLookup$R which listens on origResult Lookup.Result result2 = layer2.lookup(new Lookup.Template(String.class)); // this line is necessary. W/o actually querying the result, // it will nether compute it nor attach the listener. assertEquals("One instance", 1, result2.allInstances().size()); result2.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) {} }); Reference ref = new WeakReference(layer2); layer2 = null; result2 = null; try { holder = result1; assertGC ("The proxy lookup not been garbage collected!", ref); } finally { holder = null; } }
public void resultChanged(LookupEvent ev) { R r = result.get(); if (r != null) { r.resultChanged(ev); } else { removeListeners(); } }
public void resultChanged(LookupEvent ev) { int index = 0; synchronized (this) { Lookup.Result<?> res = (Lookup.Result<?>) ev.getSource(); for (Object _factory : res.allInstances()) { NodeFactory factory = (NodeFactory) _factory; if (!factories.contains(factory)) { factories.add(index, factory); NodeList<?> lst = factory.createNodes(project); assert lst != null; List objects = lst.keys(); synchronized (keys) { nodeLists.add(index, lst); addKeys(lst, objects); } lst.addNotify(); lst.addChangeListener(this); } else { while (!factory.equals(factories.get(index))) { factories.remove(index); synchronized (keys) { NodeList<?> lst = nodeLists.remove(index); removeKeys(lst); lst.removeNotify(); lst.removeChangeListener(this); } } } index++; } } //#115128 prevent deadlock in Children mutex SwingUtilities.invokeLater(new Runnable() { public void run() { setKeys(createKeys()); } }); }
public void testCanGCResults() throws Exception { class L implements LookupListener { int cnt; public void resultChanged(LookupEvent ev) { cnt++; } } L listener1 = new L(); L listener2 = new L(); Lookup.Result<String> res1 = this.instanceLookup.lookupResult(String.class); Lookup.Result<String> res2 = this.lookup.lookupResult(String.class); assertEquals("Empty1", 0, res1.allItems().size()); assertEquals("Empty2", 0, res2.allItems().size()); res1.addLookupListener(listener1); res2.addLookupListener(listener2); addInstances(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); this.ic.add("Ahoj"); assertEquals("Change1", 1, listener1.cnt); assertEquals("Change2", 1, listener2.cnt); assertEquals("Full1", 1, res1.allItems().size()); assertEquals("Full2", 1, res2.allItems().size()); Reference<Object> ref2 = new WeakReference<Object>(res2); if (res1 == res2) { res1 = null; } res2 = null; assertGC("Result can disappear", ref2); }
public void resultChanged(LookupEvent ev) { R r = (R)result.get(); if (r != null) { r.resultChanged(ev); } else { source.removeLookupListener(this); } }
public void testCanProxyLookupHaveWrongResults() { class L implements LookupListener { ProxyLookup pl; Lookup.Result<String> original; Lookup.Result<String> wrapped; boolean ok; public void test() { pl = new ProxyLookup(lookup); original = lookup.lookupResult(String.class); original.addLookupListener(this); wrapped = pl.lookupResult(String.class); assertEquals("Original empty", 0, original.allInstances().size()); assertEquals("Wrapped empty", 0, wrapped.allInstances().size()); ic.add("Hello!"); } public void resultChanged(LookupEvent ev) { ok = true; assertEquals("Original has hello", 1, original.allInstances().size()); assertEquals("Wrapped has hello", 1, wrapped.allInstances().size()); } } L listener = new L(); listener.test(); assertTrue("Listener called", listener.ok); }
EmbeddingHighlightsContainer(Document document) { this.document = document; lookupResult = MimeLookup.getLookup(HTML_MIME_TYPE).lookupResult(FontColorSettings.class); lookupResult.addLookupListener(WeakListeners.create(LookupListener.class, lookupListener = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { refreshColorings(); } }, lookupResult)); refreshColorings(); }
@Override public void resultChanged(LookupEvent ev) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateConfigurations(getDialogState()); } }); }
@Override public synchronized void resultChanged(LookupEvent unused) { if (Thread.currentThread().getName().contains("request-processor")) { cnt++; notifyAll(); return; } fail("Changes shall be delivered in request processor thread. But was: " + Thread.currentThread().getName()); }
synchronized AttributeSet getColoring(Coloring c, final Language language) { AttributeSet a = null; Map<Coloring,AttributeSet> map = CACHE.get(language); if (map == null) { final String mime = language.getMimeType(); a = language.getColoringManager().getColoringImpl(c); map = new HashMap<Coloring,AttributeSet>(); map.put(c, a); CACHE.put(language, map); Lookup.Result<FontColorSettings> res = MimeLookup.getLookup(MimePath.get(mime)).lookupResult(FontColorSettings.class); coloringResults.add(res); LookupListener l; res.addLookupListener( WeakListeners.create(LookupListener.class, l = new LookupListener() { @Override public void resultChanged(LookupEvent ev) { clearLanguageColoring(language); fireHighlightsChange(0, doc.getLength()); } }, res) ); coloringListeners.add(l); } else { a = map.get(c); if (a == null) { map.put(c, a = language.getColoringManager().getColoringImpl(c)); } } if (a == null) { LOG.log(Level.FINE, "Null AttributeSet for coloring {0} in language {1}", new Object [] { c, language }); } return a; }
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); } } }
/** * @return All the registered implementations. */ public static Collection<? extends KeymapManager> getKeymapManagerInstances() { if (managers != null) { return managers; } final Lookup.Result r = Lookup.getDefault().lookupResult(KeymapManager.class); ArrayList<KeymapManager> al = new ArrayList<KeymapManager>(r.allInstances()); al.trimToSize(); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Dumping registered KeymapManagers: "); for (KeymapManager m : al) { LOG.fine(" KeymapManager: " + s2s(m)); } LOG.fine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); } synchronized (KeymapModel.class) { if (managers == null) { managers = al; r.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { synchronized (KeymapModel.class) { managers = null; r.removeLookupListener(this); } if (INSTANCE != null) { INSTANCE.refreshActions(); } } }); } } return al; }
public void resultChanged(LookupEvent ev) { LookupEvent ev2 = new LookupEvent(this); LookupListener[] ls; synchronized (listeners) { ls = listeners.toArray(new LookupListener[listeners.size()]); } for (int i = 0; i < ls.length; i++) { ls[i].resultChanged(ev2); } }
private void registerLookupListenerAndAddSomething(boolean useProxy, boolean callAllInstances, boolean inheritanceTree) { called = false; InstanceContent aInstanceContent = new InstanceContent(); Storage<?> s = inheritanceTree ? new InheritanceTree() : new ArrayStorage(); Lookup aLookup = new AbstractLookup(aInstanceContent, s); if (useProxy) { aLookup = new ProxyLookup(aLookup); } Lookup.Result<ObjectInLookup> result = aLookup.lookupResult(ObjectInLookup.class); if (callAllInstances) { result.allInstances(); // TO GET SUCCESS } result.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { Lookup.Result aResult = (Lookup.Result) ev.getSource(); Collection c = aResult.allInstances(); if (!c.isEmpty()) { called = true; } } }); aInstanceContent.set(Collections.singleton( new ObjectInLookup("Set Object in Lookup)")), null); Assert.assertTrue("Listener was notified", called); }