【问题标题】:JFace TableViewer get multiple selected rowsJFace TableViewer 获取多个选定的行
【发布时间】:2015-02-19 19:40:53
【问题描述】:

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

这是表格的代码:

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);
}

【问题讨论】:

    标签: jface tableviewer


    【解决方案1】:

    用途:

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

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

    Object [] selections = selection.toArray();
    
    List<?> selections = selection.toList();
    
    Iterator<?> iterator = selection.iterator();
    

    【讨论】:

    • IStructuredSelection selection = tableViewer.getStructuredSelection() 拥有IStructuredSelection 实例的选定对象。
    • @SelcukBozdag 仅在 Eclipse 4.5 中
    猜你喜欢
    • 2011-12-28
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多