我有以下父容器:
public class ParentContainer extends Composite {
// Contains a bunch of TextButtons (RedButton, GreenButton, etc.).
private LayoutPanel buttonPanel;
// When user clicks a TextButton inside the buttonPanel,
// it changes the content of this contentPanel.
private LayoutPanel contentPanel;
}
因此,当用户单击
buttonPanel
内的一个TextButtons时,contentPanel
的内容就会更改。我正在尝试使用“活动/位置”框架使每个TextButton单击在历史中被记住。因此,如果用户分别单击“红色”,“绿色”和“蓝色”按钮,则contentPanel
将更改3次,然后他们可以单击“后退/前进”浏览器历史记录按钮并在历史记录中来回移动(然后“重播”按钮一遍又一遍地点击等等)。我也有以下课程:
com.mywebapp
MainModule.gwt.xml
com.mywebapp.client
MainModule
com.mywebapp.client.places
RedButtonPlace
GreenButtonPlace
BlueButtonPlace
... 1 place for all buttons
com.mywebapp.client.activities
RedButtonActivity
GreenButtonActivity
BlueButtonActivity
... 1 activity for all buttons
com.mywebapp.client.ui
ParentContainer
RedButton
GreenButton
BlueButton
BlackButton
PurpleButton
OrangeButton
我正计划将其连接起来,以便:
PlaceController.goTo(new RedButtonPlace())
最终路由到RedButtonActivity
PlaceController.goTo(new GreenButtonPlace())
最终路由到GreenButtonActivity
等等(每个按钮的颜色都有其位置和活动)
我遇到的问题是:如果我从
PlaceController.goTo(new RedButtonPlace())
单击处理程序中调用RedButton
,我该如何指示RedButtonActivity
更新contentPanel
的位置?例如:public class RedButton extends TextButton {
// ... bunch of stuff, nevermind why I am extending TextButton
// this is just to help me connect all the major dots of GWT!
public RedButton() {
this.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// If the RedButton is clicked, we want all the content in RedButtonActivity#RedButtonView
// to go inside ParentContainer#contentPanel.
PlaceController.goto(new RedButtonPlace());
}
});
}
}
public class RedButtonActivity extends AbstractActivity {
public interface RedButtonView extends IsWidget {
// Whatever the RedButton expects to be able to display.
}
private RedButtonView view;
@Override
public void start(AcceptsOneWidget panel, EventBus eventBus) {
// Probably injected via GIN.
view = somehowInjectTheView();
panel.setWidget(view);
}
}
最后一行是这里的关键:
panel.setWidget(view)
。我们如何确定panel
是ParentContainer#contentPanel
?提前致谢!编辑:每个答案表明,这是代码更新:
public class ParentContainer extends Composite {
// All the stuff that's up above in the first parent container.
public ParentContainer() {
super();
// Again, via GIN.
ActivityManager redButtonActivityManager = getSomehow();
redButtonActivityManager.setDisplay(contentPanel);
}
}
如果这是正确的方法,那么我假设在调用
start(AcceptsOneWidget panel, EventBus eventBus)
方法时,redButtonActivityManager
知道为panel
参数注入正确的显示吗? 最佳答案
您将ParentContainer#contentPanel
传递给setDisplay()
的ActivityManager
方法,作为管理器初始化的一部分。