在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实例化对话框;
谢谢!
答案 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