0

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!

Community
  • 1
  • 1
Fluffy
  • 299
  • 1
  • 4
  • 21
  • can you post the `GinInjector` error ? – Ümit Jul 03 '14 at 15:15
  • I am sorry, i did a newbie mistake and forgot to bind the view and presenter in the ApplicationModule. I rephrased my question above, since i do not know if this is the right way to do it. – Fluffy Jul 07 '14 at 13:00

1 Answers1

3

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

spg
  • 9,309
  • 4
  • 36
  • 41
  • Thanks for the advice! If i move the functionality of createEditorDriver() to the constructor, how should it look then? It must be implemented. – Fluffy Jul 08 '14 at 14:07
  • 1
    I just got it running :) My rep is too low, else i would vote you up. Thank you for the well structured answer. – Fluffy Jul 08 '14 at 14:55