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

The following examples show how to use org.openide.nodes.Node#getChildren() . 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: SecurityMultiViewElement.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void repaintView() {
    webApp = dObj.getWebApp();
    view = new SecurityView(webApp);
    editor.setContentView(view);
    
    Object lastActive = editor.getLastActive();
    if (lastActive != null) {
        ((SectionView)view).openPanel(lastActive);
    } else {
        SecurityView securityView = (SecurityView)view;
        
        Node initialNode = view.getRolesNode();
        Children ch = initialNode.getChildren();
        if (ch.getNodesCount() > 0)
            initialNode = ch.getNodes()[0];
        view.selectNode(initialNode);
    }
    view.checkValidity();
    dObj.checkParseable();
    
}
 
Example 2
Source File: SuiteLogicalViewTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // NB-Core-Build #7497: two children expected:<2> but was:<0>
public void testModulesNode() throws Exception {
    SuiteProject suite1 = generateSuite("suite1");
    TestBase.generateSuiteComponent(suite1, "module1a");
    Node modulesNode = new ModulesNodeFactory.ModulesNode(suite1);
    modulesNode.getChildren().getNodes(true); // "expand the node" simulation
    waitForGUIUpdate();
    assertEquals("one children", 1, modulesNode.getChildren().getNodes(true).length);
    
    final ModulesNodeFactory.ModulesNode.ModuleChildren children = (ModulesNodeFactory.ModulesNode.ModuleChildren) modulesNode.getChildren();
    TestBase.generateSuiteComponent(suite1, "module1b");
    waitForGUIUpdate();
    assertEquals("two children", 2, children.getNodes(true).length);
    TestBase.generateSuiteComponent(suite1, "module1c");
    ProjectManager.mutex().writeAccess(new Mutex.Action<Void>() {
        public Void run() {
            children.stateChanged(null); // #70914
            return null; // #70914
        }
    });
    waitForGUIUpdate();
    assertEquals("three children", 3, children.getNodes(true).length);
}
 
Example 3
Source File: SrcNodeTest.java    From netbeans with 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 4
Source File: CategoryView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Node findNode( ProjectCustomizer.Category category, Node node ) {

        Children ch = node.getChildren();

        if ( ch != null && ch != Children.LEAF ) {
            Node nodes[] = ch.getNodes( true );

            if ( nodes != null ) {
                for (Node child : nodes) {
                    ProjectCustomizer.Category cc = child.getLookup().lookup(ProjectCustomizer.Category.class);

                    if ( cc == category ) {
                        return child;
                    }
                    else {
                        Node n = findNode(category, child);
                        if ( n != null ) {
                            return n;
                        }
                    }
                }
            }
        }

        return null;
    }
 
Example 5
Source File: FolderChildrenTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // Because testChangeableDataFilter() RandomlyFails
public void testChangeableDataFilterOnFilterNodeWithPartialRefresh() throws Exception {
    String pref = getName() + "/";
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/A.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/B.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/AA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/BA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/A.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/B.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/AA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/BA.txt");

    FileObject bb = FileUtil.getConfigFile(pref + "/BB");

    Filter filter = new Filter();
    DataFolder folder = DataFolder.findFolder (bb);

    Node root = new FilterNode (folder.getNodeDelegate (), folder.createNodeChildren (filter));
    Children ch = root.getChildren();
    doTestChangeableDataFilterWithPartialRefresh(ch, filter, bb);
}
 
Example 6
Source File: FolderChildrenTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // Because testChangeableDataFilterOnNodeDelegate() RandomlyFails
public void testChangeableDataFilterOnNodeDelegateWithPartialRefresh() throws Exception {
    String pref = getName() + "/";
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/A.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/B.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/AA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/0/BA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/A.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/B.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/AA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/1/BA.txt");

    FileObject bb = FileUtil.getConfigFile(pref + "/BB");

    Filter filter = new Filter();
    DataFolder folder = DataFolder.findFolder (bb);

    Node n = folder.getClonedNodeDelegate(filter);
    Children ch = n.getChildren();
    doTestChangeableDataFilterWithPartialRefresh(ch, filter, bb);
}
 
Example 7
Source File: FolderChildrenTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@RandomlyFails // NB-Core-Build #1049 (in FolderChildrenLazyTest), #1051 (in this)
public void testChangeableDataFilterOnNodeDelegate() throws Exception {
    String pref = getName() + "/";
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/A.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/B.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/AA.txt");
    FileUtil.createData (FileUtil.getConfigRoot(), pref + "BB/BA.txt");


    FileObject bb = FileUtil.getConfigFile(pref + "BB");

    Filter filter = new Filter();
    DataFolder folder = DataFolder.findFolder (bb);


    Node n = folder.getClonedNodeDelegate(filter);
    Children ch = n.getChildren();
    Node[] arr = ch.getNodes (true);

    assertNodes( arr, new String[] { "A.txt", "AA.txt" } );
    filter.fire();
    arr = ch.getNodes (true);
    assertNodes( arr, new String[] { "B.txt", "BA.txt" } );
}
 
Example 8
Source File: TemplatesPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Node getTemplateNode(FileObject fo, FileObject rootFO) {
    if (rootFO.equals(fo)) {
        return getTemplateRootNode();
    }
    Node parent = getTemplateNode(fo.getParent(), rootFO);
    if (parent == null) {
        return null;
    }
    Children ch = parent.getChildren();
    for (Node node : ch.getNodes(true)) {
        if (fo.equals(node.getLookup().lookup(FileObject.class))) {
            return node;
        }
    }
    return null;
}
 
Example 9
Source File: PlatformsCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static void expandAllNodes (BeanTreeView btv, Node node, ExplorerManager mgr, JavaPlatform platform) {
    btv.expandNode (node);
    Children ch = node.getChildren();
    if ( ch == Children.LEAF ) {
        if (platform != null && platform.equals(node.getLookup().lookup(JavaPlatform.class))) {
            try {
                mgr.setSelectedNodes (new Node[] {node});
            } catch (PropertyVetoException e) {
                //Ignore it
            }
        }
        return;
    }
    Node nodes[] = ch.getNodes( true );
    for ( int i = 0; i < nodes.length; i++ ) {
        expandAllNodes( btv, nodes[i], mgr, platform);
    }

}
 
Example 10
Source File: TreeTableView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void sortingChanged() {
    // PENDING: remember the last sorting to avoid multiple sorting
    // remenber expanded folders
    TreeNode tn = (TreeNode) (this.getRoot());
    java.util.List<TreePath> list = new ArrayList<TreePath>();
    Enumeration<TreePath> en = TreeTableView.this.tree.getExpandedDescendants(new TreePath(tn));

    while ((en != null) && en.hasMoreElements()) {
        TreePath path = en.nextElement();

        // bugfix #32328, don't sort whole subtree but only expanded folders
        Node n = ((VisualizerNode) path.getLastPathComponent ()).node;
        Children children = n.getChildren();
        if (children instanceof SortedChildren) {
            ((SortedChildren) children).sortNodes ();
            list.add(path);
        } // else Children.LEAF
    }

    // expand again folders
    for (int i = 0; i < list.size(); i++) {
        TreeTableView.this.tree.expandPath(list.get(i));
    }
}
 
Example 11
Source File: SelectPathAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Node[] getSelectionNodes() {
    if(selectionNodes == null) {
        String[] segments = selectionUrl.getPathSegments();
        Node node = (RepositoryPathNode) browser.getExplorerManager().getRootContext();            
        
        for (int i = 0; i < segments.length; i++) {
            Children children = node.getChildren();    
            node = children.findChild(segments[i]);
            if(node==null) {
                break;
            }                    
        }            
        if(node == null) {
            selectionNodes = EMPTY_NODES;
        } else {
            selectionNodes = new Node[] {node};    
        }            
    }
    return selectionNodes;
}
 
Example 12
Source File: TreeModelRoot.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Object initExpandCollapseNotify(TreeExpansionEvent event) {
    Node node = Visualizer.findNode(event.getPath ().getLastPathComponent());
    Object obj = node.getLookup().lookup(Object.class);
    Object actOn;
    node = node.getParentNode();
    if (node == null) {
        actOn = new Integer(0);
    } else {
        Children ch = node.getChildren();
        if (ch instanceof TreeModelNode.TreeModelChildren) {
            actOn = ((TreeModelNode.TreeModelChildren) ch).getTreeDepth();
        } else {
            actOn = ch;
        }
    }
    Models.CompoundModel model = getModel();
    if (model != null) {
        DefaultTreeExpansionManager.get(model).setChildrenToActOn(actOn);
    }
    return obj;
}
 
Example 13
Source File: TreeViewDropSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Node[] findDropedNodes(Node folder, Node[] dragNodes) {
    if ((folder == null) || (dragNodes.length == 0)) {
        return null;
    }

    Node[] dropNodes = new Node[dragNodes.length];
    Children children = folder.getChildren();

    for (int i = 0; i < dragNodes.length; i++) {
        dropNodes[i] = children.findChild(dragNodes[i].getName());
    }

    return dropNodes;
}
 
Example 14
Source File: DBschemaDataObject.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setSchema(SchemaElement schema) {
  schemaElement = schema;
  if (isValid()) {
      Node n = getNodeDelegate();
      Children ch = n.getChildren();
      ((SchemaRootChildren) ch).setElement(schemaElement);
  }
}
 
Example 15
Source File: ViewTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@RandomlyFails // NB-Core-Build #1012
public void testViewItemChanges() throws Exception {
    FileObject top = FileUtil.toFileObject(copyFolder(FileUtil.toFile(egdirFO.getFileObject("extsrcroot"))));
    FreeformProject extsrcroot_ = (FreeformProject) ProjectManager.getDefault().findProject(top.getFileObject("proj"));
    Node root = extsrcroot_.getLookup().lookup(LogicalViewProvider.class).createLogicalView();
    Children ch = root.getChildren();
    Node[] kids = ch.getNodes(true);
    assertEquals("two child nodes", 2, kids.length);
    assertEquals("correct code name #1", "../src", kids[0].getName());
    assertEquals("correct code name #2", "nbproject/project.xml", kids[1].getName());
    TestNL l = new TestNL();
    root.addNodeListener(l);
    Element data = extsrcroot_.getPrimaryConfigurationData();
    Element view = XMLUtil.findElement(data, "view", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <view>", view);
    Element items = XMLUtil.findElement(view, "items", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <items>", items);
    Element sourceFolder = XMLUtil.findElement(items, "source-folder", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <source-folder>", sourceFolder);
    Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <location>", location);
    NodeList nl = location.getChildNodes();
    assertEquals("one child", 1, nl.getLength());
    location.removeChild(nl.item(0));
    location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
    Element sourceFile =  XMLUtil.findElement(items, "source-file", FreeformProjectType.NS_GENERAL);
    assertNotNull("have <source-file>", sourceFile);
    items.removeChild(sourceFile);
    extsrcroot_.putPrimaryConfigurationData(data);
    // children keys are updated asynchronously. give them a time
    Thread.sleep(500);
    assertFalse("got some changes in children", l.probeChanges().isEmpty());
    kids = ch.getNodes(true);
    assertEquals("one child node", 1, kids.length);
    assertEquals("correct code name #1", "../src2", kids[0].getName());
    assertEquals("correct display name #1", "External Sources", kids[0].getDisplayName());
    assertEquals("correct cookie #1",
            DataObject.find(top.getFileObject("src2")),
            kids[0].getLookup().lookup(DataObject.class));
}
 
Example 16
Source File: ViewTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testViewItemBasic() throws Exception {
    Node root = extsrcroot.getLookup().lookup(LogicalViewProvider.class).createLogicalView();
    assertEquals("lookup has project", extsrcroot, root.getLookup().lookup(Project.class));
    Children ch = root.getChildren();
    Node[] kids = ch.getNodes(true);
    assertEquals("two child nodes", 2, kids.length);
    // Do not check anything about #1, since it is provided by java/freeform.
    assertEquals("correct code name #2", "nbproject/project.xml", kids[1].getName());
    assertEquals("correct display name #2", "project.xml", kids[1].getDisplayName());
    assertEquals("correct cookie #2",
            DataObject.find(egdirFO.getFileObject("extsrcroot/proj/nbproject/project.xml")),
            kids[1].getLookup().lookup(DataObject.class));
}
 
Example 17
Source File: WebPagesNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private WebPagesNode(Project proj, Node orig, File root, boolean isTopLevel) {
    //#142744 if orig child is leaf, put leave as well.
    super(orig, orig.getChildren() == Children.LEAF ? Children.LEAF : new WebAppFilterChildren(proj, orig, root));
    this.project = proj;
    isTopLevelNode = isTopLevel;
    if (isTopLevel) {
        file = FileUtil.toFileObject(root);
    }
}
 
Example 18
Source File: UICommonUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static FileObject getFileObjectFromNode(Node node) {
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if(fo == null) {
        Children children = node.getChildren();
        for(Node child : children.getNodes()) {
            fo = child.getLookup().lookup(FileObject.class);
            if(fo != null) {
                return child.getDisplayName().equals("<default package>") ? fo : fo.getParent();
            }
        }
    }
    return fo;
}
 
Example 19
Source File: NavigationTreeViewTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testStructureFullOfFormFiles() throws Exception {
    if ((
        Utilities.getOperatingSystem() & 
        (Utilities.OS_SOLARIS | Utilities.OS_SUNOS)
    ) != 0) {
        LOG.log(Level.CONFIG, "Giving up, this test fails too randomly on Solaris");
        return;
    }
    
    Children ch = new Children.Array();
    Node root = new AbstractNode(ch);
    root.setName(getName());

    ch.add(nodeWith("A", "-A", "-B", "B"));
    ch.add(nodeWith("X", "Y", "Z"));

    final Node first = ch.getNodes()[0];

    LOG.log(Level.INFO, "Nodes are ready: {0}", root);
    final ExplorerManager em = testWindow.getExplorerManager();
    em.setRootContext(root);
    LOG.info("setRootContext done");
    em.setSelectedNodes(new Node[] { first });
    LOG.log(Level.INFO, "setSelectedNodes to {0}", first);
    LOG.log(Level.INFO, "Verify setSelectedNodes: {0}", Arrays.asList(em.getSelectedNodes()));

    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            TreePath path = treeView.tree.getSelectionPath();
            LOG.log(Level.INFO, "getSelectionPath {0}", path);
            LOG.log(Level.INFO, "getSelectedNodes {0}", Arrays.toString(em.getSelectedNodes()));
            assertNotNull("Something is selected", path);
            Node node = Visualizer.findNode(path.getLastPathComponent());
            assertEquals("It is the first node", first, node);
        }
    });
    
    sendAction("expand");
    sendAction("selectNext");

    assertEquals("Explored context is N0", first, em.getExploredContext());
    assertEquals("Selected node is A", 1, em.getSelectedNodes().length);
    assertEquals("Selected node is A", "A", em.getSelectedNodes()[0].getName());

    sendAction(enter);

    Keys keys = (Keys)first.getChildren();
    assertEquals("One invocation", 1, keys.actionPerformed);
    assertFalse("No write access", keys.writeAccess);
    assertFalse("No read access", keys.readAccess);
}
 
Example 20
Source File: DependencyNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
JarFilterNode(Node original) {
    super(original, Children.LEAF == original.getChildren() ?
                    Children.LEAF : new JarContentFilterChildren(original));
}