在NatTable中折叠/扩展列组时,有没有办法自动调整百分比列的大小

时间:2019-01-31 12:42:36

标签: eclipse nattable

我在nattable版本1.6中找到了ResizeColumnHideShowLayer类。 (约https://bugs.eclipse.org/bugs/show_bug.cgi?id=521486

这仅适用于普通列标题。 但是,如果我折叠列组,则无法调整大小以适合窗口。 (不增加列大小)

我该如何解决问题? 有没有办法调整其他列的大小以适合窗口自动增加?

谢谢。

2 个答案:

答案 0 :(得分:0)

当前不是因为ColumnGroupExpandCollapseLayer负责隐藏折叠列。

答案 1 :(得分:-1)

我自己找到了解决方法!
它工作得很好。 :-)
我基于NatTable v1.6版本运行。(昨天下载)

我认为这是一项基本功能,因此希望该功能将包含在下一个NatTable版本中。
在狭窄的表中,折叠列组的行为意味着可能是某人想要更广泛地查看其他列数据。

概述(问题屏幕和已解决屏幕)

我解释了使用两个应用程序(之前,之后)的屏幕截图。
如果您想一次轻松地了解我的问题,请参考下图。

问题屏幕

enter image description here


屏幕改进

enter image description here


解决方案摘要:

  1. 将事件侦听器添加到ColumnGroupExpandCollapseLayer。
    (HideColumnPositionsEvent,ShowColumnPositionsEvent)
  2. 处理上述事件。
    获取被折叠隐藏的列索引
    用索引执行MultiColumnHideCommand

我的测试代码的层结构

↑ ViewportLayer (top layer)
| SelectionLayer
| ColumnGroupExpandCollapseLayer
| ResizeColumnHideShowLayer
| ColumnGroupReorderLayer
| ColumnReorderLayer
| DataLayer (base layer)

实现代码如下:

void method() {
    ...
    columnGroupExpandCollapseLayer.addLayerListener(new ILayerListener() {
        @Override
        public void handleLayerEvent(ILayerEvent event) {
            boolean doRedraw = false;

            //It works for HideColumnPositionsEvent and ShowColumnPositionsEvent 
            // triggered by ColumnGroupExpandCollapseCommandHandler
            if (event instanceof HideColumnPositionsEvent) {
                HideColumnPositionsEvent hideEvent = (HideColumnPositionsEvent)event;

                Collection<Range> columnPositionRanges = hideEvent.getColumnPositionRanges();
                Collection<Integer> convertIntegerCollection = convertIntegerCollection(columnPositionRanges);
                int[] positions = convertIntPrimitiveArray(convertIntegerCollection);

                //Execute command to hide columns that was hidden by collapsed column group.
                MultiColumnHideCommand multiColumnHideCommand = new MultiColumnHideCommand(resizeColumnHideShowLayer, positions);
                resizeColumnHideShowLayer.doCommand(multiColumnHideCommand);

                doRedraw = true;

            }else if (event instanceof ShowColumnPositionsEvent) {//called by  ColumnGroupCollapsedCollapseCommandHandler
                ShowColumnPositionsEvent showEvent = (ShowColumnPositionsEvent)event;
                Collection<Range> columnPositionRanges = showEvent.getColumnPositionRanges();
                Collection<Integer> positions  = convertIntegerCollection(columnPositionRanges);

                //Execute command to show columns that was hidden by expanded column group.
                MultiColumnShowCommand multiColumnShowCommand = new MultiColumnShowCommand(positions);
                resizeColumnHideShowLayer.doCommand(multiColumnShowCommand);

                //Set whether or not to redraw table
                doRedraw = true;
            }
            if (doRedraw) {
                natTable.redraw();
            }
        }

        /**
         * Merge position values within several Ranges to Integer collection
         */
        private Collection<Integer> convertIntegerCollection(Collection<Range> rangeCollection) {

            Iterator<Range> rangeIterator = rangeCollection.iterator();
            Set<Integer> mergedPositionSet = new HashSet<Integer>();
            while (rangeIterator.hasNext()) {
                Range range = rangeIterator.next();
                mergedPositionSet.addAll(range.getMembers());
            }
            return mergedPositionSet;
        }
        /**
         * Convert Integer wrapper object to primitive value
         */
        private int [] convertIntPrimitiveArray(Collection<Integer> integerCollection) {
            Integer [] integers = (Integer [])integerCollection.toArray(new Integer[integerCollection.size()]);
            int [] positionPrimitives = new int[integers.length];               
            for (int i = 0 ; i < integers.length ; i++) {
                positionPrimitives[i] = integers[i].intValue();
            }
            return positionPrimitives;
        }
        });
}