* @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 = "";
}
if (item != null) {
- explorer.select(item);
explorer.show(item);
+ explorer.select(item);
}
// without this the default handling would take over.
e.doit = false;
*/
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;
}
}
protected void setColumnWidths(Scrollable tree, int[] widths) {
+ // NatTable HiDPI workaround
+ double displayScale = NatTableGraphExplorer.getDisplayScale();
+ if (displayScale != 1.0) {
+ for (int i=0; i < widths.length; i++) {
+ widths[i] = (int)Math.floor(((double)widths[i]/ displayScale));
+ }
+ }
for (int i=0; i < widths.length; i++) {
columnHeaderDataProvider.getDataLayer().setColumnWidthByPosition(i, widths[i]);
}
final ExecutorService queryUpdateScheduler = Threads.getExecutor();
- private double getDisplayScale() {
+ public static double getDisplayScale() {
Point dpi = Display.getCurrent().getDPI();
return (double)dpi.x/96.0;
}
private void setSelectionExternal(List<RowSelectionItem> items) {
selectionLayer.clear(true);
for (RowSelectionItem item : items) {
- for (int c : item.columnIndex)
- selectionLayer.selectCell(c, item.rowIndex, false, true);
+ for (int c : item.columnIndex) {
+ int r = selectionLayer.getRowPositionByIndex(item.rowIndex);
+ selectionLayer.selectCell(c, r, false, true);
+ }
}
selection = new StructuredSelection(items);
fireEvents();
initData();
if (labeler != null) {
String key = explorerContext.getGe().getColumns()[column].getKey();
- String s = null;
- if (runtimeLabels != null)
- s = runtimeLabels.get(key);
- if (s == null)
- s = labels.get(key);
- if (labelDecorators != null && !labelDecorators.isEmpty()) {
- int index = 0;
- for (LabelDecorator ld : labelDecorators) {
- String ds = ld.decorateLabel(s, key, index);
- if (ds != null)
- s = ds;
- }
+ return getValue(key);
+ }
+ return null;
+ }
+
+ private String getValue(String key) {
+ String s = null;
+ if (runtimeLabels != null)
+ s = runtimeLabels.get(key);
+ if (s == null)
+ s = labels.get(key);
+ if (labelDecorators != null && !labelDecorators.isEmpty()) {
+ int index = 0;
+ for (LabelDecorator ld : labelDecorators) {
+ String ds = ld.decorateLabel(s, key, index);
+ if (ds != null)
+ s = ds;
}
- return s;
+ }
+ return s;
+ }
+
+ public String getValueString(String key) {
+ if (labels == null)
+ initData();
+ if (labeler != null) {
+ return getValue(key);
}
return null;
}