GWT's Editor Framework and GWTP

社会主义新天地 提交于 2019-12-08 12:06:43

问题


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

My view looks like this:

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 is in the parent presenter and called when clicking a button in that parent Presenter, that instantiates the dialog with private final DeviceEditorDialogPresenterWidget deviceEditorDialog;

Thanks!


回答1:


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

  • 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

You should override onReveal() like this:

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

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

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



来源:https://stackoverflow.com/questions/24555556/gwts-editor-framework-and-gwtp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!