【问题标题】:How to implement text wrapping in group by column header layer in nattable如何在 nattable 中按列标题层分组实现文本换行
【发布时间】:2021-04-13 21:32:16
【问题描述】:

我想在标题标题中实现文本换行。我还在顶部列标题层添加了逐层分组 文本换行在以下配置的标题区域中不起作用。如何在这种情况下实现文本换行

// Column header layer
this.colGrpModel = new ColumnGroupModel();

this.colHeaderLayr =
    new ColumnHeaderLayer(this.colHeaderDataLayr, this.bodyLayr, this.bodyLayr.getSelectionLayer());

this.colGrpHeaderLayer =
    new ColumnGroupHeaderLayer(this.colHeaderLayr, 
this.bodyLayr.getSelectionLayer(), this.colGrpModel, false);

this.colGrpHeaderLayer.setCalculateHeight(true);

// Composite layer
CompositeLayer compositeGridLayer = new CompositeLayer(1, 2);

//Group by header layer
this.groupByHeaderLayer = new GroupByHeaderLayer(groupByModel, this.paramFilterGridLayer,
this.filterGridLayer.getColumnHeaderDataProvider());   

compositeGridLayer.setChildLayer(GroupByHeaderLayer.GROUP_BY_REGION, this.groupByHeaderLayer, 0, 0);

compositeGridLayer.setChildLayer("Grid", this.filterGridLayer, 0, 1);

这是 groupBy 配置:

configRegstry.registerConfigAttribute(
    GroupByConfigAttributes.GROUP_BY_CHILD_COUNT_PATTERN, "[{0}] - ({1})");

configRegstry.registerConfigAttribute(
    GroupByConfigAttributes.GROUP_BY_HINT, "Drag columns here");

// To implement text wrapping in  group by header region  
configRegstry.registerConfigAttribute(
    CellConfigAttributes.CELL_PAINTER, 
    new TextPainter(true, true, 2), 
    DisplayMode.NORMAL, 
    GroupByHeaderLayer.GROUP_BY_REGION);

【问题讨论】:

    标签: eclipse eclipse-rcp nattable nebula


    【解决方案1】:

    简答:目前不支持。

    长答案: 您误解了几件事。

    1. 文本换行意味着如果单元格中没有足够的空间,则会动态添加新行。由于GroupByHeader 实际上是一个跨越整个宽度的单元格,因此单元格宽度永远不会超过强制文本换行。
    2. TextPainterICellPainter,所以它用于渲染单元格。
    3. GroupByHeader(尽管是跨单元格)不使用默认的单元格绘制器。它使用特殊的GroupByHeaderPainter,因为它需要检查GroupByModel并为每个条目呈现片段。该画家目前不支持换行。而且它内部不使用其他ICellPainter

    这意味着,如果您需要在GroupByHeader 中支持换行,您需要扩展GroupByHeaderPainter。作为一个开源项目,我们喜欢贡献。 :)

    如果您想在GroupByHeader 中添加某种文本换行,您需要指定何时应该换行文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-18
      • 2021-04-30
      • 2013-12-16
      • 1970-01-01
      • 2021-02-19
      • 2016-12-02
      • 1970-01-01
      • 2011-10-10
      相关资源
      最近更新 更多