0

我有以下父容器:

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;
}

因此,当用户单击 中的其中一个 TextButtons 时buttonPanelcontentPanel的内容会发生变化。我正在尝试使用“活动/地点”框架让每个 TextButton 点击​​被记住在历史中。因此,如果用户分别点击“红色”、“绿色”和“蓝色”按钮,contentPanel则会改变 3 次,然后他们可以点击 Back/Forward 浏览器历史记录按钮并在历史记录中不断来回移动(并且“重播”按钮一遍又一遍地点击,等等)。

我还有以下课程:

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). 我们如何确保这panelParentContainer#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参数注入正确的显示吗?

4

1 回答 1

1

作为管理器初始化的一部分,您将传递ParentContainer#contentPanel给您的setDisplay()方法。ActivityManager

于 2012-11-07T21:54:35.620 回答