简体   繁体   English

如何在SWT表中隐藏/删除列

[英]How to hide/delete column in SWT table

Which approach to use to have ability to hide/delete columns in the table in SWT (in Eclipse plugin in particular)? 使用哪种方法来隐藏/删除SWT中的列(特别是在Eclipse插件中)?

  1. A cannot transfer this functionality to rows, since I need insert and hide(or delete) of both rows and columns. A无法将此功能传输到行,因为我需要插入和隐藏(或删除)行和列。
  2. I tried to delete them with TableColumn.dispose(), but according ColumnWeightData in the layout was not deleted and resetting the whole table layout with new TableLayout did not delete information about the columns from the layout. 我试图用TableColumn.dispose()删除它们,但是根据布局中的ColumnWeightData没有被删除,并且使用新的TableLayout重置整个表格布局没有从布局中删除有关列的信息。
  3. I tried to create all the needed columns, and hide with setWidth(0) those that should be hidden/deleted. 我尝试创建所有需要的列,并使用setWidth(0)隐藏应隐藏/删除的列。 The sample code that I written is here . 我写的示例代码在这里 This approach is not good: 3.1. 这种方法并不好:3.1。 It does not scale. 它不会扩展。 In my case the maximum quantity of columns may be several thousand with only few really needed by the user. 在我的情况下,列的最大数量可能是几千,用户实际上只需要很少。 3.2. 3.2。 Dealing with resizing is really a hell. 处理大小调整真的是一个地狱。 AFAIU, even after setResizable(false) column may be resized if the parent component is resized. 即使在setResizable(false)列之后,如果调整父组件的大小,也可以调整AFAIU的大小。 To deal with it I need to write huge listeners for parent component. 为了解决这个问题,我需要为父组件编写大量的监听器。 I didn't try yet. 我还没试过。

So should I 我也应该这样

  1. Investigate disposing table columns further and use it? 调查进一步处理表格列并使用它?
  2. Stack with setWidth(0) for a while, as I have not met scaling issues yet? 使用setWidth(0)堆栈一段时间,因为我还没有遇到扩展问题吗?
  3. Look in the direction of some third-party table components (Nattable...)? 看一下第三方表组件的方向(Nattable ......)? - If yes, preferably open-source, as my Eclipse-plugin is open-source. - 如果是,最好是开源的,因为我的Eclipse插件是开源的。

We do that on many of our tables here. 我们在这里的许多表格上都是这样做的。

First, we make sure the user does not see what we're doing. 首先,我们确保用户不会看到我们正在做的事情。

table.setRedraw( false );

Then we remove all columns. 然后我们删除所有列。

while ( table.getColumnCount() > 0 ) {
    table.getColumns()[ 0 ].dispose();
}

And then we add the needed ones. 然后我们添加所需的那些。

ArrayList<Column> columns = getShownColumns();

for ( Column column : columns ) {
    TableColumn tableColumn = new TableColumn( table, column.getStyle() );
    tableColumn.setText( column.getTitle() );
    tableColumn.setWidth( column.getWidth() );
}

And finally we let the user see what we did. 最后,我们让用户看到我们做了什么。

table.setRedraw( true );

I'd recreate the table columns each time with the visible columns only. 我每次只使用可见列重新创建表列。 If you use the SWT.VIRTUAL style bit, this will be reasonably fast. 如果使用SWT.VIRTUAL样式位,则速度相当快。 Set table.setRedraw(false) , remove the data from your Table, dispose all TableColumns, recreate the neccessary ones and set your data again. 设置table.setRedraw(false) ,从表中删除数据,处理所有TableColumns,重新创建必要的数据并重新设置数据。 Then set table.setRedraw(true) . 然后设置table.setRedraw(true) This minimizes flickering. 这最大限度地减少了闪烁。

I did all this, it worked fine, the disposal of the TableColumns worked as expected. 我做了所有这些,它工作正常,TableColumns的处理按预期工作。

Using SWT.VIRTUAL is not for the faint-hearted, though. 但是,使用SWT.VIRTUAL不适合胆小的人。 It implicates a different handling of your Table. 它暗示了对表的不同处理。 You might try without that first, to see if it is fast enough. 你可以先试试,看看它是否足够快。

Having a table with thousands of columns and only showing a few to the user sounds very strange to me. 拥有一个包含数千列的表格,只向用户显示一些内容对我来说非常奇怪。 With the native Table implementations I expect issues with that. 使用本机Table实现,我预计会遇到问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM