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

The following examples show how to use org.openide.nodes.Node#getLookup() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 2
Source Project: netbeans   File: SrcNodeTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testSubfolderLookup() throws Exception {
    PhpProject phpProject = TestUtils.createPhpProject(getWorkDir());
    FileObject sources = ProjectPropertiesSupport.getSourcesDirectory(phpProject);
    final FileObject subfolder = sources.createFolder("emptyFolder");
    NodeList<SourceGroup> nodes = new SourcesNodeFactory().createNodes(phpProject);
    List<SourceGroup> sourceGroups = nodes.keys();
    assertFalse("Source groups should be found", sourceGroups.isEmpty());
    for (SourceGroup sourceGroup : sourceGroups) {
        Node node = nodes.node(sourceGroup);
        Lookup lookup = node.getLookup();
        assertNotNull("Fileobject should be found", lookup.lookup(FileObject.class));
        Children children = node.getChildren();
        assertTrue("Should have subnodes", children.getNodesCount(true) > 0);
        for (Node subnode : children.getNodes(true)) {
            Lookup sublookup = subnode.getLookup();
            FileObject fileObject = sublookup.lookup(FileObject.class);
            assertNotNull("Fileobject should be found", fileObject);
            assertEquals("Fileobjects should be same", subfolder, fileObject);
        }
    }
}
 
Example 3
Source Project: netbeans   File: TreeRootNode.java    License: Apache License 2.0 6 votes vote down vote up
private TreeRootNode(Node originalNode, SourceGroup group, GrailsProject project, Type type) {
    super(originalNode, new PackageFilterChildren(originalNode),
            new ProxyLookup(
            originalNode.getLookup(),
            Lookups.fixed(  new PathFinder(group),  // no need for explicit search info
                            // Adding TemplatesImpl to Node's lookup to narrow-down
                            // number of displayed templates with the NewFile action.
                            // see # 122942
                            new TemplatesImpl(project, group)
                            )
            ));
    String pathName = group.getName();
    setShortDescription(pathName.substring(project.getProjectDirectory().getPath().length() + 1));
    this.group = group;
    this.visualType = type;
    group.addPropertyChangeListener(WeakListeners.propertyChange(this, group));
}
 
Example 4
Source Project: netbeans   File: ProjectServicesImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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 5
Source Project: netbeans   File: TreeRootNode.java    License: Apache License 2.0 5 votes vote down vote up
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 6
Source Project: netbeans   File: ActionFilterNode.java    License: Apache License 2.0 5 votes vote down vote up
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 7
public static Lookup createLookupProxy(ProjectAssetManager manager, Node node) {
    DataObject obj = node.getLookup().lookup(DataObject.class);
    if (obj instanceof AssetDataObject && obj.getLookup().lookup(ProjectAssetManager.class) == null) {
        ((AssetDataObject) obj).getLookupContents().add(manager);
    }
    return new ProxyLookup(
            new Lookup[]{
                node.getLookup()
                /*,Lookups.fixed(manager)*/
            });
}
 
Example 8
Source Project: netbeans   File: UnitTestLibrariesNode.java    License: Apache License 2.0 5 votes vote down vote up
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 9
Source Project: netbeans   File: LibrariesNode.java    License: Apache License 2.0 5 votes vote down vote up
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 10
public static Lookup createLookupProxy(ProjectAssetManager manager, Node node) {
    DataObject obj = node.getLookup().lookup(DataObject.class);
    if (obj instanceof AssetDataObject && obj.getLookup().lookup(ProjectAssetManager.class) == null) {
        ((AssetDataObject) obj).getLookupContents().add(manager);
    }
    return new ProxyLookup(
            new Lookup[]{
                node.getLookup()
                /*,Lookups.fixed(manager)*/
            });
}
 
Example 11
Source Project: netbeans   File: SrcNode.java    License: Apache License 2.0 5 votes vote down vote up
public PackageNode(PhpProject project, final Node originalNode, boolean isTest) {
    super(originalNode, new FolderChildren(project, originalNode, isTest),
            new ProxyLookup(originalNode.getLookup()));
    this.project = project;
    this.isTest = isTest;

    ProjectPropertiesSupport.addWeakProjectPropertyChangeListener(project, propertyChangeListener);
}
 
Example 12
Source Project: netbeans   File: CategoryNode.java    License: Apache License 2.0 5 votes vote down vote up
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 13
public ProjectNode(Node node)
        throws DataObjectNotFoundException {
    super(node,
            new ProjectNodes(),
            new ProxyLookup(
                    new Lookup[]{
                        Lookups.singleton(NbAndroidProjectImpl.this),
                        node.getLookup(), Lookups.singleton(new RootGoalsNavigatorHint()),
                        lookupModels
                    }));
}
 
Example 14
public ProjectNode(Node node)
        throws DataObjectNotFoundException {
    super(node,
            new ProjectNodes(),
            new ProxyLookup(
                    new Lookup[]{
                        Lookups.singleton(NbAndroidRootProjectImpl.this),
                        node.getLookup(), Lookups.singleton(new RootGoalsNavigatorHint()),
                        lookupModels
                    }));
}
 
Example 15
Source Project: NBANDROID-V2   File: ApkDataObject.java    License: Apache License 2.0 5 votes vote down vote up
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 16
Source Project: netbeans   File: ActionFilterNode.java    License: Apache License 2.0 4 votes vote down vote up
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 17
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 18
Source Project: cakephp3-netbeans   File: MVCNode.java    License: Apache License 2.0 4 votes vote down vote up
public PackageNode(final Node originalNode, boolean isTest) {
    super(originalNode, new MVCNode.FolderChildren(originalNode, isTest),
            new ProxyLookup(originalNode.getLookup()));
}
 
Example 19
Source Project: netbeans-mmd-plugin   File: PackageNode.java    License: Apache License 2.0 4 votes vote down vote up
public PackageNode (final Project project, final Node originalNode) {
  super(originalNode, new FolderChildren(project, originalNode), new ProxyLookup(originalNode.getLookup()));
}
 
Example 20
Source Project: netbeans   File: SvnUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @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);
}