gpt4 book ai didi

gwt - 如何: UiBinder + GWT MVP + multiple independent display areas

转载 作者:行者123 更新时间:2023-12-04 07:42:50 24 4
gpt4 key购买 nike

我正在使用 GWT MVP 和 UiBinder 创建一个带有 DockLayoutPanel 的应用程序。我希望南北码头是静态的,包含按钮和链接。我想在中心和东码头的两个不同区域拥有动态 View 。由于这些动态区域应该是相互独立的,所以我为每个动态显示区域设置了不同的 ActivityMapper 和 ActivityManager;中、东上、东下。

加载应用程序时如何独立初始化这3个不同的显示区域?如何在一个显示区域从一个 Activity 切换到另一个而不影响其他区域?

当我使用 PlaceController 的 goTo 在一个区域从一个 Place 切换到另一个 Place 时,另一个区域的 Activity 会停止。

求救,求救,求救!

以下是我的一些代码:

AppViewImpl.ui.xml

<g:DockLayoutPanel styleName="{style.dockPanel}" unit="PX" width="975px" height="100%">

<!-- DOCK PANEL EAST -->
<g:east size="220">
<g:LayoutPanel styleName="{style.eastPanel}">
<g:layer left="0px" width="220px" top="0px" height="105px">
<g:SimpleLayoutPanel ui:field="topRightPanel"/>
</g:layer>

<g:layer left="0px" width="220px" top="110px" height="340px">
<g:InlineLabel styleName="{style.label}" text="ANOTHER DISPLAY AREA"/>
</g:layer>
</g:LayoutPanel>
</g:east>

<!-- DOCK PANEL NORTH -->
<g:north size="110">
<g:LayoutPanel styleName="{style.northPanel}">
<g:layer left="0px" width="755px" top="0px" height="105px">
<g:InlineLabel styleName="{style.label}" text="NORTH PANEL"/>
</g:layer>
</g:LayoutPanel>
</g:north>

<!-- DOCK PANEL SOUTH -->
<g:south size="20">
<g:LayoutPanel styleName="{style.southPanel}">
<g:layer left="0px" width="755px" top="0px" height="20px">
<g:InlineLabel styleName="{style.label}" text="SOUTH PANEL"/>
</g:layer>
</g:LayoutPanel>
</g:south>

<!-- DOCK PANEL CENTER -->
<g:center>
<g:SimpleLayoutPanel ui:field="mainPanel" />
</g:center>
</g:DockLayoutPanel>

我的模块.java

公共(public)类 MyModule 实现 EntryPoint {
private Place defaultPlace = new DefaultPlace("");

public void onModuleLoad() {
// Create ClientFactory using deferred binding so we can replace with
// different impls in gwt.xml
ClientFactory clientFactory = GWT.create(ClientFactory.class);
EventBus eventBus = clientFactory.getEventBus();
PlaceController placeController = clientFactory.getPlaceController();

// Start ActivityManager for the main widget with our ActivityMapper
ActivityMapper topRightActivityMapper = new TopRightActivityMapper(clientFactory);
ActivityManager topRightActivityManager = new ActivityManager(topRightActivityMapper, eventBus);
topRightActivityManager.setDisplay(clientFactory.getAppView().getTopRightPanel());

// Start ActivityManager for the main widget with our ActivityMapper
ActivityMapper mainActivityMapper = new AppActivityMapper(clientFactory);
ActivityManager mainActivityManager = new ActivityManager(mainActivityMapper, eventBus);
mainActivityManager.setDisplay(clientFactory.getAppView().getMainPanel());

// Start PlaceHistoryHandler with our PlaceHistoryMapper
AppPlaceHistoryMapper historyMapper = GWT .create(AppPlaceHistoryMapper.class);
PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
historyHandler.register(placeController, eventBus, defaultPlace);
RootLayoutPanel.get().add(clientFactory.getAppView());

// Goes to place represented on URL or default place
historyHandler.handleCurrentHistory();

new AppController(clientFactory);
}

}

应用 Controller .java
public class AppController implements AppView.Presenter {

private ClientFactory clientFactory;

AppController(ClientFactory clientFactory){
this.clientFactory = clientFactory;
goTo(new TopRightAPlace(""));
}

@Override
public void goTo(Place place) {
clientFactory.getPlaceController().goTo(place);
}

}

TopRightAViewImpl.java
public class TopRightAViewImpl extends Composite implements TopRightAView {

interface Binder extends UiBinder<Widget, TopRightAViewImpl> {
}

private static final Binder binder = GWT.create(Binder.class);

private Presenter listener;
@UiField
Button button;

public TopRightAViewImpl() {
initWidget(binder.createAndBindUi(this));
}

@Override
public void setName(String name) {
button.setHTML(name);
}

@Override
public void setPresenter(Presenter listener) {
this.listener = listener;
}

@UiHandler("button")
void onButtonClick(ClickEvent event) {
listener.goTo(some other place);
}
}

最佳答案

GWT Place年代,PlaceController , 和 PlaceHistoryMapper使您能够在应用程序中创建可添加书签的 URL,从而允许浏览器的后退按钮和书签按预期工作。这就是 GWT Place s 专为。因此,拥有多个 Place 是没有意义的。由于您拥有整个应用程序的一个 URL,因此您可以随时在应用程序中激活。
PlaceControllergoTo()方法确实通知注册的ActivityManager ,在接收到 PlaceChangeEvent 时停止当前 Activity。

我对你的建议是不要使用 Place s 和 PlaceChangeEvent s 代表您的DockLayoutPanel 东侧的两个区域.使用Place s 代表您的应用程序的主屏幕,它可能是您的 DockLayoutPanel 的中心.火不同GwtEvent类型,可以是通用事件类型之一(即 ValueChangeEvent )或自定义事件类型,当您需要更新东侧区域时。您仍然可以使用 Activitie s 用于东侧,但您需要创建自己的 ActivityManager ,这实际上并不难。你所要做的就是复制GWT的ActivityManager ,重命名它,并替换处理 PlaceChangeEvent 的方法的名称s 和 PlaceChangeRequestEvent s 与那些处理您自己的事件的人。

关于gwt - 如何: UiBinder + GWT MVP + multiple independent display areas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8244851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com