]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.nattable/src/org/simantics/browsing/ui/nattable/KeyToSelectionAdapter.java
Fix column width issues on HiDPI displays. KeyTiSelection fixes.
[simantics/platform.git] / bundles / org.simantics.browsing.ui.nattable / src / org / simantics / browsing / ui / nattable / KeyToSelectionAdapter.java
index 7e0202be37974204df55852aa43406b18773eaf7..9ededd52f1ac78d4cda87fcfbce1cea202ea3089 100644 (file)
@@ -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;
                }