简体   繁体   English

SWT-ComboBoxCellEditor /默认值

[英]SWT - ComboBoxCellEditor / Default Value

I would like for my ComboBoxCellEditor to be able to have 3 selections possible. 我希望ComboBoxCellEditor能够有3种选择。 Right now it only has Yes or No. I would like for it to have Yes, No, Both. 现在,它只有Yes或No。我希望它有Yes,No和Both。

Also the combobox selection values does not show up in the table unless the cell is clicked. 除非单击该单元格,否则组合框选择值也不会显示在表格中。 It is hard to tell if the table cell has a selection possible unless they click in the empty cell. 除非他们单击空单元格,否则很难判断表单元格是否有可能进行选择。 I would like it to at least show the down arrow. 我希望它至少显示向下箭头。
I have read some where that the only way you can get around this is to set a default value. 我读过一些文章,您唯一可以解决此问题的方法是设置默认值。

  1. I am not sure how to add the 3rd value. 我不确定如何添加第三个值。 I will add my code trying to add the 3rd value 我将添加代码以尝试添加第三个值

  2. How can a get the combobox show up in the table without the cell having to be clicked first? 如何在不首先单击单元格的情况下将组合框显示在表中?

.

public class OptionEditingSupport extends EditingSupport {

    private ComboBoxCellEditor cellEditor;

    public OptionEditingSupport(ColumnViewer viewer) {
        super(viewer);
        cellEditor = new ComboBoxCellEditor(((TableViewer)viewer).getTable(), new String[]{"Yes", "No", "Both"}, SWT.READ_ONLY);

    }

    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"); **<- Error Here
            ((AplotDatasetData)element).setMarkupValue(option);
            getViewer().update(element, null);
        }
    }
}

The conditional operator 条件运算符

x ? y : z

is a ternary operator, which internally does: 是三元运算符,在内部执行以下操作:

if(x)
    y;
else
    z;

Thus, you can only use it with three components. 因此,您只能将其与三个组件一起使用。 Use an if else if else instead: 使用的if else if else来代替:

Integer choice = (Integer)value;
String option = "";

if(choice == 0)
    option = "Yes";
else if(choice == 1)
    option = "No";
else
    option = "Both";

TableEditor can be used to show any Widget on top of Table Cell. TableEditor可用于在表格单元格顶部显示任何窗口小部件。 It should solve your problem with showing Combobox to let user know there is selection possible for that row and column. 它应该通过显示Combobox来解决您的问题,让用户知道该行和该列有可能的选择。

I am not sure I understand your question about 3 selections. 我不确定我是否理解您关于3个选择的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM