zoukankan      html  css  js  c++  java
  • Nattable 为特定列的不同值添加不同Label的两种方法

    Option 1:

    第一步: 实例化一个CellOverrideLabelAccumulator 对象, 调用registerOverride 方法。

    代码示例:

    CellOverrideLabelAccumulator<youRow> cellLabelAccumulator = new CellOverrideLabelAccumulator<>(bodyDataProvider);
    cellLabelAccumulator.registerOverride(value1, 1, label1);  // the second parameter is the column position, 1 means the second column
    cellLabelAccumulator.registerOverride(value2, 1, label2);
    bodyDataLayer.setConfigLabelAccumulator(cellLabelAccumulator);

    第二步: 实例化一个configuration, 并添加到Nattable 实例。

    class YourConfiguration extends AbstractRegistryConfiguration {
    
            @Override
            public void configureRegistry(IConfigRegistry configRegistry) {
                 // Your custom registry code here , should involve the label defined in Step 1
            }
    
    }
    
    YourConfiguration yourConfiguration = new YourConfiguration();
    natTable.addConfiguration(yourConfiguration); 

    Option 2:

    第一步: 从CellOverrideLabelAccumulator 派生出一个自定义的子类,重写accumulateConfigLabels 方法

    class YourLabelAccumalator extends CellOverrideLabelAccumulator<YourRow> {
            private ListDataProvider<YourRow> thisDataProvider;
    
            public YourLabelAccumalator(ListDataProvider<YourRow> dataProvider) {
                super(dataProvider);
                thisDataProvider = dataProvider;
            }
    
            @Override
            public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
                
                // should check the column position first
                if (columnPosition == 1) {
                    Object value=  this.thisDataProvider.getDataValue(1, rowPosition);
                    
                    if (value== value1) {
                        configLabels.addLabel(label1);  // should defined label1 as String
                    } else if (value== value2) {
                        configLabels.addLabel(label2); //  same as above
                    }
                }
                
            }
        }
    

    第二步: 实例化一个configuration, 并添加到Nattable 实例 (同Option 1 的第二步一样)

  • 相关阅读:
    logback 范例
    mysql中int、bigint、smallint 和 tinyint的区别详细介绍
    MySQL中视图和普通表的区别
    Linux 下升级JDK 1.7到1.8
    本人遇到的spring事务之UnexpectedRollbackException异常解决笔记
    Spring 调度任务@scheduled学习总结
    javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint
    spring中的scope详解
    Spring Boot 静态资源处理
    用人所长
  • 原文地址:https://www.cnblogs.com/wenchunl/p/8608461.html
Copyright © 2011-2022 走看看