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

The following are Jave code examples for showing how to use setName() 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: RenameGroupAction.java   Source Code and License Vote up 6 votes
@Override
protected void performAction(Node[] nodes) {
    if (nodes != null && nodes.length == 1) {
        SaasGroup group = nodes[0].getLookup().lookup(SaasGroup.class);
        if (group == null) {
            return;
        }

        Node n = nodes[0];
        NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
                NbBundle.getMessage(RenameAction.class, "CTL_RenameLabel"), // NOI18N
                NbBundle.getMessage(RenameAction.class, "CTL_RenameTitle")); // NOI18N
        dlg.setInputText(n.getName());
        if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
            String name = dlg.getInputText().trim();
            if (group.getParent().getChildGroup(name) != null) {
                String msg = NbBundle.getMessage(RenameGroupAction.class, "MSG_DuplicateGroupName"); // NOI18N
                DialogDisplayer.getDefault().notify(
                        new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE));
                return;
            }
            SaasServicesModel.getInstance().renameGroup(group, name);
            n.setName(name);
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: PreventNeedlessChangesOfActionMapTest.java   Source Code and License Vote up 6 votes
public void testChangeOfNodeDoesNotFireChangeInActionMap() {
    ActionMap am = (ActionMap)tc.getLookup().lookup(ActionMap.class);
    assertNotNull(am);
    
    Node m1 = new AbstractNode(Children.LEAF);
    m1.setName("old m1");
    Node m2 = new AbstractNode(Children.LEAF);
    m2.setName("new m2");
    
    tc.setActivatedNodes(new Node[] { m1 });
    assertEquals("No change in ActionMap 1", 0, cnt);
    tc.setActivatedNodes(new Node[] { m2 });
    assertEquals("No change in ActionMap 2", 0, cnt);
    tc.setActivatedNodes(new Node[0]);
    assertEquals("No change in ActionMap 3", 0, cnt);
    tc.setActivatedNodes(null);
    assertEquals("No change in ActionMap 4", 0, cnt);
    
    ActionMap am2 = (ActionMap)tc.getLookup().lookup(ActionMap.class);
    assertEquals("Still the same action map", am, am2);
}
 
Example 3
Project: incubator-netbeans   File: NodeFactorySupportTest.java   Source Code and License Vote up 5 votes
/**
 * Test of createCompositeChildren method, of class org.netbeans.spi.project.ui.support.NodeFactorySupport.
 */
public void testCreateCompositeChildren() throws InterruptedException, InvocationTargetException {
    InstanceContent ic = new InstanceContent();
    final Children dels = new TestDelegates(new AbstractLookup(ic));
    final Node node1 = new AbstractNode(Children.LEAF);
    final Node node2 = new AbstractNode(Children.LEAF);
    final Node node3 = new AbstractNode(Children.LEAF);
    final Node node4 = new AbstractNode(Children.LEAF);
    node1.setName("node1");
    node2.setName("node2");
    node3.setName("node3");
    node4.setName("node4");
    NodeFactory fact1 = new TestNodeFactory(node1);
    NodeFactory fact2 = new TestNodeFactory(node2);
    NodeFactory fact3 = new TestNodeFactory(node3);
    NodeFactory fact4 = new TestNodeFactory(node4);
    List<NodeFactory> col = new ArrayList<NodeFactory>();
    col.add(fact1);
    col.add(fact2);
    ic.set(col, null);

    assertEquals(Arrays.asList(node1, node2), Arrays.asList(dels.getNodes(true)));
    
    col.add(0, fact4);
    col.add(fact3);
    col.remove(fact2);
    ic.set(col, null);
    //#115995, caused by fix for #115128
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            Node[] nds = dels.getNodes();
            assertEquals(nds[0], node4);
            assertEquals(nds[1], node1);
            assertEquals(nds[2], node3);
        }
    });
    
}
 
Example 4
Project: incubator-netbeans   File: ViewUtil.java   Source Code and License Vote up 5 votes
static void nodeRename(final Node n, final String newStr) {
    // bugfix #21589 don't update name if there is not any change
    if (n.getName().equals(newStr)) {
        return;
    }
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                nodeRename(n, newStr);
            }
        });
        return;
    }
    try {
        n.setName(newStr);
    } catch (IllegalArgumentException exc) {
        boolean needToAnnotate = Exceptions.findLocalizedMessage(exc) == null;

        // annotate new localized message only if there is no localized message yet
        if (needToAnnotate) {
            String msg = NbBundle.getMessage(
                    TreeViewCellEditor.class, "RenameFailed", n.getName(), newStr
                );
            Exceptions.attachLocalizedMessage(exc, msg);
        }

        Exceptions.printStackTrace(exc);
    }
}
 
Example 5
Project: incubator-netbeans   File: ContextTreeViewTest.java   Source Code and License Vote up 5 votes
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 6
Project: incubator-netbeans   File: ViewUtilTest.java   Source Code and License Vote up 5 votes
public void testRenameNormalNode() {
    Node n = new AbstractNode(Children.LEAF) {
        @Override
        public void setName(String s) {
            assertTrue("In AWT", EventQueue.isDispatchThread());
            super.setName(s);
        }
    };
    
    n.setName("newName");
    assertEquals("newName", n.getName());
}
 
Example 7
Project: incubator-netbeans   File: DataFolderTest.java   Source Code and License Vote up 5 votes
public void testNameAndRenameWithADot() throws IOException {
    FileObject fo = FileUtil.createMemoryFileSystem().getRoot().createFolder("name-with.dot");
    DataFolder folder = DataFolder.findFolder(fo);
    Node n = folder.getNodeDelegate();
    assertEquals("Full name provided", "name-with.dot", n.getName());
    n.setName("new-name.other");
    assertEquals("New name set", "new-name.other", n.getName());
    assertEquals("New name of dobj too", "new-name.other", folder.getName());
    assertEquals("New name of fo too", "new-name.other", fo.getNameExt());
}
 
Example 8
Project: incubator-netbeans   File: SerialDataNodeTest.java   Source Code and License Vote up 5 votes
public void testDisplayName() throws Exception {
    String res = "Settings/org-netbeans-modules-settings-convertors-testDisplayName.settings";
    FileObject fo = FileUtil.getConfigFile(res);
    assertNotNull(res, fo);
    assertNull("name", fo.getAttribute("name"));
    
    DataObject dobj = DataObject.find (fo);
    Node n = dobj.getNodeDelegate();
    assertNotNull(n);
    assertEquals("I18N", n.getDisplayName());
    
    // property sets have to be initialized otherwise the change name would be
    // propagated to the node after some delay (~2s)
    Object garbage = n.getPropertySets();
    
    InstanceCookie ic = (InstanceCookie) dobj.getCookie(InstanceCookie.class);
    assertNotNull (dobj + " does not contain instance cookie", ic);
    
    FooSetting foo = (FooSetting) ic.instanceCreate();
    String newName = "newName";
    foo.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    
    newName = "newNameViaNode";
    n.setName(newName);
    assertEquals(n.toString(), newName, n.getDisplayName());
    assertEquals(n.toString(), newName, foo.getName());
}
 
Example 9
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);
}
 
Example 10
Project: incubator-netbeans   File: SelectionModeTest.java   Source Code and License Vote up 4 votes
/** 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 11
Project: incubator-netbeans   File: ListViewTest.java   Source Code and License Vote up 4 votes
/**
 * Creates two nodes. Selects one and tries to remove it
 * and replace with the other one (several times).
 */
public void testNodeAddingAndRemoving() {
    final Children c = new Array();
    Node n = new AbstractNode (c);
    final PListView lv = new PListView();
    final ExplorerPanel p = new ExplorerPanel();
    p.add(lv, BorderLayout.CENTER);
    p.getExplorerManager().setRootContext(n);
    p.open();

    final Node c1 = new AbstractNode(Children.LEAF);
    c1.setDisplayName("First");
    c1.setName("First");
    c.add(new Node[] { c1 });
    Node c2 = new AbstractNode(Children.LEAF);
    c2.setDisplayName("Second");
    c2.setName("Second");
    //Thread.sleep(500);

    for (int i = 0; i < 5; i++) {
        c.remove(new Node[] { c1 });
        c.add(new Node[] { c2 });
        
        // Waiting for until the view is updated.
        // This should not be necessary
        try {
            SwingUtilities.invokeAndWait( new EmptyRunnable() );
        } catch (InterruptedException ie) {
            fail ("Caught InterruptedException:" + ie.getMessage ());
        } catch (InvocationTargetException ite) {
            fail ("Caught InvocationTargetException: " + ite.getMessage ());
        }
        
        try {
            p.getExplorerManager().setSelectedNodes(new Node[] {c2} );
        } catch (PropertyVetoException  pve) {
            fail ("Caught the PropertyVetoException when set selected node " + c2.getName ()+ ".");
        }
        
        c.remove(new Node[] { c2 });
        c.add(new Node[] { c1 });
        
        //Thread.sleep(350);
    }
}
 
Example 12
Project: incubator-netbeans   File: ListViewTopComponentTest.java   Source Code and License Vote up 4 votes
/**
 * Creates two nodes. Selects one and tries to remove it
 * and replace with the other one (several times).
 */
public void testNodeAddingAndRemoving() {
    final Children c = new Array();
    Node n = new AbstractNode (c);
    final PListView lv = new PListView();
    final ExplorerPanel p = new ExplorerPanel();
    p.add(lv, BorderLayout.CENTER);
    p.getExplorerManager().setRootContext(n);
    p.open();

    final Node c1 = new AbstractNode(Children.LEAF);
    c1.setDisplayName("First");
    c1.setName("First");
    c.add(new Node[] { c1 });
    Node c2 = new AbstractNode(Children.LEAF);
    c2.setDisplayName("Second");
    c2.setName("Second");
    //Thread.sleep(500);

    for (int i = 0; i < 5; i++) {
        c.remove(new Node[] { c1 });
        c.add(new Node[] { c2 });
        
        // Waiting for until the view is updated.
        // This should not be necessary
        try {
            SwingUtilities.invokeAndWait( new EmptyRunnable() );
        } catch (InterruptedException ie) {
            fail ("Caught InterruptedException:" + ie.getMessage ());
        } catch (InvocationTargetException ite) {
            fail ("Caught InvocationTargetException: " + ite.getMessage ());
        }
        
        try {
            p.getExplorerManager().setSelectedNodes(new Node[] {c2} );
        } catch (PropertyVetoException  pve) {
            fail ("Caught the PropertyVetoException when set selected node " + c2.getName ()+ ".");
        }
        
        c.remove(new Node[] { c2 });
        c.add(new Node[] { c1 });
        
        //Thread.sleep(350);
    }
}
 
Example 13
Project: incubator-netbeans   File: RenameAction.java   Source Code and License Vote up 4 votes
protected void performAction(final Node[] activatedNodes) {
    if (activatedNodes == null || activatedNodes.length == 0) {
        return;
    }
    Node n = activatedNodes[0]; // we supposed that one node is activated
    
    // for slow FS perform rename out of EDT
    if (EventQueue.isDispatchThread() && Boolean.TRUE.equals(n.getValue("slowRename"))) { // NOI18N
        RP.post(new Runnable() {
            @Override
            public void run() {
                performAction(activatedNodes);
            }
        });
        return;
    }

    NotifyDescriptor.InputLine dlg = new NotifyDescriptor.InputLine(
            NbBundle.getMessage(RenameAction.class, "CTL_RenameLabel"),
            NbBundle.getMessage(RenameAction.class, "CTL_RenameTitle")
        );
    dlg.setInputText(n.getName());

    if (NotifyDescriptor.OK_OPTION.equals(DialogDisplayer.getDefault().notify(dlg))) {
        String newname = null;

        try {
            newname = dlg.getInputText();

            if (!newname.equals("")) {
                n.setName(dlg.getInputText()); // NOI18N
            }
        } catch (IllegalArgumentException e) {
            // determine if "printStackTrace"  and  "new annotation" of this exception is needed
            boolean needToAnnotate = Exceptions.findLocalizedMessage(e) == null;

            // annotate new localized message only if there is no localized message yet
            if (needToAnnotate) {
                Exceptions.attachLocalizedMessage(e,
                                                  NbBundle.getMessage(RenameAction.class,
                                                                      "MSG_BadFormat",
                                                                      n.getName(),
                                                                      newname));
            }

            Exceptions.printStackTrace(e);
        }
    }
}