0

我编辑了一个 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;
}
}

在此处输入图像描述

4

1 回答 1

1

该问题与DefaultEditConfigurationViewportLayer. 这样做将导致在按键上识别的编辑器相对于正文层堆栈而不是GridLayer. 应用的默认配置GridLayer已经包含必要的编辑配置。但是您通过GridLayer构造函数中的最后一个参数禁用了它。

简而言之,从您的示例中删除以下两行,它们仅在没有GridLayer.

viewportLayer.addConfiguration(new DefaultEditConfiguration());
viewportLayer.addConfiguration(new DefaultEditBindings());

并将创建的更改GridLayer为此

GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);

并且作为提示,在不理解它们的目的时从不同示例中复制代码时要小心。NatTable 示例通常包含代码解释以更详细地解释它们。

于 2017-10-30T17:36:09.950 回答