2016-07-05 194 views
0

我有一个由两列构成的表,其中包含第一列中的复选框和第二列中的ComboBoxCellEditor。当我在ComboBox中选择某个对象时,相应行状态的复选框应该更改为checked。根据RCP中的ComboBoxCellEditor选择更改复选框选择

tabViewer = new TableViewer(innerTopComp, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CHECK); 

而对于ComboBoxCellEditor我已经创建了一个扩展EditingSupport类。

public class ComboEditing extends EditingSupport { 

private ComboBoxCellEditor cellEditor; 

private String[] comboDataArr; 
public ComboEditing(final TableViewer viewer, String[] ComboDataArr) { 
    super(viewer); 
    this.comboDataArr = ComboDataArr; 
    this.cellEditor = new ComboBoxCellEditor(((TableViewer)viewer).getTable(), this.comboDataArr, SWT.DROP_DOWN); 
} 

@Override 
protected CellEditor getCellEditor(Object element) { 
    // TODO Auto-generated method stub 
    return cellEditor; 
} 

@Override 
protected boolean canEdit(Object element) { 
    // TODO Auto-generated method stub 
    return true; 
} 

@Override 
protected Object getValue(Object element) { 
    // TODO Auto-generated method stub 
    return 0; 
} 

@Override 
protected void setValue(Object element, Object value) { 
    // TODO Auto-generated method stub 
    if((element instanceof TableData) && (value instanceof Integer)) { 
     Integer choice = (Integer)value; 
     String option = comboDataArr[choice]; 
     ((TableData)element).setMatches(option); 
     getViewer().update(element, null); 

    } 
} 

}

如何确认与该行的组合框,当某事在ComboBox选中该复选框。

+0

你就不能做到这一点的''EditingSupport'方法setValue'? –

+0

我将如何获取setValue方法中的相应复选框? – user387600

+1

我认为你需要更清楚地解释你有什么以及你想做什么。 –

回答

0

对于使用SWT.CHECK的表,您应该使用CheckboxTableViewer,因为它提供了许多用于处理复选框的方法。

CheckboxTableViewer tabViewer = CheckboxTableViewer.newCheckList(innerTopComp, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL); 

CheckboxTableViewer延伸TableViewer所以现有的代码仍然会确定。

然后,您可以使用setChecked方法在EditingSupportsetValue方法:

CheckboxTableViewer viewer = (CheckboxTableViewer)getViewer(); 

viewer.setChecked(element, ... true or false);