X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FKeyToSelectionAdapter.java;fp=bundles%2Forg.simantics.browsing.ui.nattable%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fnattable%2FKeyToSelectionAdapter.java;h=9ededd52f1ac78d4cda87fcfbce1cea202ea3089;hp=7e0202be37974204df55852aa43406b18773eaf7;hb=bbfae087089fa3126eefb18207fde0cfaa7315a3;hpb=e3cd3cd49bc2585f57d030a8743f9012f6161a92 diff --git a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java index 7e0202be3..9ededd52f 100644 --- a/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java +++ b/bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java @@ -35,20 +35,27 @@ public class KeyToSelectionAdapter extends KeyAdapter { * @param explorer */ public KeyToSelectionAdapter(GraphExplorer explorer) { + this(explorer,"\\p{Alnum}"); + } + + public KeyToSelectionAdapter(GraphExplorer explorer, String pattern) { assert explorer != null; this.explorer = (NatTableGraphExplorer)explorer; - this.alphaNum = Pattern.compile("\\p{Alnum}"); + this.alphaNum = Pattern.compile(pattern); } - + + public boolean acceptKey(char key) { + return alphaNum.matcher(Character.toString(key)).matches(); + } + @Override public void keyPressed(KeyEvent e) { if (explorer.isDisposed()) return; - - if (!alphaNum.matcher(Character.toString(e.character)).matches()) - return; + if (!acceptKey(e.character)) + return; // concatenate / replace matcher. if ((e.time - prevEvent) > KEY_INPUT_DELAY ) matcher = ""; @@ -70,8 +77,8 @@ public class KeyToSelectionAdapter extends KeyAdapter { } if (item != null) { - explorer.select(item); explorer.show(item); + explorer.select(item); } // without this the default handling would take over. e.doit = false; @@ -144,6 +151,8 @@ public class KeyToSelectionAdapter extends KeyAdapter { */ protected boolean matchesColumn(TreeNode item, int column, String matcher) { String text = item.getValueString(column); + if (text == null) + return false; if (text.toLowerCase().startsWith(matcher)) { return true; }