我编辑了一个星云示例(_301_CustomDataProviderExample)来按Tab键测试单元格编辑功能(按Tab键启用下一个单元格编辑)。我使用GridLayer时出现问题:单元格编辑器显示不正确。我认为这是因为行和列标题,但我不知道如何调试或修复。你能帮助我或给我一些提示吗?这是我编辑或添加的代码:
@Override
public Control createExampleControl(Composite parent) {
String[][] testData = new String[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
testData[i][j] = "" + i + "/" + j;
}
}
IDataProvider bodyDataProvider = new TwoDimensionalArrayDataProvider(testData);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new DefaultEditBindings());
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider, 40, DataLayer.DEFAULT_ROW_HEIGHT);
rowHeaderDataLayer.setColumnsResizableByDefault(true);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
IDataProvider columnHeaderDataProvider = new LetterColumnHeaderDataProvider(20);
ILayer columnHeaderLayer = new ColumnHeaderLayer(
new DefaultColumnHeaderDataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
IDataProvider conerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
ILayer cornerLayer = new CornerLayer(new DataLayer(conerDataProvider), rowHeaderLayer, columnHeaderLayer);
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer, false);
final NatTable natTable = new NatTable(parent, false);
natTable.setLayer(/* viewportLayer */ gridLayer);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
super.configureRegistry(configRegistry);
configRegistry.registerConfigAttribute(
EditConfigAttributes.CELL_EDITABLE_RULE,
IEditableRule.ALWAYS_EDITABLE);
}
});
natTable.configure();
return natTable;
}
补充:
class LetterColumnHeaderDataProvider implements IDataProvider {
private int columns = 0;
public LetterColumnHeaderDataProvider(int columns) {
this.columns = columns;
}
@Override
public Object getDataValue(int columnIndex, int rowIndex) {
return (char) ('A' + columnIndex);
// TODO: support column header AA-AZ, ZA-ZZ, ZZZ...
}
@Override
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
throw new UnsupportedOperationException();
}
@Override
public int getColumnCount() {
return this.columns;
}
@Override
public int getRowCount() {
return 1;
}
}
答案 0 :(得分:1)
此问题与在DefaultEditConfiguration
上注册ViewportLayer
有关。执行此操作将导致在按键上标识的编辑器相对于主体图层堆栈而不是GridLayer
。使用GridLayer
应用的默认配置已包含必要的编辑配置。但是你通过GridLayer
构造函数中的最后一个参数禁用了它。
简而言之,从示例中删除以下两行,只有在没有GridLayer
的合成时才需要它们。
viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new DefaultEditBindings());
并将GridLayer
的创建更改为此
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
作为一个提示,在不理解其目的的情况下复制来自不同示例的代码时要小心。 NatTable示例通常包含代码中的解释,以便更详细地解释它们。