CheckboxTableViewer第一列全选 [英] CheckboxTableViewer first column select all
问题描述
我目前正在开发一个向导,它将引导我完成几个步骤。
在其中一个WizardPages上,我希望有一个动态填充的表,用户可以在其中选择一些行。
我为此使用CheckboxTableViewer。
当前运行良好(包括动态列数等)
,结果如屏幕截图所示。
I am currently developing a Wizard that will take me through a couple of steps. On one of the WizardPages I want to have a dynamically filled table where the user selects some of the rows. I am using a CheckboxTableViewer for this. Currently it works well (including dynamic number of columns, etc.) and the result looks like in the screenshot.
我的问题是第一列跨越带有复选框的列。我想具有以下行为:
My problem with this is that the first column spans over the column with the checkboxes. I would like to have the following behaviour:
- 第一列标题(屏幕截图中的 nodeAlias)应从该列顶部开始,而不是复选框上方(因此需要向右移动一点)
- 我想在复选框上方的标题中具有一个复选框,以执行全选/取消全选
我在向导页面(扩展WizardPage
)中使用的代码看起来像这样:
My code that I am using in my wizard page (extends WizardPage
) looks like this:
public class ShowResults extends WizardPage {
private Table table;
public ShowResults() {
super("wizardPage");
setTitle("Title");
setDescription("Description");
}
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
container.setLayout(new GridLayout(1, false));
CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(container, SWT.BORDER | SWT.FULL_SELECTION);
createColumns(checkboxTableViewer);
table = checkboxTableViewer.getTable();
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
table.setHeaderVisible(true);
table.setLinesVisible(true);
checkboxTableViewer.setContentProvider(ArrayContentProvider.getInstance());
checkboxTableViewer.setInput(getData()); // returns a list of Record-Objects
}
private void createColumns(CheckboxTableViewer checkboxTableViewer) {
// get the required columns as list and act for each
for(String columnName : getColumnNames()){
// create a column for the first name
TableViewerColumn colFirstName = new TableViewerColumn(checkboxTableViewer, SWT.NONE);
colFirstName.getColumn().setWidth(150);
colFirstName.getColumn().setText(columnName);
colFirstName.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Record r = (Record) element;
return r.getValue(columnName);
}
});
}
}
我没有加入此课程记录
的定义,因为无论如何显示信息仍然有效。 (我想这对这个问题并不重要。)
I've not included the class definition for the Record
as the displaying of information works anyway. (I guess it is not of importance for this problem).
推荐答案
为什么不看看星云网格小部件?您可以为列标题编写自己的CellRenderers。参见此处
Why not take a look at Nebula grid widget? you can write your own CellRenderers for the column headers. See here
这篇关于CheckboxTableViewer第一列全选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!