This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 182427
Collapse All | Expand All

(-)a/openide.explorer/apichanges.xml (+14 lines)
Lines 50-55 Link Here
50
<apidef name="explorer">Explorer API</apidef>
50
<apidef name="explorer">Explorer API</apidef>
51
</apidefs>
51
</apidefs>
52
<changes>
52
<changes>
53
    <change id="TreeView.editNode">
54
        <api name="explorer"/>
55
        <summary><code>TreeView.editNode</code> added</summary>
56
        <version major="6" minor="60"/>
57
        <date day="14" month="11" year="2014"/>
58
        <author login="tboudreau"/>
59
        <compatibility binary="compatible" source="incompatible" deprecation="no" deletion="no" addition="yes"/>
60
        <description>
61
            Added <code>TreeView.editNode(Node)</code> to programmatically
62
            enter inline-edit mode on a TreeView. Method is thread-safe.
63
        </description>
64
        <class package="org.openide.explorer.view" name="TreeView"/>
65
        <issue number="182427"/>
66
    </change>
53
    <change id="HideIcons">
67
    <change id="HideIcons">
54
        <api name="explorer"/>
68
        <api name="explorer"/>
55
        <summary>Hide node icons in OutlineView and TreeView.</summary>
69
        <summary>Hide node icons in OutlineView and TreeView.</summary>
(-)a/openide.explorer/manifest.mf (-1 / +1 lines)
Lines 2-6 Link Here
2
OpenIDE-Module: org.openide.explorer
2
OpenIDE-Module: org.openide.explorer
3
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties
4
AutoUpdate-Essential-Module: true
4
AutoUpdate-Essential-Module: true
5
OpenIDE-Module-Specification-Version: 6.59
5
OpenIDE-Module-Specification-Version: 6.60
6
6
(-)a/openide.explorer/src/org/openide/explorer/view/TreeView.java (+47 lines)
Lines 141-146 Link Here
141
import javax.swing.tree.TreePath;
141
import javax.swing.tree.TreePath;
142
import javax.swing.tree.TreeSelectionModel;
142
import javax.swing.tree.TreeSelectionModel;
143
import org.openide.awt.QuickSearch;
143
import org.openide.awt.QuickSearch;
144
import org.openide.util.Parameters;
144
145
145
146
146
/**
147
/**
Lines 620-625 Link Here
620
        });
621
        });
621
    }
622
    }
622
623
624
    /**
625
     * Initiate inline-edit mode for a Node, expanding its parent
626
     * and selecting it if necessary.  This method is thread-safe.
627
     * <p/>
628
     * If this TreeView is not actually on-screen when the edit is
629
     * initiated (for example, a call after the call to editNode() removes
630
     * it from the AWT hierarchy) then this method logs an error and does
631
     * nothing.
632
     *
633
     * @since 6.60
634
     * @param node A node whose name should be edited visually by the user
635
     */
636
    public final void editNode(final Node node) {
637
        Parameters.notNull("node", node); //NOI18N
638
        //Do not use VisualizerNode.runSafe(), which will call
639
        //EQ.invokeAndWait()
640
        Mutex.EVENT.readAccess(new EditInitiator(node));
641
    }
642
643
    private final class EditInitiator implements Runnable {
644
        private final Node node;
645
        EditInitiator (Node target) {
646
            this.node = target;
647
        }
648
649
        @Override
650
        public void run() {
651
            if (!isDisplayable()) {
652
                Logger.getLogger(TreeView.class.getName()).log(
653
                        Level.WARNING, "Attempt to edit node {0} but " + //NOI18N
654
                        "component not on screen", node); //NOI18N
655
                return;
656
            }
657
            lookupExplorerManager();
658
            TreePath path = getTreePath(node);
659
            if (path == null) {
660
                throw new IllegalArgumentException ("Unknown node " + node); //NOI18N
661
            }
662
            if (!tree.isExpanded(path)) {
663
                tree.expandPath(path);
664
            }
665
            tree.setSelectionPath(path);
666
            tree.startEditingAtPath(path);
667
        }
668
    }
669
623
    /** Test whether a node is expanded in the tree or not
670
    /** Test whether a node is expanded in the tree or not
624
    * @param n the node to test
671
    * @param n the node to test
625
    * @return true if the node is expanded
672
    * @return true if the node is expanded
(-)a/openide.explorer/src/org/openide/explorer/view/TreeViewCellEditor.java (+8 lines)
Lines 172-177 Link Here
172
    public void focusGained(FocusEvent evt) {
172
    public void focusGained(FocusEvent evt) {
173
    }
173
    }
174
174
175
    Ed ed() { //editNodeTest
176
        return (Ed) realEditor;
177
    }
178
175
    /**
179
    /**
176
     * This is invoked if a TreeCellEditor is not supplied in the constructor.
180
     * This is invoked if a TreeCellEditor is not supplied in the constructor.
177
     * It returns a TextField editor.
181
     * It returns a TextField editor.
Lines 371-376 Link Here
371
            super(tf);
375
            super(tf);
372
        }
376
        }
373
377
378
        JTextField comp() {  //editNodeTest
379
            return (JTextField) super.getComponent();
380
        }
381
374
        /** Main method of the editor.
382
        /** Main method of the editor.
375
        * @return component of editor
383
        * @return component of editor
376
        */
384
        */
(-)a/openide.explorer/test/unit/src/org/openide/explorer/view/BeanTreeViewTest.java (+101 lines)
Lines 69-74 Link Here
69
import org.openide.nodes.AbstractNode;
69
import org.openide.nodes.AbstractNode;
70
import org.openide.nodes.Children;
70
import org.openide.nodes.Children;
71
import org.openide.nodes.Node;
71
import org.openide.nodes.Node;
72
import java.awt.EventQueue;
73
import java.awt.event.HierarchyEvent;
74
import java.awt.event.HierarchyListener;
75
import java.awt.event.WindowAdapter;
76
import java.awt.event.WindowEvent;
77
import java.util.concurrent.CountDownLatch;
78
import javax.swing.JTextField;
79
import org.openide.explorer.view.TreeViewCellEditor.Ed;
72
80
73
/**
81
/**
74
 * Tests for class BeanTreeViewTest
82
 * Tests for class BeanTreeViewTest
Lines 539-542 Link Here
539
            return em;
547
            return em;
540
        }
548
        }
541
    }
549
    }
550
551
    public void testEditNode() throws Exception {
552
        Children.Array kids = new Children.Array();
553
        Node[] n = new Node[20];
554
        Node node = null;
555
        for (int i=0; i < n.length; i++) {
556
            n[i] = new RenamableNode ("" + i);
557
            if (i == 5) {
558
                node = n[i]; //pick one to edit
559
            }
560
        }
561
        kids.add(n);
562
        final Node root = new AbstractNode (kids);
563
        root.setDisplayName("Root");
564
        final WL wl = new WL();
565
        final F[] ff = new F[1];
566
        EventQueue.invokeLater(new Runnable() {
567
568
            @Override
569
            public void run() {
570
                ff[0] = new F(root);
571
                ff[0].addWindowListener(wl);
572
                ff[0].pack();
573
                ff[0].setVisible(true);
574
            }
575
576
        });
577
        wl.latch.await();
578
        F f = ff[0];
579
        //sanity check
580
        assertTrue (f.isDisplayable());
581
        assertTrue (f.isShowing());
582
        assertTrue (f.view.isShowing());
583
        JTree tree = f.view.tree;
584
        TreeViewCellEditor ce = (TreeViewCellEditor) tree.getCellEditor();
585
        Ed ed = ce.ed();
586
        final JTextField comp = ed.comp();
587
        final CountDownLatch latch = new CountDownLatch(1);
588
        comp.addHierarchyListener(new HierarchyListener() {
589
590
            @Override
591
            public void hierarchyChanged(HierarchyEvent e) {
592
                if (comp.isDisplayable()) {
593
                    latch.countDown();
594
                }
595
            }
596
597
        });
598
        f.view.editNode(node);
599
        latch.await();
600
        assertTrue (tree.isEditing());
601
        assertTrue (comp.isDisplayable());
602
        f.setVisible(false);
603
        f.dispose();
604
    }
605
606
    private static final class RenamableNode extends AbstractNode {
607
        RenamableNode (String name) {
608
            super (Children.LEAF);
609
            setDisplayName(name);
610
            setName (name);
611
        }
612
613
        @Override
614
        public boolean canRename() {
615
            return true;
616
        }
617
    }
618
619
    private static final class F extends JFrame implements ExplorerManager.Provider {
620
        private final ExplorerManager mgr = new ExplorerManager();
621
        private final BeanTreeView view = new BeanTreeView();
622
        F(Node root) {
623
            setContentPane(view);
624
            mgr.setRootContext(root);
625
        }
626
627
        @Override
628
        public ExplorerManager getExplorerManager() {
629
            return mgr;
630
        }
631
632
    }
633
634
    private static final class WL extends WindowAdapter {
635
        CountDownLatch latch = new CountDownLatch(1);
636
637
        @Override
638
        public void windowOpened(WindowEvent e) {
639
            super.windowOpened(e);
640
            latch.countDown();
641
        }
642
    }
542
}
643
}

Return to bug 182427