GWT Development with Activities and Places

Slides:



Advertisements
Similar presentations
Coding Basics - Deferred Binding. Deferred Binding is a feature of the GWT compiler works by generating many versions of code at compile time, only one.
Advertisements

A component- and message-based architectural style for GUI software
1 Microsoft Access 2002 Tutorial 9 – Automating Tasks With Macros.
Yii – How Power Comes Introduction, OOP & Design Patterns Presented at: Nextbridge Multan Center Aug 25, 2011.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
1 GWT Google Web Toolkit Build AJAX apps in the Java language
1 Chapter 12 Working With Access 2000 on the Internet.
Object-Oriented PHP (1)
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Automating Tasks With Macros
CS 290C: Formal Models for Web Software Lecture 10: Language Based Modeling and Analysis of Navigation Errors Instructor: Tevfik Bultan.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Lecture 17: Animation Yoni Fridman 7/27/01 7/27/01.
Object-Oriented Analysis and Design
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
1 JavaScript & AJAX CS , Spring JavaScript.
1 Standard Widget Toolkit. 2 SWT l a widget toolkit for Java developers l provides a portable API and tight integration with the underlying native OS.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Dependency Injection and Model-View-Controller. Overview Inversion of Control Model-View-Controller.
Object Based Programming. Summary Slide  Instantiating An Object  Encapsulation  Inheritance  Polymorphism –Overriding Methods –Overloading vs. Overriding.
MVC pattern and implementation in java
Singleton Christopher Chiaverini Software Design & Documentation September 18, 2003.
Design Patterns.
ExtWebDriver Open Source Project Daniel Koo Latha Nagaraj Bryan Robbins 04/23/2014.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
1 Web-Enabled Decision Support Systems Objects and Procedures Don McLaughlin IE 423 Design of Decision Support Systems (304)
Design patterns. What is a design pattern? Christopher Alexander: «The pattern describes a problem which again and again occurs in the work, as well as.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Google Web Toolkit An Overview By Shauvik Roy Choudhary.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Patterns in programming 1. What are patterns? “A design pattern is a general, reusable solution to a commonly occurring problem in software. A design.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Murach’s ASP.NET 4.0/VB, C1© 2006, Mike Murach & Associates, Inc.Slide 1.
Collaboration Diagrams CSIS3600. What is a Collaboration Diagram Collaboration diagrams illustrate interactions between objects The collaboration diagram.
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Cairngorm Microarchitecture. Pronunciation Cairngorm (kârn gôrm) n. yellowish-brown variety of quartz, especially found in Scottish Cairngorm mountain.
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Reference: “ASP.NET 2.0 Illustrated” by Alex Homer and Dave Sussman. -ch3 illustrated book
Object Oriented Programming.  Interface  Event Handling.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Review Class Inheritance, Abstract, Interfaces, Polymorphism, GUI (MVC)
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
WebObjects Matt Aguirre Lally Singh. What Is It? A Java based development platform specifically designed for database-backed web applications.
Web Services An Introduction Copyright © Curt Hill.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
.NET Mobile Application Development XML Web Services.
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
Understand Databound Controls Windows Development Fundamentals LESSON 4.2A.
JavaScript and Ajax (JavaScript Environment) Week 6 Web site:
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Spell Checker web service (you build a web client that interacts with the service) The client uses a servlet class and a JSP page. The user passes information.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
How to Leverage Java in Oracle Forms Web Applications Duncan Mills Application Development Tools Oracle Corporation.
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Putting together the AndroidManifest.xml file Creating multiple.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Object Oriented Programming Some Interesting Genes.
Factory Patterns 1.
Java Beans Sagun Dhakhwa.
Activities and Intents
Constructors, GUI’s(Using Swing) and ActionListner
Chapter 4: Threads.
Presentation transcript:

GWT Development with Activities and Places

The Activities and Places framework a built-in framework for browser history management. It builds on GWT's history mechanism  is introduced in GWT 2.1 allows you to create bookmarkable URLs within your application, allowing the browser's back button and bookmarks to work as users expect. may be used in conjunction with MVP development, though not required. Strictly speaking, MVP architecture is not concerned with browser history management, but Activities and Places may be used with MVP development as shown in this article.

Definitions An activity A place simply represents something the user is doing. contains no Widgets or UI code. typically restore state ("wake up"), perform initialization ("set up"), and load a corresponding UI ("show up"). can automatically display a warning confirmation when the Activity is about to be stopped (such as when the user navigates to a new Place). are started and stopped by an ActivityManager associated with a container Widget. the ActivityManager warns the user before the window is about to be closed. A place  is a Java object The object represents a particular state of the UI. can be converted to and from a URL history token by defining a PlaceTokenizer for each Place, see GWT's History mechanism) GWT's PlaceHistoryHandler automatically updates the browser URL corresponding to each Place in your app.

PlaceController PlaceChangeEvents PlaceHistoryMapper ActivityManager 2. fire PlaceController  PlaceChangeEvents  3. Listen to/updates  1. initiates navigation to a new Place, e.g., place2  PlaceHistoryMapper  PlaceHistoryHandler  URL1/Token1 Place1 URL2/Token2 Place2 declares  Place2/ State of UI_2/view User Activity1 Place1/ State of UI_1/view User Activity2 Managed by ActivityManager  Notify current_activity If current_activity is OK Start activity2 3.1 Activity2 := Get the activity corresponding to place2 ActivityMapper Activity1 Place1 Activity2 Pace2

Moving parts in a GWT 2.1 Views ClientFactory Activities Places PlaceHistoryMapper ActivityMapper

Views A view is simply the part of the UI is associated with an Activity. is defined by an interface, Interface allows multiple view implementations based on client characteristics (such as mobile vs. desktop) Interface facilitates lightweight unit testing by avoiding the time-consuming GWTTestCase. There is no View interface or class in GWT which views must implement or extend; however, GWT 2.1 introduces an IsWidget interface that is implemented by most Widgets as well as Composite. useful for views to extend IsWidget if they do in fact provide a Widget

The corresponding view implementation extends Composite, which keeps dependencies on a particular Widget from leaking out.

Activity The Presenter interface and setPresenter method allow for bi-directional communication between view and presenter, which simplifies interactions involving repeating Widgets and also allows view implementations to use UiBinder with @UiHandler methods that delegate to the presenter interface.

ClientFactory Widget creation It is good practice to A ClientFactory involves DOM operations, are relatively expensive to create. It is good practice to make them reusable, How? via a view factory, which might be part of a larger ClientFactory. A ClientFactory is not required to use Activities and Places ,however it is helpful to use a factory or dependency injection framework like GIN to obtain references to objects needed throughout your application like the event bus. Our example uses a ClientFactory to provide an EventBus, GWT PlaceController, and view implementations.

Another advantage of using a ClientFactory Deferred binding to use different implementation classes based on user.agent or other properties. For example, you might use a MobileClientFactory to provide different view implementations than the default DesktopClientFactory. How? instantiate your ClientFactory with GWT.create in onModuleLoad()

Activities Activity classes Example implement com.google.gwt.activity.shared.Activity. extend AbstractActivity, (for convenience) provides default (null) implementations of all required methods. Example simply says hello to a named user:

HelloActivity obtain HelloPlace’ states obtain a reference to the HelloView as well as the EventBus and PlaceController

HelloActivity.java The first thing to notice is that HelloActivity makes reference to HelloView, which is a view interface, not an implementation. One style of MVP coding defines the view interface in the presenter. This is perfectly legitimate; however, there is no fundamental reason why an Activity and it's corresponding view interface have to be tightly bound together. Note that HelloActivity also implements the view's Presenter interface. This is used to allow the view to call methods on the Activity, which facilitates the use of UiBinder as we saw above. The HelloActivity constructor takes two arguments: a HelloPlace and the ClientFactory. Neither is strictly required for an Activity. The HelloPlace simply makes it easy for HelloActivity to obtain properties of the state represented by HelloPlace (in this case, the name of the user we are greeting). Accepting an instance of a HelloPlace in the constructor implies that a new HelloActivity will be created for each HelloPlace. You could instead obtain an activity from a factory, but it's typically cleaner to use a newly constructed Activity so you don't have to clean up any prior state. Activities are designed to be disposable, whereas views, which are more expensive to create due to the DOM calls required, should be reusable. In keeping with this idea, ClientFactory is used by HelloActivity to obtain a reference to the HelloView as well as the EventBus and PlaceController. The start method is invoked by the ActivityManager and sets things in motion. It updates the view and then swaps the view back into the Activity's container widget by calling setWidget. The non-null mayStop() method provides a warning that will be shown to the user when the Activity is about to be stopped due to window closing or navigation to another Place. If it returns null, no such warning will be shown. Finally, the goTo() method invokes the PlaceController to navigate to a new Place. PlaceController in turn notifies the ActivityManager to stop the current Activity, find and start the Activity associated with the new Place, and update the URL in PlaceHistoryHandler.

Places One Activity -> one Place. A Place URL -> activity A Place extends com.google.gwt.place.shared. must have an associated PlaceTokenizer PlaceTokenizer knows how to serialize the Place's state to a URL token. By default, the URL consists of the Place's simple class name (like "HelloPlace") followed by a colon (:) and the token returned by the PlaceTokenizer. It is convenient (though not required) to declare the PlaceTokenizer as a static class inside the corresponding Place. However, you need not have a PlaceTokenizer for each Place. Many Places in your app might not save any state to the URL, so they could just extend a BasicPlace which declares a PlaceTokenizer that returns a null token.

PlaceHistoryMapper PlaceHistoryMapper You create an interface Declares all the Places available in your app Is the link between your PlaceTokenizers and GWT's PlaceHistoryHandler that synchronizes the browser URL with each Place. You create an interface that extends PlaceHistoryMapper and uses the annotation @WithTokenizers to list each of your tokenizer classes At GWT compile time, GWT generates (see PlaceHistoryMapperGenerator) a class based on your interface that extends AbstractPlaceHistoryMapper. For more control of the PlaceHistoryMapper, use the @Prefix annotation on a PlaceTokenizer to change the first part of the URL associated with the Place. For even more control, implement PlaceHistoryMapperWithFactory and provide a TokenizerFactory that, in turn, provides individual PlaceTokenizers.

ActivityMapper Maps It must implement Have code like each Place to its corresponding Activity. It must implement ActivityMapper, Have code like "if (place instanceof SomePlace) return new SomeActivity(place)". Must know about the ClientFactory so it can provide it to activities as needed

Putting it all together

How it all works The ActivityManager PlaceController keeps track of all Activities running within the context of one container widget. listens for PlaceChangeRequestEvents notifies the current activity when a new Place has been requested. If the current Activity allows the Place change (Activity.onMayStop() returns null) or the user allows it (by clicking OK in the confirmation dialog), the ActivityManager discards the current Activity and starts the new one. In order to find the new one, it uses your app's ActivityMapper to obtain the Activity associated with the requested Place. PlaceController initiates navigation to a new Place and is responsible for warning the user before doing so. PlaceHistoryHandler provides bi-directional mapping between Places and the URL. Whenever your app navigates to a new Place, the URL will be updated with the new token representing the Place so it can be bookmarked and saved in browser history. Likewise, when the user clicks the back button or pulls up a bookmark, PlaceHistoryHandler ensures that your application loads the corresponding Place.

How to navigate To navigate to a new Place in your application, call the goTo() method on your PlaceController. This is illustrated above in the goTo() method of HelloActivity. PlaceController warns the current Activity that it may be stopping (via a PlaceChangeRequest event) and once allowed, fires a PlaceChangeEvent with the new Place. The PlaceHistoryHandler listens for PlaceChangeEvents and updates the URL history token accordingly. The ActivityManager also listens for PlaceChangeEvents and uses your app's ActivityMapper to start the Activity associated with the new Place. Rather than using PlaceController.goTo(), you can also create a Hyperlink containing the history token for the new Place obtained by calling your PlaceHistoryMapper.getToken(). When the user navigates to a new URL (via hyperlink, back button, or bookmark), PlaceHistoryHandler catches the ValueChangeEvent from the History object and calls your app's PlaceHistoryMapper to turn the history token into its corresponding Place. It then calls PlaceController.goTo() with the new Place.