GWT的编辑框架和GWTP

时间:2014-07-03 13:51:17

标签: gwt gwt-platform

this answer上构建,我尝试将GWT编辑器集成到弹出式演示器小部件中。这样做的正确方法是什么?

我的观点如下:

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;
    }

}

我的演示者看起来像这样:

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();

}

这是正确的做法吗?缺什么?目前我尝试使用它时没有任何反应:

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

}

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

谢谢!

1 个答案:

答案 0 :(得分:3)

以上代码中缺少以下几个要点:

  • 您的DeviceEditorDialogView应该实施Editor<DeviceDto>。这是必需的,以便DeviceEditorDialogView的字段填充您POJO的数据。
  • 您的DeviceEditorDialogView应该包含映射到POJO中字段的子编辑器。例如,根据字段deviceDto.modelName(类型String),您可以在Label中拥有名为modelName的GWT DeviceEditorDialogView。这Label实施Editor<String>,当您致电modelName
  • 时,DeviceDto会填充driver.edit(deviceDto)
  • 您应该只在driver.initialize(this)的构造函数中致电DeviceEditorDialogView一次

你应该像这样覆盖onReveal()

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

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

DeviceEditorDialogPresenterWidget addToPopupSlot

之后显示弹出窗口时,系统会调用此方法