我编辑了一个 Nebula 示例 (_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;
}
}