I have the following parent container:
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;
}
So when the user clicks one of the TextButtons inside the buttonPanel
, the contentPanel
's contents change. I am trying to get each TextButton click to be remembered in history, using the Activities/Places framework. So, if the user clicks the "Red", "Green" and "Blue" buttons respectively, the contentPanel
will change three times, and then they can click the Back/Forward browser history buttons and keep moving back and forth in history (and "replaying" the button clicks over and over again, etc.).
I also have the following classes:
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
I am planning on wiring things up such that:
PlaceController.goTo(new RedButtonPlace())
eventually routes to the RedButtonActivity
PlaceController.goTo(new GreenButtonPlace())
eventually routes to the GreenButtonActivity
What I'm stuck on is: if I call PlaceController.goTo(new RedButtonPlace())
from inside a RedButton
click handler, how and where do I instruct RedButtonActivity
to update contentPanel
? For instance:
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);
}
}
That last line is the key here: panel.setWidget(view)
. How do we make sure that panel
is the ParentContainer#contentPanel
? Thanks in advance!
Edit: Per one answer suggests, here is a code update:
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);
}
}
If this is the correct way, then I assume when the start(AcceptsOneWidget panel, EventBus eventBus)
method is called, the redButtonActivityManager
knows to inject the correct display for the panel
argument?
You would pass the ParentContainer#contentPanel
to the setDisplay()
method of your ActivityManager
as part of the manager's initialization.