您发布的代码与回答您的问题无关。假设您有 4 个演示者:
将MainPresenter
包含其他 3 位演示者。当一个地方(家)被揭示时,就会触发一个事件。
HomePresenter
代码:
@Override
protected void revealInParent() {
// trigger the setInSlot of MainPageView
RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetMainContent,
this);
}
然后处理此事件setInSlot
,MainPageView
其中将内容添加到插槽之一。这就是为什么MainPresenter
应该有 3 个带有以下代码的插槽:
@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetMainContent = new Type<RevealContentHandler< ? >>();
@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetHeaderContent = new Type<RevealContentHandler< ? >>();
@ContentSlot
public static final Type<RevealContentHandler< ? >> TYPE_SetNavigationContent = new Type<RevealContentHandler< ? >>();
private boolean headerNavigationDisplayed = false;
@Inject
public MainPagePresenter(final EventBus eventBus, final MyView view,
final MyProxy proxy) {
super(eventBus, view, proxy);
}
@Override
protected void revealInParent() {
// trigger setInSlot in the RootView
RevealRootContentEvent.fire(this, this);
}
@Override
protected void onReveal() {
super.onReveal();
if (!headerNavigationDisplayed) {
// Fire this event to force reveal the header and navigation
// presenters
MainContentSetEvent.fire(this, "ThreePart");
headerNavigationDisplayed = true;
}
}
当MainPagePresenter
被揭露。它触发一个自定义事件MainContentSetEvent
。我有一个参数,但对你来说不是必需的。要处理此事件,HeaderPresenter
必须实现the
MainContentSetHandler` 接口。输入以下代码:
@Override
protected void revealInParent() {
RevealContentEvent.fire(this, MainPagePresenter.TYPE_SetHeaderContent,
this);
}
@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
forceReveal();
}
对NavigationPresenter
. 输入以下代码:
@Override
protected void revealInParent() {
RevealContentEvent.fire(this,
MainPagePresenter.TYPE_SetNavigationContent, this);
}
@ProxyEvent
@Override
public void onMainContentSet(MainContentSetEvent event) {
layout = event.getLayout();
forceReveal();
}
在视图方面,将以下代码放入MainPageView
:
@Override
public void setInSlot(Object slot, Widget content) {
if (slot == MainPagePresenter.TYPE_SetMainContent) {
setMainContent(content);
} else if (slot == MainPagePresenter.TYPE_SetHeaderContent) {
setHeaderContent(content);
} else if (slot == MainPagePresenter.TYPE_SetNavigationContent) {
setNavigationContent(content);
} else {
super.setInSlot(slot, content);
}
}
如果你想了解整个机制,在调试模式下运行,更容易理解调用的层次结构。我只放了相关代码,既然你知道了SimpleNestetExample
,你应该能写出缺少的代码。