1
在我的主dailog中,我有一個JFace TableViewer。該表的最後一列是ComboBoxCellEditor。他們可以選擇否,是的,兩者。這一切都按設計工作。SWT - 在我的TableViewer中使用EditingSupport
但這是我的問題。
- 如果用戶選擇Both作爲值。
- 我需要運行將從陣列
- 變化來自於無
- 值獲取當前行數據的方法,使數據的副本,然後將值更改爲Yes
- 加兩回到Array
- 刷新表
表範例
從 -
1002 | 001 | sss | part | both(user changed from default)
要 -
1002 | 001 | sss | part | No
1002 | 001 | sss | part | Yes
我想弄清楚這兩個選擇後如何運行做休息的方法。我假設它必須是某種傾聽者。請看看我的EditingSupport代碼,並告訴我在哪裏開始我的方法來完成剩下的工作。
public class OptionEditingSupport extends EditingSupport
{
private ComboBoxCellEditor cellEditor;
public OptionEditingSupport(ColumnViewer viewer) {
super(viewer);
cellEditor = new ComboBoxCellEditor(((TableViewer)viewer).getTable(), new String[]{"No", "Yes", "Both"}, SWT.DROP_DOWN);
//cellEditor.setValue(0);
}
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
protected boolean canEdit(Object element) {
return true;
}
protected Object getValue(Object element) {
return 0;
}
protected void setValue(Object element, Object value)
{
if((element instanceof AplotDatasetData) && (value instanceof Integer)) {
Integer choice = (Integer)value;
//String option = (choice == 0? "Yes":"No":"Both");
String option = ((AplotDatasetData)element).getMarkupValue();;
if(choice == 0) {
option = "No";
}
else if(choice == 1) {
option = "Yes";
}
else {
option = "Both";
}
((AplotDatasetData)element).setMarkupValue(option);
getViewer().update(element, null);
}
}
}
現在你明白地指出了這一點。巴茲非常感謝你的幫助。我從你的建議和解釋中學到了很多東西 – jkteater
@jkteater不客氣。當我能幫忙時總是很高興。 – Baz