在我的主dailog中,我有一个JFace TableViewer。表的最后一列是ComboBoxCellEditor。他们可以选择不,是的,两者都有。这一切都是按照设计进行的。
但这是我的问题。
表例
从-
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);
}
}
} 发布于 2012-10-12 09:31:24
就我理解您的问题而言,您希望复制一个对象,将其添加到您的模型中,并刷新查看器。
当用户在组合框中选择"both"时,所有这些都应该发生。你已经知道了,当这种事发生的时候。您将在else情况下结束您的setValue方法。然后你可以在那里做你必须做的事:
protected void setValue(Object element, Object value)
{
if((element instanceof AplotDatasetData) && (value instanceof Integer)) {
Integer choice = (Integer)value;
String option = ((AplotDatasetData)element).getMarkupValue();
if(choice == 0) {
option = "No";
}
else if(choice == 1) {
option = "Yes";
}
else {
option = "Both";
// create a copy of your element
// add it to your model
// update the viewer
}
getViewer().update(element, null);
}
}https://stackoverflow.com/questions/12847374
复制相似问题