Use a custom PlaceController to go to the previous page after login.
[online-glom:gwt-glom.git] / src / main / java / org / glom / web / client / PlaceControllerExt.java
1 /*
2  * Copyright (C) 2012 Openismus GmbH
3  *
4  * This file is part of GWT-Glom.
5  *
6  * GWT-Glom is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation, either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * GWT-Glom is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with GWT-Glom.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package org.glom.web.client;
21
22 import com.google.gwt.place.shared.Place;
23 import com.google.gwt.place.shared.PlaceChangeEvent;
24 import com.google.gwt.place.shared.PlaceController;
25 import com.google.web.bindery.event.shared.EventBus;
26
27 /**
28  * @author Murray Cumming <murrayc@murrayc.com>
29  * 
30  */
31 public class PlaceControllerExt extends PlaceController {
32
33         private final Place defaultPlace;
34         private Place previousPlace;
35         private Place currentPlace;
36
37         public PlaceControllerExt(EventBus eventBus, Place defaultPlace) {
38                 super(eventBus);
39                 this.defaultPlace = defaultPlace;
40                 eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {
41
42                         public void onPlaceChange(PlaceChangeEvent event) {
43
44                                 previousPlace = currentPlace;
45                                 currentPlace = event.getNewPlace();
46                         }
47                 });
48         }
49         
50         public Place getDefaultPlace() {
51                 return defaultPlace;
52         }
53
54         /**
55          * Navigate back to the previous Place. If there is no previous place then goto to default place. If there isn't one
56          * of these then it'll go back to the default place as configured when the PlaceHistoryHandler was registered. This
57          * is better than using History#back() as that can have the undesired effect of leaving the web app.
58          */
59         public void previous() {
60
61                 if (previousPlace != null) {
62                         goTo(previousPlace);
63                 } else {
64                         goTo(defaultPlace);
65                 }
66         }
67 }