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 181452
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.quickSearchAllowed">
54
        <api name="explorer"/>
55
        <summary>It's possible to define whether the quick search enable or disable in TreeView.</summary>
56
        <version major="6" minor="33"/>
57
        <date day="4" month="10" year="2010"/>
58
        <author login="theanuradha"/>
59
        <compatibility binary="compatible" source="compatible" deprecation="no" deletion="no" addition="yes"/>
60
        <description>
61
            Methods <code>setQuickSearchAllowed()</code> and <code>isQuickSearchAllowed()</code>
62
            added to TreeView to control quick search enable or disable.
63
        </description>
64
        <class package="org.openide.explorer.view" name="TreeView"/>
65
        <issue number="181452"/>
66
    </change>
53
    <change id="OutlineView.defaultActionAllowed">
67
    <change id="OutlineView.defaultActionAllowed">
54
        <api name="explorer"/>
68
        <api name="explorer"/>
55
        <summary>It's possible to define whether the default action is allowed or not in OutlineView.</summary>
69
        <summary>It's possible to define whether the default action is allowed or not in OutlineView.</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.32
5
OpenIDE-Module-Specification-Version: 6.33
6
6
(-)a/openide.explorer/src/org/openide/explorer/view/TreeView.java (-6 / +45 lines)
Lines 228-233 Link Here
228
    transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
228
    transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
229
    transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
229
    transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
230
    
230
    
231
    /** Quick Search support */
232
    transient private boolean allowedQuickSearch = true;
233
    transient private KeyAdapter quickSearchKeyAdapter = null;
234
    
231
    /**
235
    /**
232
     * Whether the quick search uses prefix or substring. 
236
     * Whether the quick search uses prefix or substring. 
233
     * Defaults to false meaning prefix is used.
237
     * Defaults to false meaning prefix is used.
Lines 452-457 Link Here
452
    }
456
    }
453
457
454
    /**
458
    /**
459
     * Get whether the quick search feature enable or not.
460
     * Defaults enable (false).
461
     * @since 6.33
462
     * @return true if quick search feature enabled, false
463
     * otherwise.
464
     */
465
    public boolean isQuickSearchAllowed() {
466
        return allowedQuickSearch;
467
    }
468
    
469
    /**
470
     * Set whether the quick search feature enable or not.
471
     * Defaults enable (false).
472
     * @since 6.33
473
     * @param allowedQuickSearch <code>true</code> if quick search need to enable
474
     */
475
    public void setQuickSearchAllowed(boolean allowedQuickSearch) {
476
        this.allowedQuickSearch = allowedQuickSearch;
477
        
478
         if(quickSearchKeyAdapter !=null && tree !=null ){
479
            if(allowedQuickSearch){
480
               tree.addKeyListener(quickSearchKeyAdapter);
481
            }else{
482
               removeSearchField();
483
               tree.removeKeyListener(quickSearchKeyAdapter);
484
            }
485
         }
486
    }
487
488
    
489
    /**
455
     * Set whether the quick search feature uses substring or prefix
490
     * Set whether the quick search feature uses substring or prefix
456
     * matching for the typed characters. Defaults to prefix (false).
491
     * matching for the typed characters. Defaults to prefix (false).
457
     * @since 6.11
492
     * @since 6.11
Lines 967-973 Link Here
967
            }
1002
            }
968
        });
1003
        });
969
    }
1004
    }
970
1005
    
1006
   
1007
    
971
    /** Synchronize the selected nodes from the manager of this Explorer.
1008
    /** Synchronize the selected nodes from the manager of this Explorer.
972
    * The default implementation does nothing.
1009
    * The default implementation does nothing.
973
    */
1010
    */
Lines 1629-1635 Link Here
1629
    }
1666
    }
1630
1667
1631
    TreePath[] origSelectionPaths = null;
1668
    TreePath[] origSelectionPaths = null;
1632
    private JPanel searchpanel = null;
1669
    JPanel searchpanel = null;
1633
    // searchTextField manages focus because it handles VK_TAB key
1670
    // searchTextField manages focus because it handles VK_TAB key
1634
    private JTextField searchTextField = new JTextField() {
1671
    private JTextField searchTextField = new JTextField() {
1635
        @Override
1672
        @Override
Lines 1968-1975 Link Here
1968
                removeKeyListener(keyListeners[i]);
2005
                removeKeyListener(keyListeners[i]);
1969
            }
2006
            }
1970
2007
1971
            // Add new key listeners
2008
            // create new key listeners
1972
            addKeyListener(
2009
            quickSearchKeyAdapter = (
1973
                new KeyAdapter() {
2010
                new KeyAdapter() {
1974
                @Override
2011
                @Override
1975
                    public void keyTyped(KeyEvent e) {
2012
                    public void keyTyped(KeyEvent e) {
Lines 2001-2007 Link Here
2001
                    }
2038
                    }
2002
                }
2039
                }
2003
            );
2040
            );
2004
2041
            if(isQuickSearchAllowed()){
2042
                addKeyListener(quickSearchKeyAdapter);
2043
            }
2005
            // Create a the "multi-event" listener for the text field. Instead of
2044
            // Create a the "multi-event" listener for the text field. Instead of
2006
            // adding separate instances of each needed listener, we're using a
2045
            // adding separate instances of each needed listener, we're using a
2007
            // class which implements them all. This approach is used in order 
2046
            // class which implements them all. This approach is used in order 
Lines 2011-2017 Link Here
2011
            searchTextField.addFocusListener(searchFieldListener);
2050
            searchTextField.addFocusListener(searchFieldListener);
2012
            searchTextField.getDocument().addDocumentListener(searchFieldListener);
2051
            searchTextField.getDocument().addDocumentListener(searchFieldListener);
2013
        }
2052
        }
2014
2053
        
2015
        private List<TreePath> doSearch(String prefix) {
2054
        private List<TreePath> doSearch(String prefix) {
2016
            List<TreePath> results = new ArrayList<TreePath>();
2055
            List<TreePath> results = new ArrayList<TreePath>();
2017
2056
(-)a/openide.explorer/test/unit/src/org/openide/explorer/view/TreeViewQuickSearchTest.java (+98 lines)
Lines 61-66 Link Here
61
import org.openide.nodes.AbstractNode;
61
import org.openide.nodes.AbstractNode;
62
import org.openide.nodes.Children;
62
import org.openide.nodes.Children;
63
import org.openide.nodes.Node;
63
import org.openide.nodes.Node;
64
import org.openide.util.Exceptions;
64
65
65
/**
66
/**
66
 * Tests for the quick search feature in the treeview.
67
 * Tests for the quick search feature in the treeview.
Lines 181-186 Link Here
181
        }
182
        }
182
    }
183
    }
183
    
184
    
185
    public void testQuickSearchEnable() throws Throwable {
186
        final AbstractNode root = new AbstractNode(new Children.Array());
187
        root.setName("test root");
188
        
189
        final Node[] children = {
190
            createLeaf("foo1"),
191
            createLeaf("foo2"),
192
            createLeaf("bar1"),
193
            createLeaf("bar2"),
194
            createLeaf("alpha"),
195
        };
196
        
197
        root.getChildren().add(children);
198
        
199
        final Panel p = new Panel();
200
        p.getExplorerManager().setRootContext(root);
201
        
202
        final BeanTreeView btv = new BeanTreeView();
203
        p.add(BorderLayout.CENTER, btv);
204
205
        
206
        JFrame f = new JFrame();
207
        f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
208
        f.getContentPane().add(BorderLayout.CENTER, p);
209
        f.pack();
210
        f.setVisible(true);
211
        
212
        
213
       final Exception[]problem = new Exception[1];
214
        final Integer[] phase = new Integer[1];
215
         phase[0] = 0;
216
        class AWTTst implements Runnable {
217
            public void run() {
218
                try {
219
                        if (phase[0] == 0) {
220
                            btv.tree.requestFocus();
221
                            try {
222
                                p.getExplorerManager().setSelectedNodes(new Node[] { root });
223
                            } catch (PropertyVetoException e) {
224
                                fail("Unexpected PropertyVetoException from ExplorerManager.setSelectedNodes()");
225
                            }
226
                        }
227
                            Robot robot = new Robot();
228
                            Point p = btv.tree.getLocationOnScreen();
229
                            robot.mouseMove(p.x + 10, p.y + 10);
230
                            robot.mousePress(0);
231
                            robot.mouseRelease(0);
232
                            robot.keyPress(KeyEvent.VK_A);
233
                           
234
                            if(phase[0] != 0)
235
                            {
236
                                boolean panelUsed = btv.searchpanel !=null;
237
          
238
                                if(btv.isQuickSearchAllowed()){
239
                                    assertTrue("Quick Search enabled ", panelUsed);
240
                                }else{
241
                                    assertFalse("Quick Search disable",  panelUsed);
242
                                }
243
                            }
244
                            
245
                        
246
                } catch (AWTException ex) {
247
                    problem[0] = ex;
248
                }
249
            }
250
        }
251
        AWTTst awt = new AWTTst();
252
        try {
253
            SwingUtilities.invokeAndWait(awt);
254
        } catch (InvocationTargetException ex) {
255
            throw ex.getTargetException();
256
        }
257
        if (problem[0] != null) {
258
            throw problem[0];
259
        }
260
        Thread.sleep(1000);
261
        phase[0] = 1;
262
        btv.setQuickSearchAllowed(true);
263
        try {
264
            SwingUtilities.invokeAndWait(awt);
265
        } catch (InvocationTargetException ex) {
266
            throw ex.getTargetException();
267
        }
268
        if (problem[0] != null) {
269
            throw problem[0];
270
        }
271
        
272
        Thread.sleep(1000);
273
        btv.setQuickSearchAllowed(false);
274
        try {
275
            SwingUtilities.invokeAndWait(awt);
276
        } catch (InvocationTargetException ex) {
277
            throw ex.getTargetException();
278
        }
279
        
280
    }
281
    
184
    private static Node createLeaf(String name) {
282
    private static Node createLeaf(String name) {
185
        AbstractNode n = new AbstractNode(Children.LEAF);
283
        AbstractNode n = new AbstractNode(Children.LEAF);
186
        n.setName(name);
284
        n.setName(name);

Return to bug 181452