Java Code Examples for org.openide.nodes.Node.getLookup()

The following are Jave code examples for showing how to use getLookup() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: ProjectServicesImpl.java   Source Code and License Vote up 6 votes
@Override
public FileObject[] getCurrentSelection() {
    Node[] nodes = TopComponent.getRegistry().getActivatedNodes();
    if(nodes == null) {
        return null;
    }        
    List<FileObject> ret = new ArrayList<FileObject>();
    for(Node node : nodes) {
        Lookup nodeLookup = node.getLookup();
        Collection<? extends Project> projects = nodeLookup.lookupAll(Project.class);
        if(projects != null && !projects.isEmpty()) {
            for (Project project : projects) {
                ret.add(project.getProjectDirectory());
            }
        } else {
            DataObject dataObj = nodeLookup.lookup(DataObject.class);
            if (dataObj != null) {
                FileObject fileObj = dataObj.getPrimaryFile();
                if (fileObj != null) {
                    ret.add(fileObj);
                }
            }
        }
    }
    return ret.toArray(new FileObject[ret.size()]);
}
 
Example 2
Project: incubator-netbeans   File: TestDataDirsNodeFactory.java   Source Code and License Vote up 6 votes
public Node node(final SourceGroup key) {
    try {
        Node nodeDelegate = DataObject.find(key.getRootFolder()).getNodeDelegate();
        return new FilterNode(nodeDelegate,
                null, new ProxyLookup(nodeDelegate.getLookup(), Lookups.singleton(new PathFinder(key)))) {
            @Override
            public String getName() {
                return key.getName();
            }
            @Override
            public String getDisplayName() {
                return key.getDisplayName();
            }
        };
    } catch (DataObjectNotFoundException ex) {
        throw new AssertionError(ex);
    }
}
 
Example 3
Project: incubator-netbeans   File: TreeRootNode.java   Source Code and License Vote up 5 votes
private TreeRootNode (Node originalNode, DataFolder folder, SourceGroup g, boolean reduced) {
    super(originalNode, reduced ? Children.create(new ReducedChildren(folder, new GroupDataFilter(g), g), true) : new PackageFilterChildren(originalNode),
        new ProxyLookup(
            originalNode.getLookup(),
            Lookups.singleton(new PathFinder(g, reduced))
            // no need for explicit search info
        ));
    this.g = g;
    g.addPropertyChangeListener(WeakListeners.propertyChange(this, g));
}
 
Example 4
Project: incubator-netbeans   File: UnitTestLibrariesNode.java   Source Code and License Vote up 5 votes
LibraryDependencyNode(final TestModuleDependency dep,
        String testType,
        final NbModuleProject project, final Node original) {
    super(original, null, new ProxyLookup(new Lookup[] {
        original.getLookup(),
        Lookups.fixed(new Object[] { dep, project, testType })
    }));
    this.dep = dep;
    this.testType = testType;
    this.project = project;
}
 
Example 5
Project: incubator-netbeans   File: LibrariesNode.java   Source Code and License Vote up 5 votes
LibraryDependencyNode(final ModuleDependency dep,
        final NbModuleProject project, final Node original) {
    super(original, null, new ProxyLookup(original.getLookup(), Lookups.fixed(dep, project)));
    this.dep = dep;
    this.project = project;
    setShortDescription(LibrariesNode.createHtmlDescription(dep));
}
 
Example 6
Project: incubator-netbeans   File: CategoryNode.java   Source Code and License Vote up 5 votes
private CategoryNode( Node originalNode, InstanceContent content, Lookup lkp ) {
    super( originalNode, 
           new Children( originalNode, lkp ),
           new ProxyLookup( new Lookup[] { lkp, new AbstractLookup(content), originalNode.getLookup() } ) );
    
    DataFolder folder = (DataFolder)originalNode.getCookie( DataFolder.class );
    if( null != folder ) {
        content.add( new DataFolder.Index( folder, this ) );
        FileObject fob = folder.getPrimaryFile();
        Object catName = fob.getAttribute( CAT_NAME );
        if (catName instanceof String)
            setDisplayName((String)catName);
    }
    content.add( this );
}
 
Example 7
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 5 votes
private static Lookup createLookup(final Node original, Object... toAdd) {
    final Lookup lookup = original.getLookup();
    final org.netbeans.spi.project.ui.PathFinder pathFinder =
            lookup.lookup(org.netbeans.spi.project.ui.PathFinder.class);
    final Lookup lkp = new ProxyLookup(
            Lookups.exclude(lookup, org.netbeans.spi.project.ui.PathFinder.class),
            Lookups.fixed (toAdd),
            Lookups.singleton(new PathFinder(pathFinder)));
    return lkp;
}
 
Example 8
Project: NBANDROID-V2   File: ApkDataObject.java   Source Code and License Vote up 5 votes
public ApkFilterNode(Node original) {
    super(original, org.openide.nodes.Children.LEAF, new ProxyLookup(original.getLookup(), Lookups.fixed(new SignInfoHolder())));
    holder = getLookup().lookup(SignInfoHolder.class);
    project = FileOwnerQuery.getOwner(pf);
    pf.addFileChangeListener(WeakListeners.create(FileChangeListener.class, this, pf));
    refreshIcons();
}
 
Example 9
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 4 votes
private ActionFilterNode(Node original, int mode, FileObject cpRoot, FileObject resource) {
    this(original, mode, cpRoot,
            new ProxyLookup(original.getLookup(),Lookups.singleton(new JavadocProvider(cpRoot,resource))));
}
 
Example 10
Project: incubator-netbeans   File: ProjectsRootNode.java   Source Code and License Vote up 4 votes
private static Lookup badgingLookup(Node n) {
    return new BadgingLookup(n.getLookup());
}
 
Example 11
Project: incubator-netbeans   File: ActionFilterNode.java   Source Code and License Vote up 4 votes
private ActionFilterNode (Node original, Mode mode, FileObject cpRoot, FileObject resource) {
    this (original, mode, cpRoot,
        new ProxyLookup(new Lookup[] {original.getLookup(),Lookups.singleton(new JavadocProvider(cpRoot,resource))}));
}
 
Example 12
Project: incubator-netbeans   File: TopComponentGetLookupTest.java   Source Code and License Vote up 4 votes
public void testBug32470FilterNodeAndANodeImplementingACookie() {
    class NY extends AbstractNode implements SaveCookie {
        public NY() {
            super(Children.LEAF);
            getCookieSet().add(this);
        }
        
        public void save() {
        }
    }
    
    Node ny = new NY();
    Node node = new FilterNode(new FilterNode(ny, null, ny.getLookup()));
    top.setActivatedNodes(new Node[] { node });
    
    Lookup.Template<Node> nodeTemplate = new Lookup.Template<Node>(Node.class);
    Lookup.Template<SaveCookie> saveTemplate = new Lookup.Template<SaveCookie>(SaveCookie.class);
    Collection<? extends Node> res;
    
    res = lookup.lookup(nodeTemplate).allInstances();
    
    assertEquals("just one returned", res.size(), 1);
    assertEquals("node is node", node, res.iterator().next());
    //MK - the above 2 tests should test the same..
    //        assertEquals ("FilterNode is the only node there",
    //            Collections.singletonList(node), res
    //        );
    
    Collection<? extends SaveCookie> res2 = lookup.lookup(saveTemplate).allInstances();
    
    assertEquals("just one returned", res2.size(), 1);
    assertEquals("node is node", ny, res2.iterator().next());
    //MK - the above 2 tests should test the same..
    //        assertEquals ("SaveCookie is there only once",
    //            Collections.singletonList(ny), res
    //        );
    
    res = lookup.lookup(nodeTemplate).allInstances();
    
    assertEquals("just one returned", res.size(), 1);
    assertEquals("node is node", node, res.iterator().next());
    //MK - the above 2 tests should test the same..
    //        assertEquals ("FilterNode is still the only node there",
    //            Collections.singletonList(node), res
    //        );
}
 
Example 13
Project: incubator-netbeans   File: SvnUtils.java   Source Code and License Vote up 2 votes
/**
 * @return <code>true</code> if
 * <ul>
 *  <li> the node contains a project in its lookup and
 *  <li> the project contains at least one SVN versioned source group
 * </ul>
 * otherwise <code>false</code>.
 * @param project
 * @param checkStatus if set to true, cache.getStatus is called and can take significant amount of time
 */
public static boolean isVersionedProject(Node node, boolean checkStatus) {
    Lookup lookup = node.getLookup();
    Project project = (Project) lookup.lookup(Project.class);
    return isVersionedProject(project, checkStatus);
}