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 }
public void testAssertFilteringIsLazy() throws Exception { LazyOpenNode n = new LazyOpenNode(); ExplorerManager em = new ExplorerManager(); Lookup lkp = ExplorerUtils.createLookup(em, new ActionMap()); em.setRootContext(n); em.setSelectedNodes(new Node[] { n }); waitAWT(); assertSame("My node", n, lkp.lookup(Node.class)); assertEquals("One node", 1, lkp.lookupAll(Node.class).size()); assertTrue("No savable", lkp.lookupAll(Savable.class).isEmpty()); Result<Openable> res = lkp.lookupResult(Openable.class); assertEquals("One item", 1, res.allItems().size()); n.assertNoOpen(); assertFalse("There is some openable", res.allInstances().isEmpty()); n.assertOpen(lkp.lookup(Openable.class)); }
public void testTemplateLookuping() throws IOException{ MimePath mp = MimePath.parse("text/x-java/text/html/text/xml"); Lookup lookup = MimeLookup.getLookup(mp); Result result = lookup.lookup(new Template(PopupActions.class)); Collection col = result.allInstances(); checkPopupItemPresence(lookup, RenameAction.class, true); gc(); int size = assertSize("", Arrays.asList( new Object[] {lookup} ), 10000000, getFilter()); for (int i=0; i<30; i++){ result = lookup.lookup(new Template(PopupActions.class)); col = result.allInstances(); checkPopupItemPresence(lookup, RenameAction.class, true); } gc(); assertSize("", size, lookup); }
private ProvidedExtensionsImpl lookupImpl(boolean providesCanWrite) { Result<BaseAnnotationProvider> result = Lookup.getDefault(). lookup(new Lookup.Template(BaseAnnotationProvider.class)); for (Item<BaseAnnotationProvider> item : result.allItems()) { if (!item.getId().contains(ProvidedExtensionsTest.class.getSimpleName())) { continue; } BaseAnnotationProvider ap = item.getInstance(); InterceptionListener iil = ap.getInterceptionListener(); if (iil instanceof ProvidedExtensionsImpl) { ProvidedExtensionsImpl extension = (ProvidedExtensionsImpl) iil; if (ProvidedExtensionsAccessor.IMPL.providesCanWrite(extension) == providesCanWrite) { return (ProvidedExtensionsImpl) iil; } } } return null; }
public void testNodesAreInTheLookupAndNothingIsFiredBeforeFirstQuery() { AbstractNode n1 = new AbstractNode(Children.LEAF, Lookup.EMPTY); top.setActivatedNodes(new Node[] { n1 }); assertEquals("One node there", 1, get.getActivatedNodes().length); assertEquals("Is the right now", n1, get.getActivatedNodes()[0]); Lookup.Result<Node> res = lookup.lookup(new Lookup.Template<Node>(Node.class)); L l = new L(); res.addLookupListener(l); l.check("Nothing fired before first query", 0); res.allInstances(); l.check("Nothing is fired on first query", 0); lookup.lookup(new Lookup.Template<Node>(Node.class)).allInstances(); l.check("And additional query does not change anything either", 0); }
public void testConfuseIterativeIterator() { InstanceContent ic1 = new InstanceContent(); AbstractLookup l1 = new AbstractLookup(ic1); InstanceContent ic2 = new InstanceContent(); AbstractLookup l2 = new AbstractLookup(ic2); InstanceContent ic3 = new InstanceContent(); AbstractLookup l3 = new AbstractLookup(ic3); ProxyLookup pl = new ProxyLookup(l1, l2, l3); Result<Number> res = pl.lookupResult(Number.class); ic1.add(1); ic2.add(2f); ic3.add(3d); int cnt = 0; for (Number n : res.allInstances()) { cnt += n.intValue(); } assertEquals("Six", 6, cnt); final Collection<? extends Number> all = res.allInstances(); assertEquals("Three numbers: " + all, 3, all.size()); }
public void testFrequentSwitching() { Object o1 = new Object(); Object o2 = new Object(); String s1 = new String("foo"); String s2 = new String("bar"); Lookup l1 = Lookups.fixed(o1, s1); Lookup l2 = Lookups.fixed(o2, s2); ProxyLookup lookup = new ProxyLookup(new Lookup[0]); Lookup.Result<Object> res1 = lookup.lookupResult(Object.class); Lookup.Result<String> res2 = lookup.lookupResult(String.class); assertSize("Lookup is small", 1500, lookup); for (int i = 0; i < 100; i++) { lookup.setLookups(l1); lookup.setLookups(l2); } assertSize("Lookup has grown too much", 1500, lookup); }
public void testDontCallMeUnderLock() throws Exception { final Lookup l = getTestedLookup(c2); ProxyLookup pl = new ProxyLookup(l) { @Override void beforeLookup(boolean call, Template<?> template) { super.beforeLookup(call, template); assertFalse("Don't hold MetaInfServicesLookup lock", Thread.holdsLock(l)); } }; Class<?> xface = c1.loadClass("org.foo.Interface"); Result<?> res = pl.lookupResult(Object.class); res.addLookupListener(new LookupListener() { @Override public void resultChanged(LookupEvent ev) { } }); assertTrue("Empty now", res.allItems().isEmpty()); Object first = l.lookup(xface); assertEquals(first, l.lookupAll(xface).iterator().next()); Object second = pl.lookup(xface); assertEquals(first, second); }
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); } } }
private <T> List<? extends T> listFromResult(Lookup.Result<T> result) { Collection<? extends T> col = result.allInstances(); Collection<T> tmp = new LinkedHashSet<T>(col); if (tmp.size() != col.size()) { Collection<T> nt = new ArrayList<T>(tmp.size()); nt.addAll(tmp); col = nt; } List<? extends T> all; if (col instanceof List) { all = (List<? extends T>)col; } else { ArrayList<T> arr = new ArrayList<T>(); arr.addAll(col); all = arr; } return all; }
@Override public void resultChanged(LookupEvent le) { if (le == null) { return; } Lookup.Result r = (Lookup.Result) le.getSource(); Collection c = r.allInstances(); if (c == null || c.isEmpty()) { return; } Object o = c.iterator().next(); if (o == null || !(o instanceof CrowdTask)) { return; } CrowdTask ct = (CrowdTask) o; Project project = associatedTopComponent.getProject(); update(project, ct); }
public void panelActivated (Lookup context) { getComponent (); Result<DataObject> result = context.<DataObject>lookupResult (DataObject.class); DataObject dataObject = result.allInstances ().iterator ().next (); if (lookupListener != null) lookupListener.remove (); lookupListener = new MyLookupListener (result); setDataObject (dataObject); }
/** * * @return registered hyperlink providers */ public List<VCSHyperlinkProvider> getHyperlinkProviders() { if (hpResult == null) { hpResult = (Result<? extends VCSHyperlinkProvider>) Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class); } if (hpResult == null) { return Collections.<VCSHyperlinkProvider>emptyList(); } Collection<? extends VCSHyperlinkProvider> providersCol = hpResult.allInstances(); List<VCSHyperlinkProvider> providersList = new ArrayList<VCSHyperlinkProvider>(providersCol.size()); providersList.addAll(providersCol); return Collections.unmodifiableList(providersList); }
public MavenQueryProvider() { grammars = new ArrayList<GrammarFactory>(); Result<GrammarFactory> result = Lookup.getDefault().lookupResult(GrammarFactory.class); Collection<? extends Item<GrammarFactory>> items = result.allItems(); for (Item<GrammarFactory> item : items) { grammars.add(item.getInstance()); } }
/** * Issues of changes in layer */ public void testForChangeInLayer() throws IOException{ // issue #63338 // http://www.netbeans.org/issues/show_bug.cgi?id=63338 // Subj: deadlock during showing annotations // fix: deadlock occured in after inproper firing of lookup changed event. // event was fired even in cases, the lookup listener should be quiet. MimeLookup lookup = MimeLookup.getMimeLookup("text/jsp"); //NOI18N Result result = lookup.lookup(new Template(TestLookupObject.class)); result.allInstances().size(); // remove this line if issue #60010 is fixed LookupListener listener = new LookupListener(){ public void resultChanged(LookupEvent ev){ resultChangedCount[0]++; } }; result.addLookupListener(listener); //simulate module installation, new file will be added createFile("Editors/text/jsp/testLookup/org-openide-actions-PasteAction.instance"); //NOI18N checkResultChange(0); TestUtilities.deleteFile(getWorkDir(), "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance"); checkResultChange(1); result.removeLookupListener(listener); resultChangedCount[0] = 0; // end of issue #63338 ------------------------------------------------ }
/** Issue #72873 * MimeLookup duplicates objects from default mimetype folder */ public void testDoubleItems(){ MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java"); //NOI18N Result result = lookup.lookup(new Template(TestLookupObjectTwo.class)); Collection col = result.allInstances(); assertTrue(col.size() == 1); lookup = MimeLookup.getMimeLookup(""); //NOI18N result = lookup.lookup(new Template(TestLookupObjectTwo.class)); col = result.allInstances(); assertTrue(col.size() == 1); }
/** * * @return registered hyperlink providers */ public List<VCSHyperlinkProvider> getHyperlinkProviders() { if (hpResult == null) { hpResult = (Result<? extends VCSHyperlinkProvider>) Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class); } if (hpResult == null) { return Collections.emptyList(); } Collection<? extends VCSHyperlinkProvider> providersCol = hpResult.allInstances(); List<VCSHyperlinkProvider> providersList = new ArrayList<VCSHyperlinkProvider>(providersCol.size()); providersList.addAll(providersCol); return Collections.unmodifiableList(providersList); }
/** * * @return registered hyperlink providers */ public List<VCSHyperlinkProvider> getHyperlinkProviders() { if (hpResult == null) { hpResult = (Lookup.Result<? extends VCSHyperlinkProvider>) Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class); } if (hpResult == null) { return Collections.emptyList(); } Collection<? extends VCSHyperlinkProvider> providersCol = hpResult.allInstances(); List<VCSHyperlinkProvider> providersList = new ArrayList<VCSHyperlinkProvider>(providersCol.size()); providersList.addAll(providersCol); return Collections.unmodifiableList(providersList); }
public void testSwitchRefreshesIDO() throws Exception { FileObject fo = FileUtil.getConfigFile("Folder/MyInstance.instance"); assertNotNull("File visible in SFS", fo); DataObject ido = DataObject.find(fo); Lookup lkp = ido.getLookup(); Result<InstanceCookie> res = lkp.lookupResult(InstanceCookie.class); assertEquals("One cookie", 1, res.allItems().size()); res.addLookupListener(this); ido.addPropertyChangeListener(this); assertInstance(lkp, "OldOne"); assertEquals("no lookup change yet", 0, cnt); assertEquals("no pcl change yet", 0, pcl); DynamicFS dfs = Lookup.getDefault().lookup(DynamicFS.class); dfs.setDelegate(mem2); assertEquals("one pcl change now", 1, pcl); if (cnt == 0) { fail("At least one change in lookup shall be notified"); } FileObject fo2 = FileUtil.getConfigFile("Folder/MyInstance.instance"); assertNotNull("File is still visible in SFS", fo); DataObject ido2 = DataObject.find(fo2); assertSame("Data object remains", ido, ido2); assertInstance(lkp, "NewOne"); }
private void initialize() { schemaFactories = new Hashtable<String, ValidatorSchemaFactory>(); Result<ValidatorSchemaFactory> lookupResult = Lookup.getDefault().lookupResult(ValidatorSchemaFactory.class); lookupResult.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { refreshServices(); } }); refreshServices(); }
/** Test to find nodes. */ private <T> void doTestNodes(Node[] arr, Class<T> c, int cnt) { LOG.fine("setActivatedNodes: " + arr); if (arr != null) { top.setActivatedNodes(arr); } assertNotNull("At least one node is registered", lookup.lookup(c)); LOG.fine("before lookup"); Lookup.Result<T> res = lookup.lookup(new Lookup.Template<T>(c)); Collection<? extends Lookup.Item<T>> coll = res.allItems(); LOG.fine("after lookup"); assertEquals("Two registered: " + coll, cnt, coll.size()); }
public void testCurrentNodes () throws Exception { tc.setActivatedNodes(new Node[] {Node.EMPTY}); assertEquals ("This fires change", 1, cnt); assertEquals ("One item in result", 1, result.allItems ().size ()); Lookup.Item item = (Lookup.Item)result.allItems ().iterator ().next (); assertEquals ("Item should return Node.EMPTY", Node.EMPTY, item.getInstance()); assertActionMap (); tc.setActivatedNodes (null); assertEquals ("One change", 2, cnt); assertEquals ("One empty item in result", 1, result.allItems ().size ()); item = (Lookup.Item)result.allItems ().iterator ().next (); assertEquals ("Item should return null", null, item.getInstance()); assertEquals ("Name is null", "none", item.getId ()); assertActionMap (); Result<MyNode> subclass = lookup.lookup (new Lookup.Template<MyNode> (MyNode.class)); assertTrue("No items are returned", subclass.allItems().isEmpty()); Result<FeatureDescriptor> superclass = lookup.lookup (new Lookup.Template<FeatureDescriptor>(FeatureDescriptor.class)); assertEquals("One item is returned", 1, superclass.allItems().size()); item = (Lookup.Item)superclass.allItems ().iterator ().next (); assertEquals ("Item should return null", null, item.getInstance()); tc.setActivatedNodes (new Node[0]); assertEquals ("No change", 3, cnt); assertEquals ("No items in lookup", 0, result.allItems ().size ()); assertActionMap (); }
public void testBuggyIsWrongInFavoritesIssue119727() { class ProjectFilterNode extends FilterNode { public ProjectFilterNode (Node node, org.openide.nodes.Children children) { super (node, children); } } CookieSet set = CookieSet.createGeneric(null); Node pfn = new AbstractNode(Children.LEAF, set.getLookup()); FilterNode n = new ProjectFilterNode(pfn, Children.LEAF); Lookup contextLookup = n.getLookup(); Object o; o = contextLookup.lookup(ProjectFilterNode.class); assertEquals("found self", n, o); o = contextLookup.lookup(n.getClass()); assertEquals("found sefl2", n, o); o = contextLookup.lookup(Node.class); assertEquals("found node", n, o); Result<Node> res = contextLookup.lookupResult(Node.class); Collection<? extends Node> all = res.allInstances(); assertEquals("One found: " + all, 1, all.size()); assertEquals("It is the filter node", n, all.iterator().next()); }
private void addLookupListener(TopComponent tc) { Result<DataObject> r = tc.getLookup().lookupResult(DataObject.class); L l = new L(new WeakReference<TopComponent>(tc), r); synchronized(lookupListeners) { lookupListeners.add(l); } r.addLookupListener(l); }
private MetaInfLookupList(List<String> l, Result<T> lr, Set<String> s, Class<T> service) { super(s); assert service != null; this.service = service; fillInstances(l, lr, s); // Schedule lazily as this may take a while... listenOnDisabledModulesTask.schedule(100); }
private void fillInstances(List<String> l, Result<T> lr, Set<String> s) { for (String className : l) { if (className.endsWith(HIDDEN)) { continue; } if (s != null && s.contains (className)) { continue; } fillClassInstance(className); } for (Item<T> li : lr.allItems()) { // TODO: We likely do not have the Item.getId() defined correctly. // We have to check the ContextAwareService.serviceID() String serviceName = getServiceName(li.getId()); //System.err.println("ID = '"+li.getId()+"' => serviceName = '"+serviceName+"'"); // We do not recognize method calls correctly if (s != null && (s.contains (serviceName) || s.contains (serviceName+"()"))) { continue; } //add(new LazyInstance<T>(service, li)); fillServiceInstance(li); } /* for (Object lri : lr.allInstances()) { if (lri instanceof ContextAwareService) { String className = ((ContextAwareService) lri).serviceName(); if (s != null && s.contains (className)) continue; fillClassInstance(className); } } */ }
private void refreshContent() { // Perform changes under a lock so that iterators reading this list // can sync on it synchronized(this) { clear(); List<String> l = list(folder, service); Result lr = listLookup(folder, service); Set<String> s = getHiddenClassNames(l); hiddenClassNames = s; fillInstances(l, lr, s); } firePropertyChange(); }
private static <T> List<Item<T>> itemsJustForPath(Class<T> clazz, Result<T> result, String path) { int l = path.length() + 1; Collection<? extends Item<T>> allItems = result.allItems(); List<Item<T>> pathItems = new ArrayList<Item<T>>(allItems.size()); for (Item<T> it : allItems) { String filePath = it.getId(); assert filePath.startsWith(path) : "File path '"+filePath+"' does not start with searched path '"+path+"'"; if (filePath.indexOf('/', l) < l) { // This item is from current folder if (clazz.isInterface()) { // Check whether the lookup item is really declared as an instance of the class we search for: FileObject fo = FileUtil.getConfigFile(filePath+".instance"); if (fo != null) { Object io = fo.getAttribute("instanceOf"); // NOI18N if (io != null) { if (((String) io).indexOf(clazz.getName()) < 0) { continue; } } } } pathItems.add(it); } } if (pathItems.size() == allItems.size()) { return (List<Item<T>>) ORIG_ITEMS; } return pathItems; }
/** Index 0 of lookups will be modified, the rest is up to the * setup code. */ private void doProxyLookupTemplateCaching(Lookup[] lookups, boolean reget) { // Create MyProxyLookup with one lookup containing the String object InstanceContent inst = new InstanceContent(); inst.add(new String("Hello World")); //NOI18N lookups[0] = new AbstractLookup(inst); ProxyLookup proxy = new ProxyLookup(lookups); if (reget) { lookups = proxy.getLookups(); } // Performing template lookup for String object Lookup.Result result = proxy.lookup(new Lookup.Template(String.class, null, null)); int stringTemplateResultSize = result.allInstances().size(); assertEquals ("Ensure, there is only one instance of String.class in proxyLookup:", //NOI18N 1, stringTemplateResultSize); // Changing lookup in proxy lookup, now it will contain // StringBuffer Object instead of String InstanceContent ic2 = new InstanceContent(); ic2.add(new Integer(1234567890)); lookups[0] = new AbstractLookup(ic2); proxy.setLookups(lookups); assertEquals ("the old result is updated", 0, result.allInstances().size()); // Instance of String.class should not appear in proxyLookup Lookup.Result r2 = proxy.lookup(new Lookup.Template(String.class, null, null)); assertEquals ("Instance of String.class should not appear in proxyLookup:", //NOI18N 0, r2.allInstances().size()); Lookup.Result r3 = proxy.lookup(new Lookup.Template(Integer.class, null, null)); assertEquals ("There is only one instance of Integer.class in proxyLookup:", //NOI18N 1, r3.allInstances().size()); }
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 testDontCallBeforeLookup() throws Exception { InstanceContent ic = new InstanceContent(); ic.add(1); ic.add(2L); ABefore one = new ABefore(ic); ProxyLookup lkp = new ProxyLookup(one); Result<Long> longResult = lkp.lookupResult(Long.class); longResult.addLookupListener(this); Result<Integer> intResult = lkp.lookupResult(Integer.class); intResult.addLookupListener(this); Result<Number> numResult = lkp.lookupResult(Number.class); numResult.addLookupListener(this); one.queryAllowed = true; assertEquals("Two", Long.valueOf(2L), longResult.allInstances().iterator().next()); assertEquals("One", Integer.valueOf(1), intResult.allInstances().iterator().next()); assertEquals("Two numbers", 2, numResult.allInstances().size()); assertEquals("Two number items", 2, numResult.allItems().size()); one.queryAllowed = false; NoBefore nob = new NoBefore(); lkp.setLookups(one, nob); nob.queryAllowed = true; one.queryAllowed = true; assertEquals("Again Two", Long.valueOf(2L), lkp.lookup(Long.class)); assertEquals("Again One", Integer.valueOf(1), lkp.lookup(Integer.class)); assertEquals("Again Two numbers", 2, lkp.lookupAll(Number.class).size()); }
private void doTestSuperTypes(Lookup l) throws Exception { final Class<?> xface = c1.loadClass("org.foo.Interface"); final Lookup.Result<Object> res = l.lookupResult(Object.class); assertEquals("Nothing yet", 0, res.allInstances().size()); final AtomicBoolean event = new AtomicBoolean(); final Thread here = Thread.currentThread(); res.addLookupListener(new LookupListener() { public void resultChanged(LookupEvent ev) { if (Thread.currentThread() == here) { event.set(true); } } }); assertNotNull("Interface found", l.lookup(xface)); assertFalse(event.get()); class W implements Runnable { boolean ok; public synchronized void run() { ok = true; notifyAll(); } public synchronized void await() throws Exception { while (!ok) { wait(); } } } W w = new W(); MetaInfServicesLookup.getRP().execute(w); w.await(); assertEquals("Now two", 2, res.allInstances().size()); }
/** Checks whether a type is enabled. */ public <T> boolean isEnabled(Class<T> type, ContextSelection selectMode, ContextAction.Performer<? super T> enabler) { Lookup.Result<T> result = findResult(type); boolean e = isEnabledOnData(result, type, selectMode); if (e && enabler != null) { e = enabler.enabled(listFromResult(result)); } return e; }
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; }
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; }
public NeverEmptyResult(Result<T> delegate, Result<Provider> nodes) { this.delegate = delegate; this.nodes = nodes; this.listeners = new CopyOnWriteArrayList<LookupListener>(); // add weak listeners so this can be GCed when listeners are empty this.delegate.addLookupListener(WeakListeners.create(LookupListener.class, this, this.delegate)); this.nodes.addLookupListener(WeakListeners.create(LookupListener.class, this, this.nodes)); initValues(); }
public void testEventDeliveredAsynchronously() throws Exception { class L implements LookupListener { int change; Object id = new Object(); @Override public synchronized void resultChanged(LookupEvent ev) { change++; notifyAll(); } public synchronized void createSavable() { assertEquals("No changes yet", 0, change); Savable s = new DoSave(id, null, null); assertEquals("The first", s, Savable.REGISTRY.lookup(Savable.class)); assertEquals("Still no changes", 0, change); } public synchronized void waitForChange() throws InterruptedException { while (change == 0) { wait(); } assertEquals("One change delivered", 1, change); } } L listener = new L(); Result<Savable> res = Savable.REGISTRY.lookupResult(Savable.class); try { res.addLookupListener(listener); listener.createSavable(); listener.waitForChange(); } finally { res.removeLookupListener(listener); } }
public R(FoldRegistry dom, MimePath mime, Result result, Result result2) { this.dom = dom; this.mime = mime; this.result = result; this.result2 = result2; result.addLookupListener(WeakListeners.create(LookupListener.class, this, result)); if (result2 != null) { result2.addLookupListener(WeakListeners.create(LookupListener.class, this, result2)); } }
@Override public void resultChanged(LookupEvent le) { if (le == null) { System.out.println("GraphNavigator LookupEvent is null."); return; } else { System.out.println("Lookup Event for Scene"); } Result result = (Result) le.getSource(); Collection<Scene> c = result.allInstances(); boolean setScene = false; //if (!lookupResult.allInstances().isEmpty()) { // Scene s = lookupResult.allInstances().iterator().next(); if (!c.isEmpty()) { Scene s = c.iterator().next(); if (s != null) { System.out.println("Updating the navigator pane..."); pane.setViewportView(s.createSatelliteView()); add(pane, BorderLayout.CENTER); setScene = true; } else { System.out.println("Scene object is null."); } } else { System.out.println("Scene collection is empty."); pane.setViewportView(new JLabel("<No Control Flow Information Available>")); add(pane, BorderLayout.CENTER); } this.revalidate(); }