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

The following are Jave code examples for showing how to use getChildren() 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: ResultsOutlineSupport.java   Source Code and License Vote up 6 votes
private void expandOnlyChilds(Node parent) {
    setExpansionListenerEnabled(false);
    try {
        Node node = parent;
        while (node != null) {
            Children children = node.getChildren();
            if (children.getNodesCount(true) == 1) {
                node = children.getNodeAt(0);
                outlineView.expandNode(node);
            } else {
                node = null;
            }
        }
    } finally {
        setExpansionListenerEnabled(true);
    }
}
 
Example 2
Project: incubator-netbeans   File: PlatformsCustomizer.java   Source Code and License Vote up 6 votes
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 3
Project: incubator-netbeans   File: SuiteLogicalViewTest.java   Source Code and License Vote up 6 votes
@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 4
Project: incubator-netbeans   File: TreeModelRoot.java   Source Code and License Vote up 6 votes
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 5
Project: incubator-netbeans   File: TreeTableView.java   Source Code and License Vote up 6 votes
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 6
Project: incubator-netbeans   File: BookmarksNodeTree.java   Source Code and License Vote up 6 votes
public Node findFirstBookmarkNode(ProjectBookmarks projectBookmarks, FileObject fo) {
    if (rootNode != null) {
        List<Node> projectNodes = rootNode.getChildren().snapshot();
        for (Node pNode : projectNodes) {
            ProjectBookmarksChildren pChildren =
                    (ProjectBookmarksChildren) pNode.getChildren();
            if (pChildren.projectBookmarks == projectBookmarks) {
                for (Node fNode : pChildren.snapshot()) {
                    FileBookmarksChildren fChildren = (FileBookmarksChildren) fNode.getChildren();
                    if (fChildren.fileBookmarks.getFileObject() == fo) {
                        List<Node> bNodes = fChildren.snapshot();
                        if (!bNodes.isEmpty()) {
                            return bNodes.get(0);
                        }
                    }
                }
            }
        }
    }
    return null;
}
 
Example 7
Project: NBANDROID-V2   File: SdksCustomizer.java   Source Code and License Vote up 6 votes
private static void expandAllNodes(BeanTreeView btv, Node node, ExplorerManager mgr, AndroidSdk platform) {
    btv.expandNode(node);
    Children ch = node.getChildren();
    if (ch == Children.LEAF) {
        if (platform != null && platform.equals(node.getLookup().lookup(AndroidSdk.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 8
Project: incubator-netbeans   File: SelectPathAction.java   Source Code and License Vote up 6 votes
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 9
Project: incubator-netbeans   File: TemplatesPanel.java   Source Code and License Vote up 6 votes
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 10
Project: incubator-netbeans   File: FolderChildrenTest.java   Source Code and License Vote up 6 votes
@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 11
Project: incubator-netbeans   File: FolderChildrenTest.java   Source Code and License Vote up 6 votes
@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 12
Project: incubator-netbeans   File: FolderChildrenTest.java   Source Code and License Vote up 6 votes
@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 13
Project: incubator-netbeans   File: TreeViewDropSupport.java   Source Code and License Vote up 5 votes
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
Project: incubator-netbeans   File: OutlineViewDropSupport.java   Source Code and License Vote up 5 votes
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 15
Project: incubator-netbeans   File: DBschemaDataObject.java   Source Code and License Vote up 5 votes
public void setSchema(SchemaElement schema) {
  schemaElement = schema;
  if (isValid()) {
      Node n = getNodeDelegate();
      Children ch = n.getChildren();
      ((SchemaRootChildren) ch).setElement(schemaElement);
  }
}
 
Example 16
Project: incubator-netbeans   File: ViewTest.java   Source Code and License Vote up 5 votes
public void testViewItemBasic() throws Exception {
    Node root = lvp.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 display name #1", "External Sources", kids[0].getDisplayName());
    assertEquals("correct cookie #1",
        DataObject.find(egdirFO.getFileObject("extsrcroot/src")),
        kids[0].getLookup().lookup(DataObject.class));
    Node[] kids2 = kids[0].getChildren().getNodes(true);
    assertEquals("one child of ../src", 1, kids2.length);
    assertEquals("correct name of #1's kid", "org.foo", kids2[0].getName());
    // Do not test node #2; supplied by ant/freeform.
}
 
Example 17
Project: incubator-netbeans   File: ViewTest.java   Source Code and License Vote up 5 votes
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 18
Project: incubator-netbeans   File: ViewTest.java   Source Code and License Vote up 5 votes
@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 19
Project: incubator-netbeans   File: LayerFilterNode.java   Source Code and License Vote up 4 votes
LayerFilterNode(Node original) {
    super(original, org.openide.nodes.Children.LEAF == original.getChildren()
            ? org.openide.nodes.Children.LEAF : new LayerFilterNodeChildren(original));
}
 
Example 20
Project: incubator-netbeans   File: NavigationTreeViewTest.java   Source Code and License Vote up 4 votes
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);
}