--- apichanges.xml
+++ apichanges.xml
@@ -23,7 +23,20 @@
Explorer API
-
+
+
+ Added method TreeView.setUseSubstringInQuickSearch(boolean).
+
+
+
+
+ Added method setUseSubstringInQuickSearch(boolean). This
+ method allows using substring search for the typed in text in the quick
+ search feature instead of the (default) prefix search.
+
+
+
+
Added an interface and a registration slot
--- src/org/openide/explorer/view/TreeView.java
+++ src/org/openide/explorer/view/TreeView.java
@@ -191,6 +191,12 @@
transient private int allowedDragActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
transient private int allowedDropActions = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_REFERENCE;
+ /**
+ * Whether the quick search uses prefix or substring.
+ * Defaults to false meaning prefix is used.
+ */
+ transient private boolean quickSearchUsingSubstring = false;
+
/** Constructor.
*/
public TreeView() {
@@ -383,6 +389,16 @@
tree.setShowsRootHandles(!visible);
}
+ /**
+ * Set whether the quick search feature uses substring or prefix
+ * matching for the typed characters. Defaults to prefix (false).
+ * @since 6.11
+ * @param useSubstring true
if substring search is used in quick search
+ */
+ public void setUseSubstringInQuickSearch(boolean useSubstring) {
+ quickSearchUsingSubstring = useSubstring;
+ }
+
/********** Support for the Drag & Drop operations *********/
/** Drag support is enabled by default.
* @return true if dragging from the view is enabled, false
@@ -1705,12 +1721,18 @@
while (true) {
startIndex = startIndex % size;
- TreePath path = getNextMatch(prefix, startIndex, Position.Bias.Forward);
+ TreePath path = null;
+ if (quickSearchUsingSubstring) {
+ path = getNextSubstringMatch(prefix, startIndex, Position.Bias.Forward);
+ } else {
+ path = getNextMatch(prefix, startIndex, Position.Bias.Forward);
+ }
if ((path != null) && !results.contains(path)) {
startIndex = tree.getRowForPath(path);
results.add(path);
+ if (!quickSearchUsingSubstring) {
String elementName = ((VisualizerNode) path.getLastPathComponent()).getDisplayName();
// initialize prefix
@@ -1719,7 +1741,7 @@
}
maxPrefix = findMaxPrefix(maxPrefix, elementName);
-
+ }
// try next element
startIndex++;
} else {
@@ -1741,6 +1763,39 @@
}
/**
+ * Copied and adapted from JTree.getNextMatch(...).
+ */
+ private TreePath getNextSubstringMatch(
+ String substring, int startingRow, Position.Bias bias) {
+
+ int max = getRowCount();
+ if (substring == null) {
+ throw new IllegalArgumentException();
+ }
+ if (startingRow < 0 || startingRow >= max) {
+ throw new IllegalArgumentException();
+ }
+ substring = substring.toUpperCase();
+
+ // start search from the next/previous element froom the
+ // selected element
+ int increment = (bias == Position.Bias.Forward) ? 1 : -1;
+ int row = startingRow;
+ do {
+ TreePath path = getPathForRow(row);
+ String text = convertValueToText(
+ path.getLastPathComponent(), isRowSelected(row),
+ isExpanded(row), true, row, false);
+
+ if (text.toUpperCase().indexOf(substring) >= 0) {
+ return path;
+ }
+ row = (row + increment + max) % max;
+ } while (row != startingRow);
+ return null;
+ }
+
+ /**
* Adds the search field to the tree.
*/
private void displaySearchField() {
--- manifest.mf
+++ manifest.mf
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.openide.explorer
-OpenIDE-Module-Specification-Version: 6.10
+OpenIDE-Module-Specification-Version: 6.11
OpenIDE-Module-Implementation-Version: 1
OpenIDE-Module-Localizing-Bundle: org/openide/explorer/Bundle.properties