我想从头开始构建一个DialogBox层次结构。首先,我有
BaseDialog.java 类:扩展DialogBox(gwt小部件)的简单对话框
public class BaseDialog extends DialogBox {
protected static BaseDialog2UiBinder uiBinder = GWT
.create(BaseDialog2UiBinder.class);
interface BaseDialog2UiBinder extends UiBinder<Widget, BaseDialog2> {
}
@UiField
protected FlowPanel contentPanel;
public BaseDialog() {
setWidget(uiBinder.createAndBindUi(this));
}
}
BaseDialog.ui.xml
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:VerticalPanel width="200px" height="200px">
<g:Label>Label principal</g:Label>
<g:FlowPanel ui:field="contentPanel" />
</g:VerticalPanel>
</ui:UiBinder>
如您所见,BaseDialog包含一个简单的Label和一个contentPanel(FlowPanel)。
我想扩展BaseDialog(例如ConfirmationDialog)。 ConfirmationDialog填充BaseDialog的contentPanel的内容。
我该怎么做?
感谢。
答案 0 :(得分:3)
好的,我找到了解决方案:
public class ConfirmationBox extends BaseDialog2 {
protected static ConfirmationBoxUiBinder uiBinder = GWT.create(ConfirmationBoxUiBinder.class);
interface ConfirmationBoxUiBinder extends UiBinder<Widget, ConfirmationBox> {
}
@UiField
Label helloLabel;
public ConfirmationBox() {
contentPanel.add(uiBinder.createAndBindUi(this));
}
}
和
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:my="urn:import:com.guardis.cortex.web.client.dialog">
<g:FlowPanel>
<my:BaseDialog2>
<g:FlowPanel ui:field="contentPanel">
<g:Label>test contentPanel from confirmationBox</g:Label>
</g:FlowPanel>
</my:BaseDialog2>
<g:Label ui:field="helloLabel">Hello world from confirmation box (outside of BaseDialog)</g:Label>
</g:FlowPanel>
</ui:UiBinder>