0

I'm trying to learn how to enable cell editing in Nebula NatTable. I edited _301_CustomDataProviderExample::createExampleControl to show this feature:

@Override
public Control createExampleControl(Composite parent) {
    //...
    final NatTable natTable = new NatTable(parent, SWT.NO_BACKGROUND
                | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, bodyDataLayer, false);

    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());

    natTable.addConfiguration(new AbstractRegistryConfiguration() {
        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(
                    EditConfigAttributes.CELL_EDITABLE_RULE,
                    IEditableRule.ALWAYS_EDITABLE);
        }
    });

    natTable.configure();

    return natTable;
}

But when run the example, I cannot edit the cells. What am I missing? Thanks!

Update: my solution for this case is:

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

Note: don't add those configurations to natTable cause of java.lang.ClassCastException: org.eclipse.nebula.widgets.nattable.NatTable cannot be cast to org.eclipse.nebula.widgets.nattable.layer.AbstractLayer

4

1 回答 1

0

You are missing the necessary edit related configurations DefaultEditBindings and DefaultEditConfiguration, which will configure the editors and the bindings to react on user interaction.

This is explained in the documentation: https://www.eclipse.org/nattable/documentation.php?page=editing

于 2017-10-10T09:06:06.527 回答