如何为 "TAB" 和 "ARROW" 键自定义 NatTable 的 table 单元格导航功能以实现 accepttable 可用性
How to custamize table cell navigation features of NatTable for "TAB" and "ARROW" keys for an acceptable usability
使用标准键盘导航 "Up"、"Down"、"Left"、"Right" 箭头键应将 "selection mode" 单元格移动到相应的方向。
毫无疑问,此功能在添加此代码后有效。
gridLayer.addConfiguration(新的 DefaultEditBindings());
gridLayer.addConfiguration(新的 DefaultEditConfiguration());
现在我想为特殊情况实现编辑绑定。
"special move cases":
移动 "selection mode" 单元格时,所有模式下的移动都应考虑以下特殊情况:
如果到达一行的最右边的单元格,并且请求向右移动,则 "selection mode" 应该移动到下一行中最左边的单元格
如果到达一行的最左边的单元格,并且请求向左移动,"selection mode" 应该移动到上一行中最右边的单元格
如果到达最后一行最右边的单元格,并且请求向右移动,"selection mode" 应该移动到第一行最左边的单元格
如果到达第一行最左边的单元格,并请求向左移动,"selection mode" 应该移动到最后一行最右边的单元格
如果到达最后一行的单元格,并请求向下移动,则 "selection mode" 应移动到右侧下一列第一行的单元格
如果到达第一行的单元格,并请求向上移动,则 "selection mode" 应移动到左侧前一列最后一行的单元格
如果到达最后一行最右边的单元格,并请求向下移动,"selection mode" 应该移动到第一行最左边的单元格
如果到达第一行最左边的单元格,并请求向上移动,"selection mode" 应该移动到最后一行最右边的单元格
如何实现这个,例子会有用吗?
// === Body layer ===
final DataLayer bodyDataLayer = new DataLayer(this.bodyDataProvider);
// add configuration tags (ConfigLabels) for body cells
bodyDataLayer.setConfigLabelAccumulator(this.configLabelAccumulator);
// remaining standard body layers
final DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
this.selectionLayer = bodyLayerStack.getSelectionLayer();
ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
final FreezeLayer freezeLayer = new FreezeLayer(this.selectionLayer);
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, bodyLayerStack.getViewportLayer(), this.selectionLayer);
final ILayer bodyLayer = compositeFreezeLayer;
// === Column header layer ===
final ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(this.columnHeaderDataProvider), bodyLayer, this.selectionLayer);
// === Row header layer ===
final ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(this.rowHeaderDataProvider), bodyLayer, this.selectionLayer);
// === Corner layer ===
final CornerLayer cornerLayer = new CornerLayer(new DataLayer(this.cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
// === Grid layer ===
final GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
// overwrite default AutoResizeColumnCommandHandler, which only supported auto-resizing of body layer columns
// gridLayer.registerCommandHandler(new GridLayerAutoResizeColumnCommandHandler(gridLayer));
gridLayer.registerCommandHandler(new AutoResizeColumnCommandHandler(gridLayer));
//鼠标选择正常
gridLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// TABLE_CYCLE_TRAVERSAL_STRATEGY
gridLayer.registerCommandHandler(
new MoveCellSelectionCommandHandler(this.selectionLayer, ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY));
// NatTable
this.natTable = new NatTable(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, gridLayer, false);
你要找的是NatTable 1.2引入的遍历策略配置。根据您的解释,您需要配置 TABLE_CYCLE
遍历策略才能满足您的要求。
NatTable 示例应用程序中提供了 SelectionTraversalExample,它应该显示您有哪些选项以及如何配置它们。
P.S。选择移动与编辑配置无关!
使用标准键盘导航 "Up"、"Down"、"Left"、"Right" 箭头键应将 "selection mode" 单元格移动到相应的方向。 毫无疑问,此功能在添加此代码后有效。
gridLayer.addConfiguration(新的 DefaultEditBindings());
gridLayer.addConfiguration(新的 DefaultEditConfiguration());
现在我想为特殊情况实现编辑绑定。 "special move cases": 移动 "selection mode" 单元格时,所有模式下的移动都应考虑以下特殊情况:
如果到达一行的最右边的单元格,并且请求向右移动,则 "selection mode" 应该移动到下一行中最左边的单元格
如果到达一行的最左边的单元格,并且请求向左移动,"selection mode" 应该移动到上一行中最右边的单元格
如果到达最后一行最右边的单元格,并且请求向右移动,"selection mode" 应该移动到第一行最左边的单元格
如果到达第一行最左边的单元格,并请求向左移动,"selection mode" 应该移动到最后一行最右边的单元格
如果到达最后一行的单元格,并请求向下移动,则 "selection mode" 应移动到右侧下一列第一行的单元格
如果到达第一行的单元格,并请求向上移动,则 "selection mode" 应移动到左侧前一列最后一行的单元格
如果到达最后一行最右边的单元格,并请求向下移动,"selection mode" 应该移动到第一行最左边的单元格
如果到达第一行最左边的单元格,并请求向上移动,"selection mode" 应该移动到最后一行最右边的单元格
如何实现这个,例子会有用吗?
// === Body layer ===
final DataLayer bodyDataLayer = new DataLayer(this.bodyDataProvider);
// add configuration tags (ConfigLabels) for body cells
bodyDataLayer.setConfigLabelAccumulator(this.configLabelAccumulator);
// remaining standard body layers
final DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
this.selectionLayer = bodyLayerStack.getSelectionLayer();
ViewportLayer viewportLayer = new ViewportLayer(this.selectionLayer);
// as the selection mouse bindings are registered for the region label
// GridRegion.BODY we need to set that region label to the viewport so
final FreezeLayer freezeLayer = new FreezeLayer(this.selectionLayer);
final CompositeFreezeLayer compositeFreezeLayer = new CompositeFreezeLayer(freezeLayer, bodyLayerStack.getViewportLayer(), this.selectionLayer);
final ILayer bodyLayer = compositeFreezeLayer;
// === Column header layer ===
final ILayer columnHeaderLayer = new ColumnHeaderLayer(new DefaultColumnHeaderDataLayer(this.columnHeaderDataProvider), bodyLayer, this.selectionLayer);
// === Row header layer ===
final ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(this.rowHeaderDataProvider), bodyLayer, this.selectionLayer);
// === Corner layer ===
final CornerLayer cornerLayer = new CornerLayer(new DataLayer(this.cornerDataProvider), rowHeaderLayer, columnHeaderLayer);
// === Grid layer ===
final GridLayer gridLayer = new GridLayer(bodyLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
// overwrite default AutoResizeColumnCommandHandler, which only supported auto-resizing of body layer columns
// gridLayer.registerCommandHandler(new GridLayerAutoResizeColumnCommandHandler(gridLayer));
gridLayer.registerCommandHandler(new AutoResizeColumnCommandHandler(gridLayer));
//鼠标选择正常 gridLayer.setRegionName(GridRegion.BODY);
// register a MoveCellSelectionCommandHandler with
// TABLE_CYCLE_TRAVERSAL_STRATEGY
gridLayer.registerCommandHandler(
new MoveCellSelectionCommandHandler(this.selectionLayer, ITraversalStrategy.TABLE_CYCLE_TRAVERSAL_STRATEGY));
// NatTable
this.natTable = new NatTable(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, gridLayer, false);
你要找的是NatTable 1.2引入的遍历策略配置。根据您的解释,您需要配置 TABLE_CYCLE
遍历策略才能满足您的要求。
NatTable 示例应用程序中提供了 SelectionTraversalExample,它应该显示您有哪些选项以及如何配置它们。
P.S。选择移动与编辑配置无关!