1、根据每一行的对象动态显示ComboBoxCellEditor列表中的数据
在继承ICellModifier的类中的canModify()方法中添加
public boolean canModify(Object element, String property) {
//设置同一列的不同行中的下拉列表的内容不同
//BusinessField 是一个实体类
BusinessField o = (BusinessField) element;
String[] items=o.getFieldAttributes();
//tv.getCellEditors()[1]是一个ComboBoxCellEditor
tv.getCellEditors()[1]=new ComboBoxCellEditor(tv.getTable(), items, SWT.READ_ONLY);
return true;
}
2、访问TableViewer中绑定的每一个对象
TableItem[] children = tv.getTable().getItems();
for (int i = 0; i < children.length; i++) {
TableItem item = children[i];
if(item.getData() instanceof BusinessField){
BusinessField bf = (BusinessField)item.getData();
............
}
3、CellEditor为CheckboxCellEditor时如何显示CheckBox
修改前
修改后
在LabelProvider里根据属性值True/False显示不同的图片即可(,)(鼠标右键另存为可下载).
public Image getColumnImage(Object element, int columnIndex) {
if(element instanceof BusinessField){
BusinessField bf = (BusinessField)element;
switch(columnIndex){
case 0:
String imageStr0="";
if(bf.getIsSelected())
imageStr0 = "icons/checked.gif";
else
imageStr0 = "icons/unchecked.gif";
return AbstractUIPlugin.imageDescriptorFromPlugin("your plugin name", imageStr0).createImage();
default:
return null;
}
}
return null;
}