0
我嘗試在SWT Widgets上使用DataBinding。在Combo上使用DataBinding
我想知道是否有方法將Combo Box連接到模型中的底層String。 因此,我的模型中有String,我的View上有Combo?
隨着標準的方式是行不通的:
//View
DataBindingContext ctx = new DataBindingContext();
IObservableValue target1 = WidgetProperties.singleSelectionIndex().observe(combo);
IObservableValue model1 = BeanProperties.value(OutputVariable.class, "type").observe(outputVariable);
ctx.bindValue(target1, model1);
//Model
public void setType(String type) {
//TYPES is a constant with the possible Combo values
if (contains(TYPES, type)) {
String oldType = this.type;
this.type = type;
firePropertyChange("type", oldType, this.type);
}else {
throw new IllegalArgumentException();
}
}
我試圖使用沒有任何工作的fireIndexedPropertyChangeMethod。
有沒有辦法將這兩者連接在一起?也許我必須使用另一個WidgetProperties或BeanProperties方法?
作爲一種解決方法,我可以在模型中使用一個新的屬性,該屬性定義了組合選擇索引,將其連接到Combo並將此索引的更改轉移到類型屬性,反之亦然。但是這對我來說似乎不是一個很好的解決方案。
編輯: 帶有selectionIndex屬性的解決方案正在工作。但是更簡潔的方法仍然很好,因爲模型中的類型屬性更改必須重置selectionIndex,反之亦然。