我有以下父容器:
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
的内容会发生变化。我正在尝试使用Activities / Places框架让每个TextButton点击在历史记录中被记住。因此,如果用户分别单击“红色”,“绿色”和“蓝色”按钮,contentPanel
将更改三次,然后他们可以单击后退/前进浏览器历史记录按钮并继续来回移动在历史中(和“重播”按钮一遍又一遍地点击等)。
我还有以下课程:
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
参数注入正确的显示?
答案 0 :(得分:1)
作为管理员初始化的一部分,您可以将ParentContainer#contentPanel
传递给ActivityManager
的{{3}}方法。