Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用不带UiBinder的GWT编辑器_Java_User Interface_Gwt_Uibinder - Fatal编程技术网

Java 使用不带UiBinder的GWT编辑器

Java 使用不带UiBinder的GWT编辑器,java,user-interface,gwt,uibinder,Java,User Interface,Gwt,Uibinder,我想通过使用编辑器来绑定POJO来改进我的gwt项目的代码,我使用POJO手动来回解析小部件。然而,我感到困惑,主要是因为它引用了另一个我还没有弄明白的特性 使用没有ui活页夹的编辑器有意义吗?我的ParentDTO包含许多childto。下面的代码片段显示了我如何尝试将一些由TextArea扩展的ChildEditor嵌套到我的ParentEditor中(尝试将其拆分为essentials): 公共类MyEditorPage{ //编辑 类ParentDTOEditor实现编辑器{ 整数数据库

我想通过使用编辑器来绑定POJO来改进我的gwt项目的代码,我使用POJO手动来回解析小部件。然而,我感到困惑,主要是因为它引用了另一个我还没有弄明白的特性

使用没有ui活页夹的编辑器有意义吗?我的ParentDTO包含许多childto。下面的代码片段显示了我如何尝试将一些由TextArea扩展的ChildEditor嵌套到我的ParentEditor中(尝试将其拆分为essentials):

公共类MyEditorPage{
//编辑
类ParentDTOEditor实现编辑器{
整数数据库ID;
列出儿童;
公共空白附加(根面板根面板){
for(childtoeditor小部件:childs){
添加(小部件);
}
}
}
类ChildToeditor实现编辑器扩展TextArea{}
//司机
接口驱动程序扩展SimpleBeanEditorDriver{}
Driver-Driver=GWT.create(Driver.class);
//将集合小部件加载到根面板
公共void加载页(根面板根面板){
//从服务器获取POJO
myService.getSuff(。。。
...
成功时公共无效(从父项到结果){
ParentDTOEditor编辑器=新的ParentDTOEditor();
初始化驱动程序(编辑器);
驱动程序。编辑(结果);
编辑器。附加(根面板);
}
}
//拯救
公共作废保存(){
ParentDTO dto=driver.flush();
…//调用myService.saveStuff(dto,。。。
}
}
我甚至需要单独的编辑器,还是只需要ListEditor类型的父编辑器直接保存子DTO

使用没有ui活页夹的编辑器有意义吗

是的,这些功能是独立的,可以在没有其他功能的情况下使用

我甚至需要单独的编辑器,还是只需要类型为
ListEditor
的父编辑器直接保存子DTO

您可以直接创建一个
ListEditor
实现,但如果您告诉GWT如何通过扩展
EditorSource
并使用
ListEditor.of(new yourchildtoeditorsourceimpl())来创建和销毁
编辑器,GWT可以为您创建和销毁该编辑器

这里有一个不错的例子,但我会在这里给出一个最低限度的实现

public class FooEditor extends Composite implements Editor<Foo> {

    // Implement one of uibinder+fields, fields, methods, or LeafValueEditor.set/getValue()

    public FooEditor() {
        initWidget(/* root widget or call to uiBinder.createAndBindUi(this) */)
    }

}

public class FooListEditor extends Composite implements IsEditor<ListEditor<Foo, FooEditor>> {

    private class FooEditorSource extends EditorSource<FooEditor> {
        @Override
        public FooEditor create(int index) {
            FooEditor subEditor = new FooEditor();

            // any additional per-item config can go here, e.g wiring up delete handler

            listPanel.insert(subEditor, index);

            return subEditor;
        }

        @Override
        public void dispose(FooEditor subEditor) {
            subEditor.removeFromParent();
        }

        @Override
        public void setIndex(FooEditor subEditor, int index) {
            listPanel.insert(subEditor, index);
        }
    }

    // FlowPanel or anything else you want to use to hold the sub-editors.
    // Instantiated explicitly or through uibinder.
    FlowPanel listPanel = new FlowPanel(); 


    // Let GWT handle the ListEdiotr implementation
    ListEditor<Foo, FooEditor> editor = ListEditor.of(new FooEditorSource());

    public FooListEditor() {
        initWidget(listPanel /* or uiBinder.createAndBindUi(this) */);
    }

    @Override
    public ListEditor<Foo, FooEditor> asEditor() {
        return editor;
    }

}
公共类FooEditor扩展了复合实现编辑器{
//实现uibinder+字段、字段、方法或LeafValueEditor.set/getValue()中的一个
公共编辑(){
initWidget(/*根小部件或对uiBinder.createAndBindUi的调用(此)*/)
}
}
公共类傻瓜编辑器扩展复合实现IsEditor{
私有类FooEditorSource扩展了EditorSource{
@凌驾
公共编辑器创建(int索引){
FooEditor子编辑器=新建FooEditor();
//任何附加的每项配置都可以转到此处,例如连接删除处理程序
插入(子编辑器,索引);
返回子编辑器;
}
@凌驾
公共void dispose(FooEditor子编辑器){
subEditor.removeFromParent();
}
@凌驾
公共void集合索引(FooEditor子编辑器,int索引){
插入(子编辑器,索引);
}
}
//FlowPanel或任何您想要用来保存子编辑器的东西。
//显式实例化或通过uibinder实例化。
FlowPanel listPanel=新的FlowPanel();
//让GWT处理ListEdiotr实现
ListEditor editor=ListEditor.of(new foodeditorsource());
公共编辑程序(){
initWidget(listPanel/*或uiBinder.createAndBindUi(this)*/);
}
@凌驾
public ListEditor asEditor(){
返回编辑器;
}
}
现在,您可以创建一个编辑器驱动程序,并像使用普通编辑器一样使用它,但可以向它传递一个列表

interface Driver extends SimpleBeanEditorDriver<List<Foo>, ListEditor<Foo, FooEditor>> {}
Driver driver = GWT.create(Driver.class);
FooListEditor fooListEditor = new FooListEditor();

/* snip */

driver.initialize(FooListEditor);
driver.edit(someListOfFoo);
接口驱动程序扩展SimpleBeanEditorDriver{}
Driver-Driver=GWT.create(Driver.class);
傻瓜编辑器傻瓜编辑器=新的傻瓜编辑器();
/*剪断*/
驱动程序初始化(傻瓜编辑器);
driver.edit(somelistofoo);
interface Driver extends SimpleBeanEditorDriver<List<Foo>, ListEditor<Foo, FooEditor>> {}
Driver driver = GWT.create(Driver.class);
FooListEditor fooListEditor = new FooListEditor();

/* snip */

driver.initialize(FooListEditor);
driver.edit(someListOfFoo);