My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
PlaceManager  
Overview of the PlaceManager
Updated Dec 30, 2010 by gal.dol...@gmail.com

Introduction

The PlaceManager is the one that will take care of History management.

Choice

You can disable the PlaceManager if you don't want to use it. But by default it is enabled.

To disable it, add in your gwt.xml module:

<set-configuration-property name="app.use.place" value="false">
</set-configuration-property>

Place

A place is a location in your application. It can be a Presenter or a Controller.

The place interface has only one method:

    void go(D data) {
    }

Guit PlaceManager implementation needs the places to be Singletons by design.

To turn a Presenter or a Controller into a Place you need to:

  • Make them implement com.unnison.framework.client.place.Place
  • Bind them as Singleton in the gin module (@Singleton annotation won't work, use .in(Singleton.class))

After doing that your Presenter/Controller will be already a place!

¿Where is my places registration?

In Guit you don't need to register the places.

Guit scans your gin bindings for classes that implement Place and are binded as Singleton. From that classes Guit build the Places registration.

That's what I call zero-configuration! :).

StayPlace

A StayPlace is a place with a few extra methods:

    // When trying to leave the place
    String mayLeave();

   // When the place is leaved
    void leave();

    // If mayLeave was called and the user cancelled this method gets called
    void stay();

I think this is pretty straight.

Place name

The place name that will be used for the token is by default the SimpleSourceName of the presenter.

If you want a custom place name, annotate the presenter with @PlaceName("YourCuteNewName")

Default place

To specify your default place, you need to add in your gwt.xml module:

<set-configuration-property name="app.default.place" value="com.demo.client.YourPresenter">
</set-configuration-property>

This place will be called when the history token is empty (in general, when you get into the application). Another situation when it will get called is in production, when the History token gets corrupted. In development mode you will get an assert exception.

It is important to note that this is not required.

Place data

When you declare a place you generally have "data" attached to it. That "data" represents the state of the place. Guit lets you declare that data as a java pojo.

@GwtPresenter
public class ComplexPlace extends ComplexPlacePresenter
    implements
    Place<ComplexPlaceData> {

As you can notice, the Place interface takes an argument, that is your place data's type.

public class ComplexPlaceData {

    private String text;

    private boolean enabled;

    private String color;

    private int textSize = 25;

    public ComplexPlaceData() {
    }

    ... getters and setters
}

Guit will automatically serialize and deserialize that data for you into the browser's token.

Guit had built-in a json orm to do that.

Guit json's orm supports any crazy data that you will declare (seriously). But remember: it must be serializable.

To get a field serialized:

  • It could be of any type but Object. This include: primitives, other pojo types, arrays, lists, maps.
  • It needs to have getters and setters (isName() getter convention for primitive booleans)
  • Must not be final or transient

The following places are also supported:

 * Place<Void>
 * Place<Double>
 * Place<Integer>
 * Place<String>
 * Place<Date>
 * Place<Long>
 * Place<Enum>

Go

To go programmatically to a place you need to call "go()" on the placeManager:

    placeManager.go(HomePresenter.class, null);

NewItem

To programmatically register a new item into the history, call "newItem()" on the placeManager:

    placeManager.newItem(TablePresenter.class, 2);

The newItem method can only be called with the current place as argument.

Place hyperlink

Another way to go to a place is using Hyperlinks. Guit provides two Hyperlinks: PlaceHyperlink and InlinePlaceHyperlink.

Same as placeManage.go() and placeManager.newItem() a PlaceHyperlink takes a place class and data.

Here is a little tip to use it with uiBinder:

    @UiField(provided = true)
    PlaceHyperlink login = new PlaceHyperlink(LoginPresenter.class);

RunAsync

To code-split a place you need to annotate it with @RunAsync

Crypting place token

<set-configuration-property name="app.encrypt.place"

value="true" />

Otherwise annotate the places you want to encrypt with @PlaceDataEncrypted

The default crypter is base64. To use your own you have to turn off the default: <set-configuration-property name="app.encrypt.base64"

value="false" />

And bind you crypter in you gin module: bind(Cryper.class).to(JsonToUserlikeCrypter.class);

PlaceChangeEvent

Guit 1.5 introduces PlaceChangeEvent.

Powered by Google Project Hosting