Pet*_*ete 8 gwt uibinder gwt-mvp gwt-activities gwt-places
我正在使用GWT MVP和UiBinder来创建一个带有DockLayoutPanel的应用程序.我希望南北码头是静态的,包含按钮和链接.我希望在中心和东部码头的两个不同区域拥有动态视图.由于这些动态区域应该彼此独立,我为每个动态显示区域设置不同的ActivityMapper和ActivityManager; 中心,东顶和东底.
如何在加载应用程序时独立初始化这3个不同的显示区域?如何在一个显示区域中从一个Activity切换到另一个Activity而不影响其他区域?
当我使用PlaceController的goTo在一个区域中从一个地方切换到另一个地方时,另一个区域的活动停止.
五月天,请帮忙,五月天!
以下是我的一些代码:
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>
Run Code Online (Sandbox Code Playgroud)
MyModule.java
公共类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);
}
Run Code Online (Sandbox Code Playgroud)
}
AppController.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);
}
}
Run Code Online (Sandbox Code Playgroud)
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);
}
}
Run Code Online (Sandbox Code Playgroud)
GWT PlaceS,PlaceController以及PlaceHistoryMapper使您能够创建应用程序,使浏览器的后退按钮和书签的工作正如人们所预料之内可收藏的URL.这就是GWT Place的设计目标.因此,Place在任何时间点在应用程序中激活多个是没有意义的,因为您有一个整个应用程序的URL.
PlaceController的goTo()方法确实通知了已注册的ActivityManager,它在收到PlaceChangeEvent时停止当前的Activity.
我建议你不要在你东边的两个区域使用Places和PlaceChangeEvents DockLayoutPanel.将Places用于应用程序的主屏幕,这可能是您的主屏幕的中心DockLayoutPanel.当您需要更新它们时,为东侧区域触发不同GwtEvent类型(通用事件类型之一(即.ValueChangeEvent)或自定义事件类型).您仍然可以Activitie在东侧使用s,但是您需要创建自己的ActivityManager,实际上并不那么难.您所要做的就是复制GWT ActivityManager,重命名它,并将处理PlaceChangeEvents和PlaceChangeRequestEvents 的方法的名称替换为处理自己事件的方法.
| 归档时间: |
|
| 查看次数: |
3925 次 |
| 最近记录: |