我的問題幾乎是相同的,因爲這一個: ListEditor with polymorphic types 托馬斯有一個很好的答案,但它是不夠的我。GWT ListEditor與多態類型 - 無法更新
我想顯示可能不同的對象列表,因此每個編輯器可以以不同的方式顯示。 它幾乎工作,除了我找不到問題:不可能獲得當前值並保存它。 (我認爲setValue方法必須被自動調用,但我有打電話給我自己)
下面是一些代碼:
ShapeListEditor:
public class ShapeListEditor extends VerticalLayoutContainer implements IsEditor<ListEditor<ShapeProxy, ShapeEditorWrapper>> {
public class ESource extends EditorSource<ShapeEditorWrapper> {
@Override
public ShapeEditorWrapper create(int index) {
ShapeEditorWrapper subEditor = new ShapeEditorWrapper(index);
subEditor.setLayoutData(new VerticalLayoutData(1, -1, new Margins(20, 20, 40, 20)));
insert(subEditor, index);
return subEditor;
}
@Override
public void dispose(ShapeEditorWrapper subEditor) {
remove(subEditor);
}
@Override
public void setIndex(ShapeEditorWrapper editor, int index) {
insert(editor, index);
}
}
private ListEditor<ShapeProxy, ShapeEditorWrapper> editor = ListEditor.of(new ESource());
@Override
public ListEditor<ShapeProxy, ShapeEditorWrapper> asEditor() {
return editor;
}
}
ShapeEditorWrapper:
public class ShapeEditorWrapper extends Composite implements ValueAwareEditor<ShapeProxy> {
private SimplePanel panel = new SimplePanel();
@Path("")
ShapeEditor ShapeEditor;
public ShapeEditorWrapper(int index) {
super();
initWidget(panel);
}
@Override
public void setValue(ShapeProxy value) {
if (ShapeEditor == null) {
if (value == null) {
} else if (value.getShapeType() == ShapeTypeEnum.SQUARE) {
ShapeEditor = new ShapeSquareEditor();
ShapeEditor.setValue(value);
panel.setWidget(ShapeEditor);
} else if (value.getShapeType() == ShapeTypeEnum.TRIANGLE) {
ShapeEditor = new ShapeTriangleEditor();
panel.setWidget(ShapeEditor);
}
}
}
}
ShapeEditor:
public class ShapeEditor extends VerticalLayoutContainer implements ValueAwareEditor<ShapeProxy> {
public ShapeEditor() {
super();
}
@Override
public void setValue(ShapeProxy value) {
}
@Override
public void setDelegate(EditorDelegate<ShapeProxy> delegate) {
// TODO Auto-generated method stub
}
@Override
public void flush() {
// TODO Auto-generated method stub
}
@Override
public void onPropertyChange(String... paths) {
// TODO Auto-generated method stub
}
}
ShapeTriangleEditor和ShapeSquareEditor具有相同的屬性,但我不想擁有相同的顯示。這些類覆蓋setValue(),創建和顯示字段,這些字段以良好的值出現。但是,如果我更改了值,則不會檢測到任何修改。
誰能告訴我我錯過了什麼?
在此先感謝