0

我的问题与这个问题几乎相同: 具有多态类型的 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(),创建并显示具有良好值的字段。但是,如果我更改一个值,则不会检测到任何修改。

谁能告诉我我错过了什么?

提前致谢

4

1 回答 1

0

我有一个类似的问题。作为一个建议,试试这个:

1. 在 ShapeEditorWrapper 中

您似乎错过了设置 ShapeTypeEnum.TRIANGLE 的值。

@Override
public void setValue(ShapeProxy value) {
    if (shapeEditor == null) {
        ...
        } else if (value.getShapeType() == ShapeTypeEnum.TRIANGLE) {
            ...
            ShapeEditor.setValue(value); // ===> It seems you forgot this.
            ...
        } 
    } 
}

每当刷新包装器时刷新 ShapeEditor。

@Override
public void flush ()
{
    shapeEditor.flush();
}

2.在ShapeEditor中,ShapeTriangleEditor和ShapeSquareEditor

确保 setValue() 实际上更新了一个 bean,并在必要时使用 bean 值初始化任何小部件。

private ShapeProxy shape;
@Override
public void setValue(ShapeProxy value) {
    this.shape = value
    // intialize your widget fields here.
}

将小部件值刷新回 bean。编辑器框架应该为您处理其余的事情。

@Override
public void flush ()
{
    //Flush your widget values to the proxy
    shape.setXXX(...);
    //...
}

我希望这个对你有用。它对我有用!

于 2014-05-08T20:52:11.593 回答