gpt4 book ai didi

JFace TableViewer 获取多个选定行

转载 作者:行者123 更新时间:2023-12-02 21:19:26 26 4
gpt4 key购买 nike

enter image description here

我想向选择按钮添加一个监听器,该按钮获取在 list 表查看器中选择的多行。然后它会继续检查这些框。我的问题是如何获取在表格查看器中选择的行列表?

这是该表的代码:

private void createCheckViewer(Composite parent){

tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.MULTI| SWT.BORDER | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);


if ( (GanttFrame.getListOfFunctionTasks()!= null)){

if (!(GanttFrame.getListOfFunctionTasks().isEmpty())){

// Data Rows
for (int i = 0; i < GanttFrame.getListOfFunctionTasks().size(); i++) {
tableViewer.add(GanttFrame.getListOfFunctionTasks().get(i));
GanttFrame.getListOfFunctionTasks().get(i).setCheckId(i);
}
}

}

// flow trace or function trace
String columnHeader;

if (TraceData.getFlowTraceFlag()){
columnHeader = "Flow Traces";
}else{
columnHeader = "Function Traces";
}

// define layout for the viewer
gridData = new GridData(SWT.FILL, SWT.TOP, true, false, 3, 1);
gridData.heightHint = 400;
tableViewer.getControl().setLayoutData(gridData);

tableViewer.addCheckStateListener(this.getCheckListListener());

final Table table = tableViewer.getTable();

TableLayout layout = new TableLayout();

TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.LEAD);
col.getColumn().setText(columnHeader);
layout.addColumnData(new ColumnWeightData(500));

table.setLayout(layout);
table.setHeaderVisible(true);
table.setLinesVisible(true);
}

最佳答案

用途:

IStructuredSelection selection = (IStructuredSelection)tableViewer.getSelection();

然后您可以有多种选择来处理选择:

Object [] selections = selection.toArray();

List<?> selections = selection.toList();

Iterator<?> iterator = selection.iterator();

关于JFace TableViewer 获取多个选定行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com