Java Code Examples for org.openide.nodes.Children#Array

The following examples show how to use org.openide.nodes.Children#Array . 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: TopComponentActivatedNodesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void setUp () {        
    System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); // no lookup
    
    
    p = new ExplorerPanel ();
    em = p.getExplorerManager ();
    
    TreeView tv = new BeanTreeView ();
    p.add (tv);
    Children ch = new Children.Array ();
    nodes = new Node[10];
    for (int i = 0; i < 10; i++) {
        nodes[i] = new AbstractNode (Children.LEAF);
        nodes[i].setName ("Node" + i);
    }
    ch.add (nodes);
    Node root = new AbstractNode (ch);
    em.setRootContext (root);
    
    // check synchronixzation before
    assertArrays ("INIT: getSelectedNodes equals getActivatedNodes.",
        em.getSelectedNodes (), p.getActivatedNodes ());
}
 
Example 2
Source File: TemplatesPanelGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Messages("LBL_TemplatesPanel_PleaseWait=Please wait...")
private void postInitComponents () {        
    Mnemonics.setLocalizedText(jLabel1, this.firer.getCategoriesName());
    Mnemonics.setLocalizedText(jLabel2, this.firer.getTemplatesName());
    this.description.setEditorKit(new HTMLEditorKit());
    description.putClientProperty( JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE );

    // please wait node, see issue 52900
    pleaseWait = new AbstractNode (Children.LEAF) {
        @Override
        public Image getIcon (int ignore) {
            return PLEASE_WAIT_ICON;
        }
    };
    pleaseWait.setName(LBL_TemplatesPanel_PleaseWait());
    Children ch = new Children.Array ();
    ch.add (new Node[] {pleaseWait});
    final Node root = new AbstractNode (ch);
    SwingUtilities.invokeLater (new Runnable () {
        @Override public void run() {
            ((ExplorerProviderPanel)categoriesPanel).setRootNode (root);
        }
    });
    ((ExplorerProviderPanel)projectsPanel).addDefaultActionListener( firer );
    description.addHyperlinkListener(new ClickHyperlinks());
}
 
Example 3
Source File: ReferencesNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
ReferencesNode(SectionNodeView sectionNodeView, Ejb ejb, final ASDDVersion version) {
    super(sectionNodeView, new Children.Array(), ejb, version, 
            NbBundle.getMessage(ReferencesNode.class, "LBL_ReferencesHeader"), 
            ICON_BASE_REFERENCES_NODE);
    this.helpProvider = true;

    // References
    addChild(new EjbRefGroupNode(sectionNodeView, ejb, version));
    addChild(new ResourceRefGroupNode(sectionNodeView, ejb, version));
    addChild(new ResourceEnvRefGroupNode(sectionNodeView, ejb, version));
    if(ASDDVersion.SUN_APPSERVER_8_0.compareTo(version) <= 0) {
        SunDescriptorDataObject dataObject = (SunDescriptorDataObject) sectionNodeView.getDataObject();
        J2EEBaseVersion j2eeVersion = dataObject.getJ2eeModuleVersion();
        if(j2eeVersion == null || j2eeVersion.compareSpecification(J2EEVersion.J2EE_1_4) >= 0) {
            addChild(new ServiceRefGroupNode(sectionNodeView, ejb, version));
            if(ASDDVersion.SUN_APPSERVER_9_0.compareTo(version) <= 0) {
                if(j2eeVersion == null || j2eeVersion.compareSpecification(J2EEVersion.JAVAEE_5_0) >= 0) {
                    addChild(new MessageDestinationRefGroupNode(sectionNodeView, ejb, version));
                }
            }
        }
    }
}
 
Example 4
Source File: RESTExplorerPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void addNotify() {
    super.addNotify();
    manager.addPropertyChangeListener(this);
    Project[] projects = OpenProjects.getDefault().getOpenProjects();
    Children rootChildren = new Children.Array();
    AbstractNode explorerResourcesRoot = new AbstractNode(rootChildren);
    List<Node> projectNodeList = new ArrayList<Node>();
    for (Project prj : projects) {
        Node node = factory.createNode(prj);
        if ( node != null ){
            projectNodeList.add(node);
        }
    }
    Node[] projectNodes = new Node[projectNodeList.size()];
    projectNodeList.<Node>toArray(projectNodes);
    rootChildren.add(projectNodes);
    manager.setRootContext(explorerResourcesRoot);
    
    // !PW If we preselect a node, this can go away.
    descriptor.setValid(false);

    treeView.requestFocusInWindow();
}
 
Example 5
Source File: TTVTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private NodeStructure createNodeStructure (NodeHolderProperty[] props) {
    NodeStructure createdData = new NodeStructure();
    createdData.childrenNodes = new Node[100];
    Children rootChildren = new Children.Array();
    createdData.rootNode = new AbstractNode(rootChildren);
    createdData.rootNode.setDisplayName("Root test node");
    for (int i = 0; i < 100; i++) {
        Node newNode = new TestNode("node #" + i);
        createdData.childrenNodes[i] = newNode;
    }
    rootChildren.add(createdData.childrenNodes);
    return createdData;
}
 
Example 6
Source File: CustomScopePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Children createChildren(ProjectData data, CustomScopePanel panel) {
    Children childs = new Children.Array();
    for (SourceData sourceData : data.getSources()) {
        childs.add(new Node[]{new SourceGroupNode(sourceData, panel)});
    }
    return childs;
}
 
Example 7
Source File: CustomScopePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Children createChildren(final PackageData data, CustomScopePanel panel) {
    Children childs = new Children.Array();
    for (ClassData classData : data.getClasses()) {
        childs.add(new Node[]{new ClassNode(classData, panel)});
    }
    return childs;
}
 
Example 8
Source File: ProjectFileExplorer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ProjectFileExplorer() {
    projects = OpenProjects.getDefault().getOpenProjects();
    rootChildren = new Children.Array();
    explorerClientRoot = new AbstractNode(rootChildren);
    projectNodeList = new ArrayList<Node>();
    manager = new ExplorerManager();

    initComponents();
    initUserComponents();
}
 
Example 9
Source File: TopComponentGetLookupOverridenTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void propertyChange (java.beans.PropertyChangeEvent ev) {
    ExplorerManager manager = delegate.getExplorerManager ();

    LOG.info("propertyChange: " + ev.getPropertyName());

    if ("activatedNodes".equals (ev.getPropertyName())) {
        if (Boolean.TRUE.equals (callbacks.get ())) {
            LOG.info("  it was callback");
            return;
        }
        try {
            callbacks.set (Boolean.TRUE);
            Node[] arr = getActivatedNodes ();

            LOG.info("settings ndoes to zero");
            // first of all clear the previous values otherwise
            // we will not test SynchronizeNodes (associateLookup (..., true))
            setActivatedNodes (ownNode());


            Children.Array ch = (Children.Array)manager.getRootContext ().getChildren ();
            for (int i = 0; i < arr.length; i++) {
                if (arr[i].getParentNode() != manager.getRootContext()) {
                    assertTrue ("If this fails we are in troubles", ch.add (new Node[] { arr[i] }));
                }
            }
            LOG.info("em setSelectedNodes: " + Arrays.asList(arr));
            manager.setSelectedNodes (arr);
            LOG.info("em setSelectedNodes done: " + Arrays.asList(arr));
        } catch (java.beans.PropertyVetoException ex) {
            ex.printStackTrace();
            fail (ex.getMessage());
        } finally {
            callbacks.set (null);
        }
    }

}
 
Example 10
Source File: TreeTableView126560Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Node createNodes(int subNodesCount) {
    if (subNodesCount == 0) {
        return new TestNode(Children.LEAF);
    }
    Node[] subnodes = new TestNode[subNodesCount];
    for (int i = 0; i < subnodes.length; i++) {
        subnodes[i] = new TestNode(Children.LEAF);
    }
    Children ch = new Children.Array();
    ch.add(subnodes);
    return new TestNode(ch);
}
 
Example 11
Source File: ClientExplorerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public ClientExplorerPanel(FileObject srcFileObject) {
    super(srcFileObject);
    projects = OpenProjects.getDefault().getOpenProjects();
    rootChildren = new Children.Array();
    explorerClientRoot = new AbstractNode(rootChildren);
    projectNodeList = new ArrayList<Node>();
}
 
Example 12
Source File: DummyPalette.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static Node createPaletteRoot() {
    Children categories = new Children.Array();
    categories.add( createCategories() );
    return new RootNode( categories );
}
 
Example 13
Source File: WildflyTargetNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public WildflyTargetNode(Lookup lookup) {
    super(new Children.Array());
    getChildren().add(new Node[] {
        new WildflyItemNode(new WildflyApplicationsChildren(lookup), NbBundle.getMessage(WildflyTargetNode.class, "LBL_Apps")),
        new WildflyResourcesItemNode(new WildflyResourcesChildren(lookup), NbBundle.getMessage(WildflyTargetNode.class, "LBL_Resources"), Util.RESOURCES_ICON)});
}
 
Example 14
Source File: ContextTreeViewTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testLeafNodeReallyNotDisplayed() throws Throwable {
    final AbstractNode root = new AbstractNode(new Children.Array());
    root.setName("test root");
    
    
    
    root.getChildren().add(new Node[] {
        createLeaf("kuk"),
        createLeaf("huk"),
    });
    
    class AWTTst implements Runnable {
        public void run() {
            Panel p = new Panel();
            p.getExplorerManager().setRootContext(root);

            ContextTreeView ctv = new ContextTreeView();
            p.add(BorderLayout.CENTER, ctv);

            JFrame f = new JFrame();
            f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
            f.getContentPane().add(BorderLayout.CENTER, p);
            f.setVisible(true);

            final JTree tree = ctv.tree;
    
            // wait a while till the frame is realized and ctv.addNotify called
            Object r = tree.getModel().getRoot();
            assertEquals("There is root", Visualizer.findVisualizer(root), r);
            
            int cnt = tree.getModel().getChildCount(r);
            if (cnt != 0) {
                fail("Should be zero " + cnt + " but there was:  " +
                        tree.getModel().getChild(r, 0) + " and " +
                        tree.getModel().getChild(r, 1)
                        );
            }
            assertEquals("No children as they are leaves", 0, cnt);

            Node n = Visualizer.findNode(r);
            n.setName("Try Rename!");
        }
    }
    AWTTst awt = new AWTTst();
    try {
        SwingUtilities.invokeAndWait(awt);
    } catch (InvocationTargetException ex) {
        throw ex.getTargetException();
    }
}
 
Example 15
Source File: SelectionModeTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Create tree and a selection of nodes for test.
 */
@SuppressWarnings("deprecation")
@Override
protected void setUp () {
    System.setProperty ("org.openide.util.Lookup", Lkp.class.getName());
    
    // create tree:
    // root +--- parent_one +--- one1
    //                      |--- one2
    //      |--- parent_two +--- two1
    //      |--- leaf
    
    final Children parents = new Children.Array ();
    Node root = new AbstractNode (parents);
    root.setName ("root");
    
    tree = new BeanTreeView ();
    //tree = new ContextTreeView ();

    final org.openide.explorer.ExplorerPanel p = new org.openide.explorer.ExplorerPanel();
    p.setName ("SelectionModeTest");
    
    p.add (tree, BorderLayout.CENTER);
    p.getExplorerManager ().setRootContext (root);
    p.open ();

    final Children ones = new Children.Array ();
    Node parent_one = new AbstractNode (ones);
    parent_one.setName ("parent_one");
    final Children twos = new Children.Array ();
    Node parent_two = new AbstractNode (twos);
    parent_two.setName ("parent_two");

    final Node one1 = new AbstractNode (Children.LEAF);
    one1.setName("one1");

    final Node one2 = new AbstractNode (Children.LEAF);
    one2.setName("one2");

    ones.add(new Node[] { one1, one2 });
    
    final Node two1 = new AbstractNode (Children.LEAF);
    two1.setName("two1");

    twos.add (new Node[] { two1 });
    
    parents.add (new Node[] { parent_one, parent_two });
    
    
    // the test selections
    singleSelection = new Node[] {parent_two};
    contiguousSelection = new Node[] {one1, one2};
    discontiguousSelection = new Node[] {one2, two1};
    
    mgr = p.getExplorerManager();
}
 
Example 16
Source File: ContextTreeViewModelTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static Node createNode(String name, boolean leaf) {
    AbstractNode n = new AbstractNode(leaf ? Children.LEAF : new Children.Array());
    n.setName(name);
    return n;
}
 
Example 17
Source File: ExplorerPanelTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public TestRoot(Node[] children) {
    super(new Children.Array());
    getChildren().add(children);
}
 
Example 18
Source File: TreeViewTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testExpandNodePreparedOutsideOfAWT() throws Exception {
    assertFalse(EventQueue.isDispatchThread());

    class OutOfAWT extends Keys {
        Exception noAWTAddNotify;
        Exception noAWTCreateNodes;

        public OutOfAWT(boolean lazy, String... args) {
            super(lazy, args);
        }

        @Override
        protected void addNotify() {
            if (EventQueue.isDispatchThread()) {
                noAWTAddNotify = new Exception();
            }
            super.addNotify();
        }

        @Override
        protected Node[] createNodes(Object key) {
            if (EventQueue.isDispatchThread()) {
                noAWTCreateNodes = new Exception();
            }
            return super.createNodes(key);
        }
    }
    AbstractNode root = new AbstractNode(new Children.Array());
    final OutOfAWT ch = new OutOfAWT(false, "A", "B", "C");
    AbstractNode an = new AbstractNode(ch);
    root.getChildren().add(new Node[] { an });
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            testWindow = new ExplorerWindow();
        }
    });
    testWindow.showWindow();
    testWindow.getExplorerManager().setRootContext(root);

    testWindow.treeView.expandNode(an);
    Thread.sleep(2000);

    if (ch.noAWTAddNotify != null) {
        throw ch.noAWTAddNotify;
    }
    if (ch.noAWTCreateNodes != null) {
        throw ch.noAWTCreateNodes;
    }
}
 
Example 19
Source File: ContextTreeViewModelTest.java    From netbeans with Apache License 2.0 2 votes vote down vote up
public void testRemoveInMiddle() throws Throwable {
    final AbstractNode root = new AbstractNode(new Children.Array());
    root.setName("test root");


    LOG.info("root added");

    root.getChildren().add(new Node[] { createNode("Ahoj", false) });
    
    LOG.info("a node added");

    Node[] first = {
        createNode("kuk", false),
        createNode("huk", false),
    };


    LOG.info("adding more nodes");
    
    root.getChildren().add(first);

    LOG.info("nodes added");
    
    
    NodeTreeModel m = new ContextTreeView.NodeContextModel();
    m.setNode(root);

    LOG.info("root set");
    TreeNode visual = (TreeNode)m.getRoot();

    LOG.info("visual is here: " + visual);

    waitEQ();
    
    
    assertEquals("Initial size is two", 3, m.getChildCount(visual));
    
    Listener listener = new Listener(visual);
    m.addTreeModelListener(listener);


    LOG.info("listener added");
    
    Node[] arr = {
        createNode("add1", false), createNode("add2", false)
    };

    assertAgressiveGC();
    
    root.getChildren().add(arr);

    LOG.info("arr added");

    listener.assertEvents("One addition", 1);
    listener.assertIndexes("after the three first", new int[] { 3, 4 });

    LOG.info("arr ok");

    root.getChildren().remove(first);


    LOG.info("arr removed");

    listener.assertEvents("One removal", 1);
    listener.assertIndexes("from end", new int[] { 1, 2 });

    LOG.info("all ok");
}
 
Example 20
Source File: ContextTreeViewModelTest.java    From netbeans with Apache License 2.0 2 votes vote down vote up
public void testABitMoreComplexAddAndRemoveEventCheck() throws Throwable {
    final AbstractNode root = new AbstractNode(new Children.Array());
    root.setName("test root");

    LOG.info("root created");

    root.getChildren().add(new Node[] {
        createNode("kuk", false),
        createNode("huk", false),
    });


    LOG.info("two nodes added");
    
    NodeTreeModel m = new ContextTreeView.NodeContextModel();
    m.setNode(root);

    LOG.info("root set");

    TreeNode visual = (TreeNode)m.getRoot();
    waitEQ();

    LOG.info("visual is here: " + visual);
    
    
    assertEquals("Initial size is two", 2, m.getChildCount(visual));
    
    Listener listener = new Listener(visual);
    m.addTreeModelListener(listener);

    LOG.info("listener added");
    
    Node[] arr = {
        createNode("add1", false), createNode("add2", false)
    };

    assertAgressiveGC();

    LOG.info("adding children");
    root.getChildren().add(arr);

    LOG.info("children added");

    listener.assertEvents("One addition", 1);
    listener.assertIndexes("after the two first", new int[] { 2, 3 });

    LOG.info("removing children");
    root.getChildren().remove(arr);
    LOG.info("children removed");

    listener.assertEvents("One removal", 1);
    listener.assertIndexes("from end", new int[] { 2, 3 });

    LOG.info("all well");
}