GWT的编辑器框架和GWTP [英] GWT's Editor Framework and GWTP

查看:81
本文介绍了GWT的编辑器框架和GWTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于此答案,我尝试将GWT编辑器集成到弹出演示器小部件中.正确的做法是什么?

building on this answer, i try to integrate the GWT editors into a popup presenter widget. What is the right way to do that?

我的视图如下:

public class DeviceEditorDialogView extends
        PopupViewWithUiHandlers<DeviceEditorDialogUiHandlers> implements
        DeviceEditorDialogPresenterWidget.MyView {
    interface Binder extends UiBinder<PopupPanel, DeviceEditorDialogView> {
    }
    public interface Driver extends SimpleBeanEditorDriver<DeviceDto, DeviceEditorDialogView> {
    }

    @Inject
    DeviceEditorDialogView(Binder uiBinder, EventBus eventBus) {
        super(eventBus);

        initWidget(uiBinder.createAndBindUi(this));
    }


    @Override
    public SimpleBeanEditorDriver<DeviceDto, ?> createEditorDriver() {
        Driver driver = GWT.create(Driver.class);
        driver.initialize(this);
        return driver;
    }

}

我的主持人看起来像这样:

and my presenter looks like this:

public class DeviceEditorDialogPresenterWidget extends PresenterWidget<DeviceEditorDialogPresenterWidget.MyView> implements
            DeviceEditorDialogUiHandlers {

    @Inject
    DeviceEditorDialogPresenterWidget(EventBus eventBus,
                               MyView view) {
        super(eventBus, view);
        getView().setUiHandlers(this);
    }
    /**
     * {@link LocalDialogPresenterWidget}'s PopupView.
     */
    public interface MyView extends PopupView, DevicesEditView<DeviceDto>, HasUiHandlers<DeviceEditorDialogUiHandlers> {

    }

    private DeviceDto currentDeviceDTO = null;

    private SimpleBeanEditorDriver<DeviceDto, ?> driver;

    public DeviceDto getCurrentDeviceDTO() {
        return currentDeviceDTO;
    }

    public void setCurrentDeviceDTO(DeviceDto currentDeviceDTO) {
        this.currentDeviceDTO = currentDeviceDTO;
    }

    @Override
    protected void onBind() {
        super.onBind();

        driver = getView().createEditorDriver();
    }
    //UiHandler Method: Person person = driver.flush();

}

这是正确的方法吗?什么不见​​了?目前,当我尝试像这样使用它时,什么也没有发生:

Is this the right approach? What is missing? Currently nothing happens when i try to use it like this:

@Override
public void showDeviceDialog() {
    deviceEditorDialog.setCurrentDeviceDTO(new DeviceDto());
    addToPopupSlot(deviceEditorDialog);

}

showDeviceDialog在父演示者中,并在单击该父演示者中的按钮时调用,该对话框使用私有的最终DeviceEditorDialogPresenterWidget deviceEditorDialog实例化对话框;

showDeviceDialog is in the parent presenter and called when clicking a button in that parent Presenter, that instantiates the dialog with private final DeviceEditorDialogPresenterWidget deviceEditorDialog;

谢谢!

推荐答案

以下是您上面的代码中缺少的一些关键点:

Here are a few key points that are missing from your code above:

  • 您的DeviceEditorDialogView应该实现Editor<DeviceDto>.为了用来自POJO的数据填充DeviceEditorDialogView字段,这是必需的.
  • 您的DeviceEditorDialogView应该具有映射到POJO中的字段的子编辑器.例如,给定字段deviceDto.modelName(类型为String),您可能在DeviceEditorDialogView中具有名为modelName的GWT Label.此Label实现Editor<String>,并且在调用driver.edit(deviceDto)
  • 时将在您的DeviceDto中填充modelName
  • 您只能在DeviceEditorDialogView的构造函数中调用driver.initialize(this)一次
  • Your DeviceEditorDialogView should implement Editor<DeviceDto>. This is required in order for the fields of DeviceEditorDialogView to be populated with data from you POJO.
  • Your DeviceEditorDialogView should have child editors that are mapped to fields in your POJO. For example, given the field deviceDto.modelName (type String), you could have a GWT Label named modelName in your DeviceEditorDialogView. This Label implements Editor<String> and will be populated with the modelName from your DeviceDto when you call driver.edit(deviceDto)
  • You should call driver.initialize(this) only once, in DeviceEditorDialogView's constructor

您应该像这样覆盖onReveal():

@Override
public void onReveal() {
    super.onReveal();

    driver.edit(currentDeviceDTO); // this will populate your view with the data from your POJO
}

在您显示DeviceEditorDialogPresenterWidget之后,将在显示弹出窗口时调用此方法.

This method will be called when the popup is displayed, just after your DeviceEditorDialogPresenterWidget has been addToPopupSlot

这篇关于GWT的编辑器框架和GWTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆