`
flashcloud
  • 浏览: 185307 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

MVP For GWT 系列资料转载八:Swapping DIVs technique for navigation with gwt-presenter

    博客分类:
  • GWT
 
阅读更多

源文转自:Swapping DIVs technique for navigation with gwt-presenter

 

I have previously written about navigation in gwt-presenter using the DeckPresenter or WidgetContainerPresenter approaches. Those techniques work well for swapping out views in one portion of the page, and could be applied to the whole page, as well; however, here’s another simpler technique for situations in which you need to swap between totally unrelated views. For example, my main app has a header, footer, and content area in which views are swapped out using a WidgetContainerPresenter. However, I also need to replace the whole page (header, footer, and all) for a user registration page. To do this, I simply created two DIVs in the HTML host page:

 

<div id="roa-registration"></div>
<div id="container"></div>

 

My main AppPresenter loads all the presenters up front and fires a PlaceRequestEvent to the user registration presenter for new users. For existing users, it fires a PlaceRequestEvent based on the URL or to the default presenter if the URL is empty.

 

...
	public void go(final HasWidgets container)
	{
		this.container = container;
		loadMain();
		hideSplash();
		if (roaModel.getLoginInfo().getUser() != null)
		{
			showMain();
			String currentPlace = History.getToken();
			if ("".equals(currentPlace))
			{
				goToDefaultView();
			}
			else
			{
				// Load requested page
				placeManager.fireCurrentPlace();
			}
		}
		else
		{
			showRegistration();
		}
	}

	private void showRegistration()
	{
		// New user must register
		eventBus.fireEvent(new PlaceRequestEvent(new PlaceRequest(
			UserRegistrationPresenter.PLACE)));
	}

	private void hideSplash()
	{
		DOM.removeChild(RootPanel.getBodyElement(), DOM
			.getElementById(RoaStyles.ID_SPLASH));
	}

	private void loadMain()
	{
		// Hide while loading
		 DOM.setStyleAttribute(RootPanel.get(RoaStyles.CONTAINER_ID)
		 .getElement(), "display", "none");
		container.clear();
		HeaderPanel headerPanel = new HeaderPanel(roaModel.getLoginInfo());
		headerPanel.add(messagePresenter.getDisplay().asWidget());
		container.add(headerPanel);
		...
		container.add(bodyPanel);
		container.add(new FooterPanel());
	}

	private void showMain()
	{
		// Set GWT container visible
		DOM.setStyleAttribute(RootPanel.get(RoaStyles.CONTAINER_ID)
			.getElement(), "display", "block");
		// Load initial data
		prayerListService.refreshPrayerLists();
	}

	private void goToDefaultView()
	{
		// Nothing in URL, load default page
		eventBus.fireEvent(new PlaceRequestEvent(new PlaceRequest(
			ManageListsPresenter.PLACE)));
	}

 

Finally, I toggle the visibility of the two DIVs in the user registration presenter’s revealDisplay() method, which gets called in response to a PlaceRequestEvent. In addition, I call a hideDisplay() method in the presenter’s onBind() method (called from the constructor), so that its initial state is hidden.

 

@Override
public void revealDisplay()
{
	super.revealDisplay();
	RootPanel.get(RoaStyles.CONTAINER_ID).setVisible(false);
	RootPanel.get(RoaStyles.REGISTRATION_CONTAINER_ID).setVisible(true);
}

public void hideDisplay()
{
	RootPanel.get(RoaStyles.REGISTRATION_CONTAINER_ID).setVisible(false);
}

 

The downside to this technique is that it would be a pain to manage with more than a few DIVs, as each presenter would have to know how to show itself and hide the others; however, for swapping between completely different page layouts, I think it’s easier than creating nested WidgetContainerPresenters (if that would even work). On the plus side, multiple presenters can use each layout (DIV), and most applications are likely to need only a handful of completely distinct page layouts. YMMV.

分享到:
评论

相关推荐

    GWT简介.docx

    NULL 博文链接:https://mydownload.iteye.com/blog/1157105

    gxt-2.1.1-gwt2 最新的

    gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2gxt-2.1.1-gwt2

    gwt-maven-plugin:旧版GWT Maven插件

    现在,该插件被认为是legacy GWT maven plugin (又名mojo GWT maven插件),而新插件被认为是new generation GWT maven plugin (又名tbroyer GWT maven插件)。 仍然支持旧版maven插件,但强烈建议将新插件用于新...

    gwt-widgets-server1.1.jar

    GWT整合Spring时需要这个包,在官网上没有最新的jar包,这是自己用jar命令生成的,并测试可以使用。

    gwt-ex t学习必备资料

    gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-ex t学习必备资料gwt ext gwt-ext gwt-...

    gwt入门-gwt从这里开始

    C:\程序开发\Java\gwt-windows-1.4.59 doc(文档目录,开发文档和Java API文档) samples(示例代码目录,非常有名的KitchenSink示例代码即在此目录中) about.html about.txt applicationCreator.cmd ...

    gwt-comet-jar包+实例+source.jar包,

    里面东西很多,都是关于GWT-COMET的内容,实现gwt的服务器推技术,包括gwt-comet-examples-1.2.3:google官网上的Test实例;gwt-comet-1.2.3.jar:jar包,gwt-example:聊天实例源代码(.java的),gwt-event-source...

    gwt-maven-plugin:开始使用Maven构建GWT项目

    gwt-maven-plugin 该插件旨在通过提供两种特定的打包方式: gwt-lib和gwt-app ,使使用Maven构建GWT项目更加容易。 基本用法 将插件添加到您的POM并启用扩展: &lt; groupId&gt;net.ltgt.gwt.maven&lt;/ groupId&gt; ...

    gwt-dev-plugin for IE、FireFox、Chrome

    gwt-dev-plugin是GWT针对浏览器的安装插件,包含IE、FireFox、Chrome的。不需要的匆下,非学习文档

    GWT-Developer-Plugin

    GWT-Developer-Plugin

    gwt-user.jar

    gwt-user.jar 大小:2.86 MB

    gwt-dev-plugin-x86-对ie浏览器使用

    gwt代码调试插件gwt-dev-plugin-x86.msi,针对ie浏览器使用

    gwt-dev-plugin

    gwt-dev-plugin

    gwt-dev-windows.jar

    gwt-dev-windows.jar 大小:9.60 MB

    gwt-dev-plugin-1.26-rc1.xpi for firefox插件

    原地址如下 http://google-web-toolkit.googlecode.com/files/gwt-dev-plugin-1.26-rc1.xpi

    gwt-websocket-exercise:用于GWT培训的简单GWT Websocket练习

    gwt-websocket-exercise 用于GWT培训的简单GWT Websocket练习 依赖于realityforge的gwt-websocket实现: 在Eclipse中设置Realityforge / gwt-websockets项目 在项目中:在类路径上添加GWT SDK,启用GWT支持 删除...

    gwt-270-skeleton:GWT v2.7.0 骨架

    gwt-270-骨架GWT v2.7.0 骨架 mvn archetype:generate \ -DarchetypeGroupId=org.codehaus.mojo \ -DarchetypeArtifactId=gwt-maven-plugin \ -DarchetypeVersion=2.7.0属性配置: groupId: ... gwt270exampleversion: ...

    gwt-dev-plugin for Firefox3.0.xpi

    GWT调试插件,适用于firefox3.x GWT浏览器插件 gwt-dev-plugin for Firefox3.0

    最好的gwt-ext学习资料

    最好的gwt-ext学习资料,适合初学者。

Global site tag (gtag.js) - Google Analytics