--- a/openide.explorer/apichanges.xml Thu Nov 04 08:53:16 2010 +0100
+++ a/openide.explorer/apichanges.xml Thu Nov 04 09:44:33 2010 +0100
@@ -50,6 +50,20 @@
Explorer API
+
+
+ It's possible to define whether the quick search enable or disable in TreeView.
+
+
+
+
+
+ Methods setQuickSearchAllowed()
and isQuickSearchAllowed()
+ added to TreeView to control quick search enable or disable.
+
+
+
+
It's possible to define whether the default action is allowed or not in OutlineView.
--- a/openide.explorer/manifest.mf Thu Nov 04 08:53:16 2010 +0100
+++ a/openide.explorer/manifest.mf Thu Nov 04 09:44:33 2010 +0100
@@ -2,5 +2,5 @@
OpenIDE-Module: org.openide.explorer
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties
AutoUpdate-Essential-Module: true
-OpenIDE-Module-Specification-Version: 6.32
+OpenIDE-Module-Specification-Version: 6.33
--- a/openide.explorer/src/org/openide/explorer/view/TreeView.java Thu Nov 04 08:53:16 2010 +0100
+++ a/openide.explorer/src/org/openide/explorer/view/TreeView.java Thu Nov 04 09:44:33 2010 +0100
@@ -228,6 +228,10 @@
transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
+ /** Quick Search support */
+ transient private boolean allowedQuickSearch = true;
+ transient private KeyAdapter quickSearchKeyAdapter = null;
+
/**
* Whether the quick search uses prefix or substring.
* Defaults to false meaning prefix is used.
@@ -452,6 +456,37 @@
}
/**
+ * Get whether the quick search feature enable or not.
+ * Defaults enable (false).
+ * @since 6.33
+ * @return true if quick search feature enabled, false
+ * otherwise.
+ */
+ public boolean isQuickSearchAllowed() {
+ return allowedQuickSearch;
+ }
+
+ /**
+ * Set whether the quick search feature enable or not.
+ * Defaults enable (false).
+ * @since 6.33
+ * @param allowedQuickSearch true
if quick search need to enable
+ */
+ public void setQuickSearchAllowed(boolean allowedQuickSearch) {
+ this.allowedQuickSearch = allowedQuickSearch;
+
+ if(quickSearchKeyAdapter !=null && tree !=null ){
+ if(allowedQuickSearch){
+ tree.addKeyListener(quickSearchKeyAdapter);
+ }else{
+ removeSearchField();
+ tree.removeKeyListener(quickSearchKeyAdapter);
+ }
+ }
+ }
+
+
+ /**
* Set whether the quick search feature uses substring or prefix
* matching for the typed characters. Defaults to prefix (false).
* @since 6.11
@@ -967,7 +1002,9 @@
}
});
}
-
+
+
+
/** Synchronize the selected nodes from the manager of this Explorer.
* The default implementation does nothing.
*/
@@ -1629,7 +1666,7 @@
}
TreePath[] origSelectionPaths = null;
- private JPanel searchpanel = null;
+ JPanel searchpanel = null;
// searchTextField manages focus because it handles VK_TAB key
private JTextField searchTextField = new JTextField() {
@Override
@@ -1968,8 +2005,8 @@
removeKeyListener(keyListeners[i]);
}
- // Add new key listeners
- addKeyListener(
+ // create new key listeners
+ quickSearchKeyAdapter = (
new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
@@ -2001,7 +2038,9 @@
}
}
);
-
+ if(isQuickSearchAllowed()){
+ addKeyListener(quickSearchKeyAdapter);
+ }
// Create a the "multi-event" listener for the text field. Instead of
// adding separate instances of each needed listener, we're using a
// class which implements them all. This approach is used in order
@@ -2011,7 +2050,7 @@
searchTextField.addFocusListener(searchFieldListener);
searchTextField.getDocument().addDocumentListener(searchFieldListener);
}
-
+
private List doSearch(String prefix) {
List results = new ArrayList();
--- a/openide.explorer/test/unit/src/org/openide/explorer/view/TreeViewQuickSearchTest.java Thu Nov 04 08:53:16 2010 +0100
+++ a/openide.explorer/test/unit/src/org/openide/explorer/view/TreeViewQuickSearchTest.java Thu Nov 04 09:44:33 2010 +0100
@@ -61,6 +61,7 @@
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
+import org.openide.util.Exceptions;
/**
* Tests for the quick search feature in the treeview.
@@ -181,6 +182,103 @@
}
}
+ public void testQuickSearchEnable() throws Throwable {
+ final AbstractNode root = new AbstractNode(new Children.Array());
+ root.setName("test root");
+
+ final Node[] children = {
+ createLeaf("foo1"),
+ createLeaf("foo2"),
+ createLeaf("bar1"),
+ createLeaf("bar2"),
+ createLeaf("alpha"),
+ };
+
+ root.getChildren().add(children);
+
+ final Panel p = new Panel();
+ p.getExplorerManager().setRootContext(root);
+
+ final BeanTreeView btv = new BeanTreeView();
+ p.add(BorderLayout.CENTER, btv);
+
+
+ JFrame f = new JFrame();
+ f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
+ f.getContentPane().add(BorderLayout.CENTER, p);
+ f.pack();
+ f.setVisible(true);
+
+
+ final Exception[]problem = new Exception[1];
+ final Integer[] phase = new Integer[1];
+ phase[0] = 0;
+ class AWTTst implements Runnable {
+ public void run() {
+ try {
+ if (phase[0] == 0) {
+ btv.tree.requestFocus();
+ try {
+ p.getExplorerManager().setSelectedNodes(new Node[] { root });
+ } catch (PropertyVetoException e) {
+ fail("Unexpected PropertyVetoException from ExplorerManager.setSelectedNodes()");
+ }
+ }
+ Robot robot = new Robot();
+ Point p = btv.tree.getLocationOnScreen();
+ robot.mouseMove(p.x + 10, p.y + 10);
+ robot.mousePress(0);
+ robot.mouseRelease(0);
+ robot.keyPress(KeyEvent.VK_A);
+
+ if(phase[0] != 0)
+ {
+ boolean panelUsed = btv.searchpanel !=null;
+
+ if(btv.isQuickSearchAllowed()){
+ assertTrue("Quick Search enabled ", panelUsed);
+ }else{
+ assertFalse("Quick Search disable", panelUsed);
+ }
+ }
+
+
+ } catch (AWTException ex) {
+ problem[0] = ex;
+ }
+ }
+ }
+ AWTTst awt = new AWTTst();
+ try {
+ SwingUtilities.invokeAndWait(awt);
+ } catch (InvocationTargetException ex) {
+ throw ex.getTargetException();
+ }
+ if (problem[0] != null) {
+ throw problem[0];
+ }
+ Thread.sleep(1000);
+ phase[0] = 1;
+ btv.setQuickSearchAllowed(true);
+ try {
+ SwingUtilities.invokeAndWait(awt);
+ } catch (InvocationTargetException ex) {
+ throw ex.getTargetException();
+ }
+ if (problem[0] != null) {
+ throw problem[0];
+ }
+
+ Thread.sleep(1000);
+ btv.setQuickSearchAllowed(false);
+ try {
+ SwingUtilities.invokeAndWait(awt);
+ } catch (InvocationTargetException ex) {
+ throw ex.getTargetException();
+ }
+
+ }
+
private static Node createLeaf(String name) {
AbstractNode n = new AbstractNode(Children.LEAF);
n.setName(name);