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 的第二步一样)

  • 相关阅读:
    采用[ICONIX] 方法实践BLOG设计之二 [用例建模]
    Java平台AOP技术研究
    AOP技术基础
    使用 Windows Vista 的凭据提供程序创造自定义的登录体验
    采用[ICONIX] 方法实践BLOG设计之一 [问题域建模]
    软件工程知识体系全景图
    .Net平台AOP技术研究
    采用[ICONIX] 方法实践BLOG设计之四 [健壮性分析]
    采用[ICONIX] 方法实践BLOG设计之三 [需求复核]
    AOP——引言
  • 原文地址:https://www.cnblogs.com/wenchunl/p/8608461.html
Copyright © 2011-2022 走看看