我的问题与这个问题几乎相同: 具有多态类型的 ListEditor Thomas 有一个很好的答案,但这对我来说还不够。
我想显示可能不同的对象列表,因此每个编辑器的显示方式可能不同。它几乎可以工作,只是我找不到问题:无法获取当前值并保存它。(我认为setValue方法必须自动调用,但我必须自己调用)
这是一些代码:
形状列表编辑器:
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;
}
}
形状编辑器包装器:
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);
}
}
}
}
形状编辑器:
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(),创建并显示具有良好值的字段。但是,如果我更改一个值,则不会检测到任何修改。
谁能告诉我我错过了什么?
提前致谢