Java Code Examples for org.openide.util.Lookup.Result#allInstances()

The following examples show how to use org.openide.util.Lookup.Result#allInstances() . 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: MimeLookupPerformanceTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 3
Source File: ProxyLookupTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 4
Source File: IssuesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
    
}
 
Example 5
Source File: FilterNodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 6
Source File: ServerInstanceLookupTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static <T> void assertResultContainsInstance(Class<T> clazz, T instance, Result<T> result) {
    Set<Class<? extends T>> classes = result.allClasses();
    assertEquals(1, classes.size());
    assertTrue(clazz.isAssignableFrom(classes.iterator().next()));

    Collection<? extends T> instances = result.allInstances();
    assertEquals(1, instances.size());
    assertEquals(instance, instances.iterator().next());

    Collection<? extends Item<T>> items = result.allItems();
    assertEquals(1, items.size());
    assertEquals(instance, items.iterator().next().getInstance());
}
 
Example 7
Source File: FileObjectTestHid.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void  testMoveAndChanges() throws Exception {
    checkSetUp();
    FileObject fold = getTestFolder1(root);
    FileObject fo1 = getTestFile1(fold);
    FileObject sub;
    try {
        sub = fold.createFolder("sub");
    } catch (IOException ex) {
        fsAssert("OK, if the system is read-only",
            fs.isReadOnly() || root.isReadOnly());
        return;
    }
    
    class L implements LookupListener {
        int cnt;

        @Override
        public void resultChanged(LookupEvent ev) {
            cnt++;
        }
        
        public void assertChange(String msg) {
            assertTrue(msg, cnt > 0);
            cnt = 0;
        }
    }
    L listener = new L();

    Lookup first = fo1.getLookup();
    Result<FileObject> result = first.lookupResult(FileObject.class);
    result.addLookupListener(listener);
    
    Collection<? extends FileObject> all = result.allInstances();
    assertTrue("Contains itself before move: " + all, all.contains(fo1));
    FileLock lock = null;
    FileObject ret;
    try {
        lock = fo1.lock();
        ret = fo1.move(lock, sub, fo1.getName(), fo1.getExt());
    } finally {
        if (lock != null) {
            lock.releaseLock();
        }            
    }
    
    listener.assertChange("File object has changed");
    all = result.allInstances();
    assertTrue("Contains itself after move: " + all, all.contains(ret));
    
    FileObject ret2 = FileUtil.moveFile(ret, fold, "strange.name");

    listener.assertChange("Another change in the lookup");
    all = result.allInstances();
    assertTrue("Contains itself after move: " + all, all.contains(ret2));
}